Commits

Jerry Zhang committed 9982d83

options: 修改初始化方法; parse_options添加args参数,方便命令行测试; 修改ConfigParser的optionxform方法,避免key被转成小写的默认行为

Comments (0)

Files changed (2)

kahgean/daemonkit.py

 def change_user(username):
     u"""修改用户"""
     if not pwd: return
-    os.setgid(pwd.getpwnam(username).pw_uid)
+    os.setuid(pwd.getpwnam(username).pw_uid)
 
 
 def change_rlimit_nofile(limit):

kahgean/options.py

     
     def __init__(self, prog=None, description=None, epilog=None,
                  formatter_class=HelpFormatter):
+        self._actions = dict()
+        self._namespace = None
         self._arg_parser = ArgumentParser(prog, None, description, epilog,
                                           formatter_class=formatter_class)
-        self.add_argument(*self.config_argument, dest=self.config_file_dest,
+        self.add_option(*self.config_argument, dest=self.config_file_dest,
                           metavar='filename', type=file, default=SUPPRESS,
-                          help=u'配置文件')
-        self._actions = dict()
-        self._namespace = None
+                          help=u'配置文件')        
 
     def add_option(self, *args, **kwargs):
         u"""添加配置项
         action = self._arg_parser.add_argument(*args, **kwargs)
         self._actions[action.dest] = action
     
-    def parse_options(self):
+    def parse_options(self, args=None):
         u"""从命令行和配置文件(如果在命令行中指定的话)中读取配置信息"""
-        namespace = self._parse_args()
+        namespace = self._parse_args(args)
         if hasattr(namespace, self.config_file_dest):
             ns = self._load_options(getattr(namespace, self.config_file_dest))
             for key in ns.__dict__:
         # 以便后续可以使用命令行处理器分析处理
         args = list()
         parser = SafeConfigParser(allow_no_value=True)
+        parser.optionxform = str
         parser.readfp(file)
         sections = parser.sections()
         for section in sections: