def main(parser, appConfig, loggerConfig): import utils.logger (options, args) = parser.parse_args(args=None, values=None) loggerDictConfig = utils.logger.set_logger(loggerConfig, options.log_path, options.log_level) elog.force("%s-%s start", APPNAME, APPVER) # 当前脚本绝对路径 abspath = util.script_abspath(inspect.currentframe()) options.artifactName = options.artifactName \ .replace('${artifactId}', options.artifactId) \ .replace('-', '_') \ .replace('.', '_') options.artifactRootdir = options.artifactRootdir \ .replace('${projectRootdir}', appConfig['projectRootdir']) \ .replace('${artifactId}', options.artifactId) \ .replace('${artifactName}', options.artifactName) if options.create_project: util.info2("projectRootdir = '%s'" % appConfig['projectRootdir']) util.info2("sb2template = '%s'" % appConfig['sb2template']) util.print_options_attrs(options, [ 'groupId', 'artifactId', 'artifactName', 'artifactVersion', 'artifactDescription', 'artifactRootdir' ]) if util.dir_exists(options.artifactRootdir) and not options.force: elog.warn( "artifactRootdir has already existed. (using '--force' to overwrite it.)" ) sys.exit(-1) pass create_sb2_project(appConfig, options) elog.force("%s-%s exit.", APPNAME, APPVER) pass
def main(parser, appConfig, loggerConfig): import utils.logger (options, args) = parser.parse_args(args=None, values=None) loggerDictConfig = utils.logger.set_logger(loggerConfig, options.log_path, options.log_level) elog.force("%s-%s starting", APPNAME, APPVER) # 当前脚本绝对路径 abspath = util.script_abspath(inspect.currentframe()) util.print_options_attrs(options, ['source_dbicfg', 'dest_sqlfile']) absYamlFile = os.path.abspath(options.source_dbicfg) absSqlFile = os.path.abspath(options.dest_sqlfile) module, _ = os.path.splitext(os.path.basename(absYamlFile)) util.info2(absYamlFile) util.info2(absSqlFile) # 打开配置文件 fd = open(absYamlFile) data = fd.read() fd.close() # 载入配置 dict = yaml.load(data) # 创建 sqlfile create_phoenix_cresql(dict, module.lower(), absSqlFile, options.force, dict.get('constants')) util.warn( "NOW YOU CAN USE BELOW COMMAND TO CREATE TABLES IN HBASE-PHOENIX !") elog.force_clean(" $ sqlline.py zkhost:zkport /path/to/file.cresql") util.info("Sample:\n $ ./sqlline.py localhost:2182 %s" % absSqlFile) pass
def main(parser): (options, args) = parser.parse_args(args=None, values=None) # 当前脚本绝对路径 abspath = util.script_abspath(inspect.currentframe()) if not options.path: elog.warn("No path specified. using: -P, --path=PATH") exit(-1) # 取得配置项 options.path 的绝对路径 root_path = util.source_abspath(APPFILE, options.path, abspath) # 取得文件扩展名数组 file_exts = [] filters = parse_strarr(options.filter) for filter in filters: if filter.startswith('.'): if filter not in file_exts: file_exts.append(filter) if filter in source_filters_dict.keys(): for ext in source_filters_dict[filter]: if ext not in file_exts: file_exts.append(ext) curtime = time.time() elog.force("path: %r", root_path) elog.force("exts: %r", file_exts) elog.force("recursive: %r", options.recursive) elog.force("timestamp: %r", curtime) if options.author: elog.force("author: %r", options.author) sweep_path(root_path, file_exts, options.recursive, options.author, curtime) pass
def main(parser): (options, args) = parser.parse_args(args=None, values=None) # 子进程退出后向父进程发送的信号 ## signal.signal(signal.SIGCHLD, util.sig_chld) # 进程退出信号 signal.signal(signal.SIGINT, util.sig_int) signal.signal(signal.SIGTERM, util.sig_term) # 当前脚本绝对路径 abspath = util.script_abspath(inspect.currentframe()) if not options.path: options.path = os.getcwd() elog.warn( "No path specified. using current working dir or using: --path='PATH'" ) if not options.srcs: elog.error("No source strings specified. using: --srcs='STRINGS'") sys.exit(1) if not options.dsts: elog.warn("No destigation strings specified. using: --dsts='STRINGS'") # 取得配置项options.path的绝对路径 root_path = util.source_abspath(APPFILE, options.path, abspath) srcs = parse_strarr(options.srcs) dsts = parse_strarr(options.dsts) elog.force("path: %s", root_path) elog.force("sour = %r", srcs) elog.force("dest = %r", dsts) founds = [] sweep_dir(root_path, srcs, founds) elog.force("Total %d files found", len(founds)) if len(founds) > 0: if options.replace: if len(srcs) == len(dsts): for pf in founds: ctime, mtime = None, None fts = file_times(pf) if fts: ctime, mtime = fts else: elog.warn("missing file: %s", pf) continue for i in range(0, len(srcs)): srcstr = srcs[i] dststr = None if i < len(dsts): dststr = dsts[i] if dststr: ds = dststr.replace('$(mtime)', mtime).replace( '$(ctime)', ctime) if options.whole_line: cmd = "sed -i 's/%s.*/%s/g' '%s'" % (srcstr, ds, pf) else: cmd = "sed -i 's/%s/%s/g' '%s'" % (srcstr, ds, pf) elog.debug(cmd) (status, output) = commands.getstatusoutput(cmd) if status != 0: elog.error( "failed to command: \"%s\", output: %r", sed, output) elog.force("Total %d files replaced", len(founds)) else: elog.error( "Failed to replace for srcs(%r) mismatched with dsts(%r)", srcs, dsts) pass else: elog.warn("No files to be replaced. Using: --replace") pass pass
def main(parser): (options, args) = parser.parse_args(args=None, values=None) # 当前脚本绝对路径 abspath = util.script_abspath(inspect.currentframe()) # 产品文件夹全路径 artifactRoot = options.artifactRoot # 产品文件夹名称 artifactRootName = os.path.basename(artifactRoot) artifactId = options.artifactId if not artifactId: artifactId = artifactRootName artifactName = options.artifactName if not artifactName: artifactName = artifactId if not options.groupId: exit(-1) if artifactRootName != artifactId: print "WARN:", "产品ID与文件夹名称不一致, 可能导致歧义:" print "产品文件夹:", artifactRoot print "产品ID:", artifactId print "期望的产品ID:", artifactRootName pass # 解压模板文件 demoZipfile = os.path.join(abspath, "demo.zip") if not util.file_exists(demoZipfile): print "ERROR 模板文件不存在", demoZipfile exit(-1) demoRootDir = os.path.join(abspath, "build", "tmp", "demo") if util.dir_exists(demoRootDir): shutil.rmtree(demoRootDir) pass util.unzip_file(demoZipfile, demoRootDir) if not util.dir_exists(demoRootDir): print "ERROR 模板路径不存在", demoRootDir exit(-1) if not options.forceUpdate: create_artifact(artifactRoot=artifactRoot, artifactId=artifactId, artifactName=artifactName, groupId=options.groupId, artifactVersion=options.artifactVersion, springbootVersion=options.springbootVersion, javaVersion=options.javaVersion, description=options.description, author=options.author) else: print "当前不支持!" pass # 使用完毕删除模板 shutil.rmtree(demoRootDir) pass