3 # pylint: disable-msg=R0201
4 # method could be function but we need shared class data
11 Creates and reads config file using ConfigObj
13 config['keyword'] = get_keyword()
14 config['overlay'] = get_portdir_overlay()
15 config['format'] = "ansi"
22 from configobj import ConfigObj
24 from g_pypi.portage_utils import get_keyword, get_portdir_overlay
26 __docformat__ = 'restructuredtext'
28 CONFIG_DIR = os.path.expanduser("~/.g-pypi")
34 Holds options from config file
42 self.set_config(self.get_config())
45 """Read config file, create if it doesn't exist"""
46 if not os.path.exists(self.get_rc_filename()):
48 return ConfigObj(self.get_rc_filename())
50 def create_config(self):
51 """Create config file with defaults"""
52 if not os.path.exists(CONFIG_DIR):
54 self.create_config_obj()
56 def create_config_obj(self):
57 """Set defaults for ConigObj"""
59 config.filename = self.get_rc_filename()
60 config['keyword'] = get_keyword()
61 config['overlay'] = get_portdir_overlay()
62 config['format'] = "ansi"
63 config['background'] = "dark"
65 self.set_config(config)
67 print "Your default keyword will be: %s " % \
69 print "Your default overlay will be: %s " % \
71 print "To change these edit: %s \n\n" % config.filename
73 def set_config(self, config):
75 MyConfig.config = config
77 def set_options(self, options):
79 MyConfig.options = options
81 def get_rc_filename(self):
82 """Return rc_file filename"""
83 return os.path.join(CONFIG_DIR, "g-pypirc")
87 MyConfig.logger = logging.getLogger("g-pypi")
88 if MyConfig.options.verbose:
89 MyConfig.logger.setLevel(logging.INFO)
90 elif MyConfig.options.quiet:
91 MyConfig.logger.setLevel(logging.ERROR)
92 elif MyConfig.options.debug:
93 MyConfig.logger.setLevel(logging.DEBUG)
95 MyConfig.logger.setLevel(logging.INFO)
96 MyConfig.logger.addHandler(logging.StreamHandler())
99 """Return logging object"""
100 return MyConfig.logger