1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
#################################################################################
# LAYMAN CONFIGURATION
#################################################################################
# File: config.py
#
# Handles layman configuration
#
# Copyright:
# (c) 2005 Gunnar Wrobel
# Distributed under the terms of the GNU General Public License v2
#
# Author(s):
# Gunnar Wrobel <wrobel@gentoo.org>
#
__version__ = "$Id$"
#===============================================================================
#
# Dependencies
#
#-------------------------------------------------------------------------------
import os, sys, optparse, ConfigParser
from optparse import OptionParser, OptionGroup
from layman.debug import OUT
from layman.version import LMVERSION
#===============================================================================
#
# Class Config
#
#-------------------------------------------------------------------------------
class Config(object):
defaults = {'config' : '/etc/layman/layman.cfg',
'overlays': 'http://dev.gentoo.org/~wrobel/layman/overlays.xml'}
def __init__(self):
'''
Creates and describes all possible polymeraZe options and creates
a debugging object.
'''
self.parser = OptionParser(
usage = 'layman <ACTION> [overlay]',
version = LMVERSION)
##################################################################
# Main Options
group = OptionGroup(self.parser,
'<Actions>')
group.add_option('-a',
'--add',
action = 'store',
help = 'Add an overlay to your selection of overlays'
'.')
group.add_option('-d',
'--delete',
action = 'store',
help = 'Remove an overlay from your selection of ove'
'rlays.')
group.add_option('-u',
'--update',
action = 'store',
help = 'Update the specified overlays. If you don\'t'
' specify an argument, all overlays will be updated ')
group.add_option('-f',
'--fetch',
action = 'store_true',
help = 'Fetch the overlay listing.')
self.parser.add_option_group(group)
##################################################################
# Additional Options
group = OptionGroup(self.parser,
'<Path options>')
group.add_option('-c',
'--config',
action = 'store',
help = 'Path to the config file.')
group.add_option('-o',
'--overlays',
action = 'store',
help = 'The list of overlays.')
self.parser.add_option_group(group)
# Parse the command line first since we need to get the config
# file option.
(options, args) = self.parser.parse_args()
# Map options from the command line into the default
for i in options.__dict__:
self.default[i] = options.__dict__[i]
self.config = ConfigParser.ConfigParser(self.default)
self.config.add_section('MAIN')
self.config.read(self.default['config'])
|