本文整理汇总了Python中Configuration.Configuration.get_value方法的典型用法代码示例。如果您正苦于以下问题:Python Configuration.get_value方法的具体用法?Python Configuration.get_value怎么用?Python Configuration.get_value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Configuration.Configuration
的用法示例。
在下文中一共展示了Configuration.get_value方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from Configuration import Configuration [as 别名]
# 或者: from Configuration.Configuration import get_value [as 别名]
def main() :
commandline = CommandLine(sys.argv)
e = None
try :
#if True :
action = commandline.parse()
if action == CommandLine.ACTION_DUMP :
configuration = Configuration()
dumpername = configuration.get_value('dumper')
pluginpath = []
pluginsubpath = os.path.join('dirstat','Dumpers')
if os.path.exists(sys.argv[0]) :
pluginpath.append(os.path.join(os.path.dirname(sys.argv[0]),pluginsubpath))
if configuration.get_value('pluginpath') != '' :
pluginpath.append(os.path.join(configuration.get_value('pluginpath'),pluginsubpath))
pluginpath.append(configuration.get_value('pluginpath'))
for pathname in sys.path :
pluginpath.append(os.path.join(pathname,pluginsubpath))
try :
modulename = dumpername
#print (modulename,pluginpath)
moduleinfo = imp.find_module(modulename,pluginpath)
#print (moduleinfo,)
module = imp.load_module(modulename,*moduleinfo)
moduleinfo[0].close()
Dumper = module.Dumper
Dumper().dump()
except ImportError :
raise ParseError('Dumper %s cannot be loaded' % (dumpername,))
elif action == CommandLine.ACTION_USAGE :
print commandline.get_usage(),
elif action == CommandLine.ACTION_VERSION :
print commandline.get_version_text(),
elif action == CommandLine.ACTION_CONFIG :
config()
except (ParseError,ValueError), e :
print commandline.get_usage()
raise e
示例2: FileDumper
# 需要导入模块: from Configuration import Configuration [as 别名]
# 或者: from Configuration.Configuration import get_value [as 别名]
class FileDumper( object ) :
"""This is the mother class of all dumpers. A dumper is a plugin that receive informations about a file and how to draw it. It usually dump a file, but you can do whatever you want with it."""
EXT=".dump"
NEEDHANDLE=True
def __init__(self, rootpath=None, outputfile=None) :
self._configuration = Configuration()
if self._configuration.get_value('path') != '' :
rootpath = self._configuration.get_value('path')
# Gruik Gruik : C:" -> C:\ Thanks Windows !
if rootpath and (len(rootpath)==3) and (rootpath[2]) == '"' :
rootpath = rootpath[0:2] + '\\'
if rootpath == None :
rootpath = '.'
if os.path.supports_unicode_filenames :
rootpath = unicode(rootpath)
else :
rootpath = str(rootpath)
tree = FileTree(rootpath)
tree.scan()
self._rootpath = rootpath
self._tree = tree
filename = outputfile
if filename == None :
filename = self._configuration.get_value('outputfile')
if filename == '' :
if os.path.isdir(rootpath) :
filename = os.path.join(rootpath,self._configuration.get_value('basename')+self.EXT)
else :
name = os.path.split(rootpath)[1]
filename = name + '.' + self._configuration.get_value('basename') + self.EXT
self._filename = filename
self._size = None
def dump(self,gsize=None) :
"""This method really start the dump. You should not override it. Override _start_dump, _end_dump or add_rect instead."""
if gsize != None :
self._size = gsize
if self._size == None :
self._size = Size(self._configuration.get_value('width'),self._configuration.get_value('height'))
self._treemapview = TreemapView( self._tree, self._size )
size = self._treemapview.visibleSize()
if self.NEEDHANDLE :
self._file = file(self._filename,'wt')
self._start_dump()
self._treemapview.draw(self)
self._end_dump()
if self.NEEDHANDLE :
self._file.close()
def get_metadata(self) :
'''This method may be called by plugin to print metadata'''
return [
('Generator', 'pydirstat'),
('Version', __version__),
('Directory', os.path.abspath(self._rootpath)),
('Total Size',fmtsize(self._treemapview.rootTile().fileinfo().totalSize())),
('Date', time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())),
('Configuration File',self._configuration.get_filename()),
('Python version',sys.version),
]
def get_colors(self) :
'''This method may be called by plugin to print legend'''
method_by_type = {}
types = []
colors = {}
for section_name in self._configuration.get_sections() :
if section_name.startswith('type:') :
section_content = self._configuration.get_section(section_name)
for key in section_content :
value = section_content[key]
if value not in method_by_type :
method_by_type[value] = {}
if section_name not in method_by_type[value] :
method_by_type[value][section_name] = []
method_by_type[value][section_name].append(key)
if value not in types :
types.append(value)
elif section_name == 'color' :
colors_conf = self._configuration.get_section('color')
for color in colors_conf :
colors[color] = Color(colors_conf[color])
types.sort()
if 'file' not in types :
types.append('file')
if 'dir' not in types :
types.append('dir')
if '_' not in types :
#.........这里部分代码省略.........
示例3: FileDumper
# 需要导入模块: from Configuration import Configuration [as 别名]
# 或者: from Configuration.Configuration import get_value [as 别名]
class FileDumper(object):
EXT = ".dump"
NEEDHANDLE = True
def __init__(self, rootpath=None, outputfile=None, size=None, tree=None, configuration=None):
self._configuration = configuration
if self._configuration == None:
self._configuration = Configuration()
if rootpath == None and self._configuration.get_value("path") != "":
rootpath = self._configuration.get_value("path")
# Gruik Gruik : C:" -> C:\ Thanks Windows !
if rootpath and (len(rootpath) == 3) and (rootpath[2]) == '"':
rootpath = rootpath[0:2] + "\\"
if (rootpath == None) and (tree == None):
rootpath = "."
if rootpath != None:
if os.path.supports_unicode_filenames:
rootpath = unicode(rootpath)
else:
rootpath = str(rootpath)
tree = FileTree(rootpath)
tree.scan()
self._rootpath = rootpath
self._tree = tree
filename = outputfile
if filename == None:
filename = self._configuration.get_value("outputfile")
if filename == "":
if os.path.isdir(rootpath):
filename = os.path.join(rootpath, self._configuration.get_value("basename") + self.EXT)
else:
name = os.path.split(rootpath)[1]
filename = name + "." + self._configuration.get_value("basename") + self.EXT
self._filename = filename
self._size = size
def dump(self, gsize=None):
if gsize != None:
self._size = gsize
if self._size == None:
self._size = Size(self._configuration.get_value("width"), self._configuration.get_value("height"))
self._tmv = TreemapView(self._tree, self._size, self._configuration)
size = self._tmv.visibleSize()
if self.NEEDHANDLE:
self._file = file(self._filename, "wt")
self._start_dump()
self._tmv.draw(self)
self._end_dump()
if self.NEEDHANDLE:
self._file.close()
def get_metadata(self):
"""This method may be called by plugin to print metadata"""
return [
("Generator", "pydirstat"),
("Version", __version__),
("Directory", os.path.abspath(self._rootpath)),
("Date", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())),
("Configuration File", self._configuration.get_filename()),
("Total Size", fmtsize(self._tmv.rootTile().orig().totalSize())),
("Python version", sys.version),
]
def get_colors(self):
method_by_type = {}
types = []
colors = {}
for section_name in self._configuration.get_sections():
if section_name.startswith("type:"):
section_content = self._configuration.get_section(section_name)
for key in section_content:
value = section_content[key]
if value not in method_by_type:
method_by_type[value] = {}
if section_name not in method_by_type[value]:
method_by_type[value][section_name] = []
method_by_type[value][section_name].append(key)
if value not in types:
types.append(value)
elif section_name == "color":
colors_conf = self._configuration.get_section("color")
for color in colors_conf:
colors[color] = Color(colors_conf[color])
types.sort()
if "file" not in types:
types.append("file")
if "dir" not in types:
types.append("dir")
if "_" not in types:
types.append("_")
for typename in types:
if typename not in colors:
#.........这里部分代码省略.........
示例4: parse
# 需要导入模块: from Configuration import Configuration [as 别名]
# 或者: from Configuration.Configuration import get_value [as 别名]
def parse(self) :
configuration = Configuration()
minialiases = {}
aliases = {}
for key in schema :
if 'minialias' in schema[key] :
for letter in schema[key]['minialias'] :
minialiases[letter] = key
aliases[key] = key
rest = []
remaining_args_to_parse = []
next_arg_is_value = False
next_arg_key = None
no_name_offset = 0
for arg in self._commandline[1:] :
if len(remaining_args_to_parse) > 0 :
configuration.set_strvalue(remaining_args_to_parse[0],arg)
remaining_args_to_parse = remaining_args_to_parse[1:]
elif arg[:2] == '--' :
if '=' in arg :
(key,value) = arg[2:].split('=',1)
else :
(key,value) = (arg[2:],'')
if key in aliases :
if schema[aliases[key]]['needvalue'] :
configuration.set_strvalue(aliases[key],value)
else :
configuration.set_strvalue(aliases[key],1)
else :
# error
raise ParseError('parameter %s does not exist' % (key,))
elif arg[:1] == '-' :
for letter in arg[1:] :
if letter in minialiases :
key = minialiases[letter]
if schema[key]['needvalue'] :
remaining_args_to_parse.append(key)
else :
configuration.set_strvalue(key,'1')
else :
# error
raise ParseError('miniparameter %s does not exist' % (letter,))
else :
if no_name_offset<len(schema_default) :
# poide
key = schema_default[no_name_offset]
if key in schema :
configuration.set_strvalue(key,arg)
else :
raise ParseError('parameter %s does not exist in schema' % (key,))
# strange error
pass
else :
raise ParseError('need value for parameter %s' % (key,))
# error
pass
no_name_offset += 1
if len(remaining_args_to_parse) > 0 :
raise ParseError('need value for parameter %s' % (remaining_args_to_parse[0],))
if configuration.get_value('help') != 0 :
return self.ACTION_USAGE
if configuration.get_value('version') != 0 :
return self.ACTION_VERSION
if configuration.get_value('config') != 0 :
return self.ACTION_CONFIG
return self.ACTION_DUMP
示例5: FileDumper
# 需要导入模块: from Configuration import Configuration [as 别名]
# 或者: from Configuration.Configuration import get_value [as 别名]
class FileDumper( object ) :
EXT=".dump"
NEEDHANDLE=True
def __init__(self, rootpath=None, outputfile=None, size=None, tree=None, configuration=None) :
self._configuration = configuration
if self._configuration == None :
self._configuration = Configuration()
if rootpath == None and self._configuration.get_value('path') != '' :
rootpath = self._configuration.get_value('path')
# Gruik Gruik : C:" -> C:\ Thanks Windows !
if rootpath and (len(rootpath)==3) and (rootpath[2]) == '"' :
rootpath = rootpath[0:2] + '\\'
if (rootpath == None) and (tree==None) :
rootpath = '.'
if rootpath != None :
if os.path.supports_unicode_filenames :
rootpath = unicode(rootpath)
else :
rootpath = str(rootpath)
tree = FileTree(rootpath)
tree.scan()
self._tree = tree
filename = outputfile
if filename == None :
filename = self._configuration.get_value('outputfile')
if filename == '' :
if os.path.isdir(rootpath) :
filename = os.path.join(rootpath,self._configuration.get_value('basename')+self.EXT)
else :
name = os.path.split(rootpath)[1]
filename = name + '.' + self._configuration.get_value('basename') + self.EXT
self._filename = filename
self._size = size
def dump(self,gsize=None) :
if gsize != None :
self._size = gsize
if self._size == None :
self._size = Size(self._configuration.get_value('width'),self._configuration.get_value('height'))
self._tmv = TreemapView( self._tree, self._size, self._configuration )
size = self._tmv.visibleSize()
if self.NEEDHANDLE :
self._file = file(self._filename,'wt')
self._start_dump()
self._tmv.draw(self)
self._end_dump()
if self.NEEDHANDLE :
self._file.close()
def _start_dump(self) :
'''You should override this method. Called once before starting dump.'''
pass
def _end_dump(self) :
'''You should override this method. Called once after dumping all rectangle.'''
pass
def addrect(self,**kwargs) :
'''You should override this method. It will be called on each rectangle. kwargs contains x,y,width,height,filename,filesize,color...'''
pass