I would imagine that I could do this with a generator and setattr, but I am still learning how to do that kinda of coding....maybe if I had a dictionary like this and then loaded it
d={ "site_name":["s","site",'sites','site_name','site_names'], "jar_name":["j","jar",'jars','jar_name','jar_names'], ... } Once again, I haven't been sleeping regularly lately....working on pynutbutter 24/7...Thanks for all your help -Alex Goretoy http://www.goretoy.com On Sat, Mar 14, 2009 at 10:02 PM, alex goretoy <aleksandr.gore...@gmail.com>wrote: > Nice, this is good code. Thank you. Seeing as we are still on the same > subject, how would I do it on sysarg values from getopt? > > I have a main method defined like so > > def main(self): > #XXX > """ > 1 > #get site_name: prepend to curl get/post requests > #this overrides what it is in the jar > > 2 > #get jar_name: jar_name used in directory for > sys.path.append > #import jar_name and loading jar_name.options and > jar_name.settings > #cmdline var o|options overrides default jar options and > settings > > 3 > #get file_name: parse this file for upload > #this is optional, you can specify it in the jar options > #overrides jar specified files to load. makes this the main > file > #only works with one file this way > > 4 > #get verbose = 0:default 1:function/caller output 2:curl > get/post requests/responses > #this is optional, default is 0 > #still not working how it should, it's on the todo list > > 5 > #flavors/butterknives to load with the jar, eg. mysql, > curl, csvparser support > #with plans for urllib, httplib,https, oracle, postgres, > mssql > #it is not hard to also add support for user defined custom > protocols this way > #then just define your mapped functions inside jar > configuration directories > #specifying this here option in the terminal overrides what > is configured in the jar conf > > 6 > #final functions to execute upon completion of all function > mappings and exec for each line > > 7 > #file to download and parse, this overrides disregards > file_name if passed in simutaniously > #to be used with remote files, located on http/s/ftp etc... > it fetches the file and stores it > #under the key() as the name, which is to be concurrent > with keys in files, so that we know which is main > #works with multiple files > > 8 > #colors - allows you to specify what colors to use for > output of caller/called functions, etc... > > 9 > #specify source for options to be loaded from > #you can specify custom option modules w/ attr & settings > to load > #todo: implement using options from db > #todo: implement getting data from different sources other > than csv files > > 10 > #source of our configuration, only jars files work > for now > #currently default is storing configuration > settings in jars files > > 11 > # This is the jar conf file located in the jar > directory > #it is imported for getting > options/settings/mappings/etc... > #name of module to load which is located inside the > jar dir > > 12 > # jar configuration options attribute( dict that > holds all mappings and functions, located in jar conf ) > # name of options dictionary that hold all jar > options/mapping etc... > > 13 > #jar configuration settings attribute (dict that > holds all settings, located in jar conf file) > #name of our settings dictionary that holds all jar > settings > > 14 > #jar file settings > #secondary file to parse and use inside you > functions > > """ > for _argsi in range(len("".join(self.args).split('='))-1): > _args=self.args[_argsi].split("=") > print ("printing A:",_args) > #XXX#1 > if _args[0] in ("s","site",'sites'): > self.opt['properties']['site_name'] = _args[1] > self.soc.debug( "%s"%("args site_name: > ",self.opt['properties']['site_name']) ) > #XXX#2 > elif _args[0] in ("j","jar",'jars','jar_name'): > self.opt['properties']['jar_name'] = _args[1] > self.soc.debug( "%s"%("args jar_name: > ",self.opt['properties']['jar_name']) ) > > #XXX#3 > elif _args[0] in > ("f",'file','files','filename','filenames','file_name','file_names'): > self.opt['properties']['file_name'] = _args[1] > self.soc.debug( "%s"%("args file_name: > ",self.opt['properties']['file_name']) ) > > #XXX#4 > elif _args[0] in ("v","vv","vvv",'verbose','verbosity'): > self.opt['properties']['verbose'] = _args[1] > self.soc.debug( "%s"%("args verbose: > ",self.opt['properties']['verbose']) ) > > #XXX#5 > elif _args[0] in ("ff","flav","flavor","flavors"): > if _args[1] is not "": > bk=_args[1] #get flavors/butterknives > _bk=bk.split(',') > for _bki in range(len(_bk)): > __bk=_bk[_bki].split(":") > > self.opt['properties']['flavors'][__bk[0]]=int(__bk[1]) > self.soc.debug( "%s"%("args flavors: > ",self.opt['properties']['flavors']) ) > > #XXX#6 > elif _args[0] in > ("fff","finfun","final_func","final_funcs","final_function","final_functions"): > if _args[1] is not "": > bk=_args[1] #get flavors/butterknives > _bk=bk.split(',') > for _bki in range(len(_bk)): > __bk=_bk[_bki].split(":") > > self.opt['properties']['final_funcs'][__bk[0]]=int(__bk[1]) > self.soc.debug( "%s"%("args final_funcs: > ",self.opt['properties']['final_funcs']) ) > > #XXX#7 > elif _args[0] in > ("d",'df',"down",'down_file','down_files',"download","downloads",'download_file','download_files'): > if _args[1] is not "": > bk=_args[1] #get downloads d="file.csv: > http://asdf.asd/file.csv" or d="1" or d="True" etc > if bool(bk): > print ("\nDOWNLOAD FILES",bk) > > self.opt['properties']['settings']['download_files'] = 1 > self.soc.debug( "%s"%("args download_files: > ",self.opt['properties']['site_name']) ) > > if bk.find("://") >-1: > _bk=bk.split(',') > for _bki in range(len(_bk)): > __bk=_bk[_bki].split(";") > > self.opt['properties']['file_downloads'][__bk[0]]=__bk[1] > self.soc.debug( "%s"%("args file_downloads: > ",self.opt['properties']['file_downloads']) ) > > #XXX#8 > elif _args[0] in ("c","col","color","colors",'reaper'): > if _args[1] is not "": > c=_args[1] #get flavors/butterknives > _c=c.split(',') > for _ci in range(len(_c)): > __c=_c[_ci].split(":") > self.opt['properties']['colors'][__c[0]]=__c[1] > self.soc.debug( "%s"%("args colors: > ",self.opt['properties']['colors']) ) > > #XXX#9 > elif _args[0] in ('o','opt','option',"options"): > options = _args[1] > _options=options.split(",") > for _optionsi in range(len(_options)): > print (_optionsi, _options[_optionsi].split(':')) > __options=_options[_optionsi].split(':') > #XXX#10 > if __options[0] in ('ss',"src","source","sources"): > print (__options[0], __options[1]) > if __options[1] is not "": > self.opt['properties']['imp_src'] = > "".join(__options[1]) > self.soc.debug( "%s"%("args imp_src: > ",self.opt['properties']['imp_src']) ) > > #XXX#11 > elif __options[0] in ("mod","module","modules"): > print (__options[0], __options[1]) > if __options[1] is not "": > self.opt['properties']['imp_mod'] = > "".join(__options[1]) > self.soc.debug( "%s"%("args imp_mod: > ",self.opt['properties']['imp_mod']) ) > > else: > self.opt['properties']['imp_mod'] = > self.opt['properties']['jar_name'] > self.soc.debug( "%s"%("args imp_mod: > ",self.opt['properties']['imp_mod']) ) > > #XXX#12 > elif __options[0] in ("opt","option","options"): > print (__options[0], __options[1]) > if __options[1] is not "": > self.opt['properties']['imp_opt'] = > "".join(__options[1]) > self.soc.debug( "%s"%("args imp_opt: > ",self.opt['properties']['imp_opt']) ) > > #XXX#13 > elif __options[0] in ("set","setting","settings"): > print (__options[0], __options[1]) > if __options[1] is not "": > self.opt['properties']['imp_set'] = > "".join(__options[1]) > self.soc.debug( "%s"%("args imp_set: > ",self.opt['properties']['imp_set']) ) > > #XXX#14 > elif __options[0] in ("file","files"): > print (__options[0], __options[1]) > if __options[1] is not "": > self.opt['properties']['imp_files'] = > "".join(__options[1]) > self.soc.debug( "%s"%("args imp_files: > ",self.opt['properties']['imp_files']) ) > > #XXX#15 > elif __options[0] in ("flav","flavor","flavors"): > print (__options[0], __options[1]) > if __options[1] is not "": > self.opt['properties']['imp_flavors'] = > "".join(__options[1]) > self.soc.debug( "%s"%("args imp_flavors: > ",self.opt['properties']['imp_flavors']) ) > > elif __options[0] in > ("down","download","downloads","file_download"): > print (__options[0], __options[1]) > if __options[1] is not "": > self.opt['properties']['imp_downloads'] = > "".join(__options[1]) > self.soc.debug( "%s"%("args imp_downloads: > ",self.opt['properties']['imp_downloads']) ) > > -Alex Goretoy > http://www.goretoy.com > > > > On Sat, Mar 14, 2009 at 6:54 PM, MRAB <goo...@mrabarnett.plus.com> wrote: > >> >> def write(self, value, color="red", level="INFO"): >> print "value=%s, color=%s, level=%s" % (repr(value), repr(color), >> repr(level)) > > >
-- http://mail.python.org/mailman/listinfo/python-list