def main(argv=None): """Usage: ./CfxCfg.py -p ./ctx """ if argv is None: argv = sys.argv try: try: opts, args = getopt.getopt(argv[1:], "hp:", ["help", "path="]) except getopt.error, msg: raise Usage(msg) path = None for opt, arg in opts : if opt in ("-h", "--help"): print __doc__ sys.exit(0) elif opt in ("-p", "--path"): path = arg if not path : raise Usage("option -p is required.") print 'Begin.' print 'Check path', path filelist = FileUtils.get_filelist(path, '.ini') [parse_file(filename) for filename in filelist] print 'End.'
def main(argv=None): """Uses the ConFigMgr and related classes. Usage: ./main.py -p ./remote [-w] Args: (switches for running ConfigMgr.py main) -h: help -p: path to config files to be changed -w: write. Copies the files from targ dir to work dir and modifies them. (Otherwise, it just reports on files in targ dir) """ # set log file logpathname = os.path.join(os.getcwd(), 'logs', 'pydbutil.main.log') logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(name)s %(levelname)-5s %(message)s', datefmt='%m-%d %H:%M', filename=logpathname, filemode='w') print 'BEGIN.' if argv is None: argv = sys.argv try: try: opts, args = getopt.getopt( argv[1:], "hp:w", ["help", "path=", "write"]) except getopt.error, msg: raise Usage(msg) # default value path = None DO_WRITE = False for opt, arg in opts : if opt in ("-h", "--help"): print __doc__ sys.exit(0) elif opt in ("-p", "--path"): path = arg elif opt in ("-w", "--write"): DO_WRITE = True if not path : raise Usage("option -p is required.") if DO_WRITE: # copy remote to work. remove old work dir. if os.path.exists(ConfigMgr.WORK_DIR) : shutil.rmtree(ConfigMgr.WORK_DIR) shutil.copytree(path, ConfigMgr.WORK_DIR) print "Copied from {0} to {1}".format(path, ConfigMgr.WORK_DIR) workfiles = FileUtils.get_filelist(ConfigMgr.WORK_DIR, *Configure.FILE_EXTS) else: # not a write, so use the target path workfiles = FileUtils.get_filelist(path, *Configure.FILE_EXTS) cm = ConfigMgr(dbset=Configure.DBSET, filelist=workfiles, configs=Configure.CONFIGS) md = cm.go(write=DO_WRITE) if DO_WRITE : print print "{0} files written to dir '{1}'.".format( FileUtils.filecount(ConfigMgr.OUTPUT_DIR), ConfigMgr.OUTPUT_DIR) print print 'END.'