class MetaborgRelengSetRemote(cli.Application): """ Changes the remote for all submodules to an SSH or HTTP remote. """ toSsh = cli.Flag(names=['-s', '--ssh'], default=False, excludes=['--http'], help='Set remotes to SSH remotes') toHttp = cli.Flag(names=['-h', '--http'], default=False, excludes=['--ssh'], help='Set remotes to HTTP remotes') def main(self): if not self.toSsh and not self.toHttp: print('Must choose between SSH (-s) or HTTP (-h)') return 1 if self.toSsh: toType = RemoteType.SSH elif self.toHttp: toType = RemoteType.HTTP print('Setting remotes for all submodules') # noinspection PyUnboundLocalVariable SetRemoteAll(self.parent.repo, toType=toType) return 0
class SyncCommand(BaijiCommand): DESCRIPTION = "move a directory tree from or to s3, a la rsync" progress = cli.Flag(['-P', '--progress'], help='show progress') guess_content_type = cli.Flag(['-g', '--guess-content-type'], help='Guess content type of file') policy = cli.SwitchAttr( '--policy', str, help= 'override policy when copying to s3 (e.g. private, public-read, bucket-owner-read' ) encoding = cli.SwitchAttr('--encoding', str, help='Content-Encoding: gzip, etc') do_not_delete = cli.SwitchAttr( ['-D', '--do-not-delete'], str, list=True, help='Path prefixes not to delete from the target') encrypt = cli.Flag('--no-encrypt', default=True, help='Do not server side encrypt at rest') def main(self, src, dst): kwargs = { 'do_not_delete': self.do_not_delete, 'progress': self.progress, 'policy': self.policy, 'encoding': self.encoding, 'encrypt': self.encrypt, 'guess_content_type': self.guess_content_type, } s3.sync(src, dst, **kwargs)
class App(cli.Application): """Convert a document to html and deploy the html with github pages. doc_path: path of a document, such as xxx-xxx.pdf or /path/to/xxx-xxx.epub repo: <username>/<repo> the repository to be deployed on github. """ public = cli.Flag('--public', default=False, help='Deploy to an public repository.') threshold = cli.SwitchAttr('--pdf-threshold', argtype=int, default=100, help='Character number threshold. Only works for pdf file. When number of characters in a page is larger than threshold, then the page is thought as a text page.') rate = cli.SwitchAttr('--pdf-rate', argtype=float, default=0.6, help="Minimum rate of text pages over total pages. Only works for pdf file. If the actual rate is below this value, the pdf file is thought as a scanned document, which won't be converted.") force = cli.Flag('--pdf-force', default=False, help="Force to convert pdf despite whether it's scanned or not.") def main(self, doc_path, repo): # Split "<username>/<repo>" splited = repo.split('/') if not (len(splited) == 2 and all(splited)): print(f'Invalid repo: {repo}') sys.exit(1) cfg['USERNAME'], cfg['REPO'] = splited cfg['PUBLIC'] = self.public cfg['THRESHOLD'] = self.threshold cfg['RATE'] = self.rate cfg['FORCE'] = self.force _main(doc_path, cfg['REPO'])
class TestCommand(cli.Application, DoFuncs): no_clear = cli.Flag("--no_clear", help="Do not clear screen") verbose = cli.SwitchAttr("--verbose", int, default=1, help="Verbosity 0,1,2") coverage = cli.Flag("--coverage", help="Run coverage and show in local HTML") debug_mode = cli.Flag("--debug_mode", help="Put zap into debug_mode") run_groups = cli.SwitchAttr("--run_groups", str, help="Comma separated list of groups") disable_shuffle = cli.Flag("--disable_shuffle", help="If set, do not shuffle test order") def main(self, *args): self.assert_env() if not self.no_clear: self.clear() match_string = safe_list_get(args, 0) with Context(debug_mode=self.debug_mode): return self.run_zests( verbose=self.verbose, match_string=match_string, coverage=self.coverage, run_groups=self.run_groups, )
class CrestHistory(cli.Application): '''plumbum cli application: CrestHistory. ''' verbose = cli.Flag(['v', 'verbose'], help='enable logging to stdout') uncache = cli.Flag(['v', 'cache'], help='force cache refresh') region_list = [DEFAULT_REGION] @cli.switch(['-r', '--regions='], str, help='List of regions to run DEFAULT=' + region_list) def parse_regions(self, region_str_arg): '''parse ',' str into list for later''' tmp_list = region_str_arg.split(',') try: tmp_list = list(map(int, tmp_list)) except Exception as error_msg: raise error_msg self.region_list = tmp_list threads = 1 @cli.switch(['-t', '--threads='], int, help='Number of threads to use to scrape endpoint: ' + str(threads)) def set_threads(self, thread_count): '''load thread count, else default''' self.threads = thread_count def main(self): '''script logic goes here''' print('Hello World')
class MetaborgRelengReset(cli.Application): """ Resets each submodule """ confirmPrompt = cli.Flag( names=['-y', '--yes'], default=False, help='Answer warning prompts with yes automatically') toRemote = cli.Flag( names=['-r', '--remote'], default=False, help='Resets to the remote branch, deleting any unpushed commits') def main(self): print('Resetting all submodules') if self.toRemote: if not self.confirmPrompt: print( 'WARNING: This will DELETE UNCOMMITED CHANGES and DELETE UNPUSHED COMMITS, do you want to continue?' ) if not YesNoTrice(): return 1 else: if not self.confirmPrompt: print( 'WARNING: This will DELETE UNCOMMITED CHANGES, do you want to continue?' ) if not YesNoTwice(): return 1 ResetAll(self.parent.repo, self.toRemote) return 0
class SimpleApp(cli.Application): @cli.switch(["a"]) def spam(self): print("!!a") @cli.switch(["b", "bacon"], argtype=int, mandatory=True, envname="PLUMBUM_TEST_BACON") def bacon(self, param): """give me some bacon""" print("!!b", param) eggs = cli.SwitchAttr(["e"], str, help="sets the eggs attribute", envname="PLUMBUM_TEST_EGGS") cheese = cli.Flag(["--cheese"], help="cheese, please") chives = cli.Flag(["--chives"], help="chives, instead") verbose = cli.CountOf(["v"], help="increases the verbosity level") benedict = cli.CountOf(["--benedict"], help="""a very long help message with lots of useless information that nobody would ever want to read, but heck, we need to test text wrapping in help messages as well""") def main(self, *args): old = self.eggs self.eggs = "lalala" self.eggs = old self.tailargs = args
class Deploy(BaseDeploy): clean = cli.Flag("--clean", default=False, help="Clean VM before deploying it") force_clean = cli.Flag("--force-clean", default=False, help="Force destroy VM") def do_clean(self, project_name): minion_path = self.parent.config['minions'][project_name] # Check if sahara is available minion_path = self.parent.config['minions'][project_name] try: plugins = Vagrant(minion_path).plugin_list() except Exception as e: raise sahara = bool([p for p in plugins if p.name == "sahara"]) # Check sandbox status sandbox_status = 'off' if sahara: sandbox = SandboxVagrant(minion_path) sandbox_status = sandbox.sandbox_status() # If sandbox is activated, rollback only if sandbox_status == 'on' and not self.force_clean: message = "Rollback snapshot, if you will delete snapshot, use "\ "--force-clean option" puts(colored.blue(message)) sandbox.sandbox_rollback() puts(colored.blue("Done")) command = "sudo /etc/init.d/salt-minion restart" result = get_output_cmd(command, minion_path) puts(colored.blue("Restarted salt-minion")) puts(colored.blue("Wait some time for salt-minion to connect")) sleep(10) # Else destroy and up else: # Destroy VagrantDestroy.parent = self.parent VagrantDestroy.run(['destroy', project_name], exit=False) # Up VagrantUp.parent = self.parent VagrantUp.run(['up', project_name], exit=False) def main(self, project_name): # Clean if self.clean or self.force_clean: self.do_clean(project_name) super(Deploy, self).main(project_name)
class FsToDwi(cli.Application): """Registers Freesurfer labelmap to DWI space.""" fsdir = cli.SwitchAttr(['-f', '--freesurfer'], cli.ExistingDirectory, help='freesurfer subject directory', mandatory=True) dwi = cli.SwitchAttr(['--dwi'], cli.ExistingFile, help='target DWI', mandatory=True) bvals_file = cli.SwitchAttr(['--bvals'], cli.ExistingFile, help='bvals file of the DWI', mandatory=True) bse = cli.SwitchAttr(['--bse'], cli.ExistingFile, help='masked bse of DWI') dwimask = cli.SwitchAttr(['--dwimask'], cli.ExistingFile, help='DWI mask', mandatory=True) out = cli.SwitchAttr(['-o', '--outDir'], help='output directory', mandatory=True) force = cli.Flag(['--force'], help='turn on this flag to overwrite existing output', default=False, mandatory=False) debug = cli.Flag( ['-d', '--debug'], help= 'Debug mode, saves intermediate transforms to out/fs2dwi-debug-<pid>', default=False) def main(self): if not self.nested_command: print("No command given") sys.exit(1) self.fshome = local.path(os.getenv('FREESURFER_HOME')) if not self.fshome: print('Set FREESURFER_HOME first.') sys.exit(1) print('Making output directory') self.out = local.path(self.out) if self.out.exists() and self.force: print('Deleting existing directory') self.out.delete() self.out.mkdir()
class KrakenRDI(cli.Application): restApiCli = cli.Flag(["-r", "--start-restapi"], help = "Start Rest API.") workerCli = cli.Flag(["-w" , "--start-worker"], help = "Start Celery worker.") cleanDatabase = cli.Flag(["-c" , "--clean-database"], help = "Restore the database with default values and cleans the current data.", default=False) def main(self): if self.restApiCli or self.workerCli: print("Initialization tasks...") self.configuration = {} self.tools = {} self.arguments = {} try: with open('config/config.json') as configFile: self.configuration = json.load(configFile) except: print("Failed reading configuration from <KRAKENRID_DIR>/config/config.json") sys.exit(1) try: with open('config/tools.json') as toolsFile: self.tools = json.load(toolsFile) except: print("Failed reading configuration from <KRAKENRID_DIR>/config/tools.json") sys.exit(1) try: with open('config/arguments.json') as argumentsFile: self.arguments = json.load(argumentsFile) except: print("Failed reading configuration from <KRAKENRID_DIR>/config/arguments.json") sys.exit(1) KrakenServer.init(self.configuration, self.tools, self.arguments, self.cleanDatabase) print("Configuration established.") KrakenServer.configureServices() print("Core services for the Rest API configured.") if self.restApiCli: print("Starting webserver and Rest API...") self.startRestApi() elif self.workerCli: print("Starting Celery worker...") self.startWorker() def startRestApi(self): KrakenConfiguration.restApi.run() def startWorker(self): from celery import current_app from celery.bin import worker application = current_app._get_current_object() worker = worker.worker(app=application) options = { 'broker': KrakenConfiguration.restApi.config['CELERY_BROKER_URL'], 'loglevel': 'INFO', 'traceback': True, } worker.run(**options)
class PyXGBoostCLI(cli.Application): """Compiles an XGBoost model into python source and outputs it into stdout""" #generateMetadata=cli.Flag("--generate-metadata", default=False, help="Generate docstrings with metadata extracted from the model file") useNumPy = cli.Flag("--numpy", help="use numpy for vector operations") useSigmoids = cli.Flag("--sigmoids", help="use sigmoid functions for splits. This is meant to allows the gradients to be automatically computed.") def main(self, file: cli.ExistingFile): print(compile(file, useSigmoids=self.useSigmoids, useNumPy=self.useNumPy))
class BuildPackage(cli.Application): upload = cli.Flag("--upload") dont_register = cli.Flag("--dont-register") def main(self): local.cwd.chdir(HERE) sys.path.insert(0, str(ROOT)) local.env["PYTHONPATH"] = ROOT local.python("build_openni.py") local.python("build_nite.py") from primesense import openni2, nite2 dist = local.path("../dist") dist.delete() dist.mkdir() tmp = local.path("tmp") tmp.delete() tmp.mkdir() copy("../primesense", tmp / "primesense") copy("MANIFEST.in", tmp) copy("../LICENSE", tmp) copy("../README.rst", tmp) ver = "%s.%s.%s.%s-%s" % ( openni2.c_api.ONI_VERSION_MAJOR, openni2.c_api.ONI_VERSION_MINOR, openni2.c_api.ONI_VERSION_MAINTENANCE, openni2.c_api.ONI_VERSION_BUILD, config.get("pypi", "release")) data = local.path("setup_template.py").read().replace("$VERSION$", ver) (tmp / "setup.py").write(data) with local.cwd(tmp): if self.upload: # copy pypirc to ~ orig = local.path("~/.pypirc") restore = False if orig.exists(): copy(orig, "~/.pypirc-openni-wrapper") restore = True copy(ROOT / "_pypirc", "~/.pypirc") try: local.python["setup.py", "sdist", "--formats=zip,gztar", None if self.dont_register else "register", "upload"] & FG finally: if restore: copy("~/.pypirc-openni-wrapper", orig) else: local.python["setup.py", "sdist", "--formats=zip,gztar"] & FG for fn in tmp / "dist" // "*": fn.move(dist)
class Command(cli.Application): """ 远程执行命令,一般针对集群 """ VERSION = colors.bold | "1.1.0" COLOR_GROUPS = { "Meta-switches": colors.bold & colors.yellow, "Switches": colors.bold & colors.yellow } _user, _pwd = ("root", "XXXXXX") # 这里修改默认用户和密码 _ips, _cmd = ("", "") no_log = cli.Flag("--no-log", help="if not given, print detail") _all = cli.Flag(["-a", "--all"], excludes=["-i", "-u", "-p"], help="handle all nodes") @cli.switch(["-i", "--ip"], str, help="remote ips,use '/' to split") def ips(self, ips): self._ips = ips @cli.switch(["-u", "--user"], str, help="user") def user(self, user): self._user = user @cli.switch(["-p", "--password"], str, help="password") def pwd(self, pwd): self._pwd = pwd def main(self): cmd = raw_input("please input cmd:") data = get_config() if self._all: remote_ips = data.get("cluster") self._user, self._pwd = data.get("user"), data.get("password") else: remote_ips = self._ips.split("/") for remote_ip in remote_ips: try: ssh = SSH(remote_ip, self._user, password=self._pwd, port=data.get("port")) result = ssh.exec_command(cmd) ssh.close() except Exception as e: print_error("[ ERROR ] {}".format(e)) else: if self.no_log: print_ok("[ OK ] execute at {0} ".format(remote_ip)) else: print_ok("[ OK ] {0} result: {1} {0}".format( "=" * 10, remote_ip)) print_normal(result)
class MainMixin(): offline = cli.Flag( ["off", "offline"], help="Search for information not only in local the known_packages") all_flag = cli.Flag( ["a", "all"], help="Search for information not only the known_packages") quiet = cli.Flag(["q", "quiet"], help="Disable Logging") pm_names = [] @cli.switch("--pm", str, list=True, help="Search in Package Manager: " + str(PACKAGE_MANAGERS_NAMES)) def pms(self, PM_names): for pm in PM_names: if pm not in PACKAGE_MANAGERS_NAMES: try: raise ValueError( f"\"{pm}\" not found in known Package Managers") except: console.print_exception() exit() self.pm_names = PM_names _known_packages = cli.SwitchAttr(["k", "package-manager"], cli.ExistingFile, help="known_packages.json file") def init(self, shell): if self.quiet: logging.disable(logging.CRITICAL) known_packages = get_known_packages(offline=self.offline) if self._known_packages: known_packages.update(json.load(self._known_packages) ) # FIXME: _known_packages is not iostream self.known_packages = known_packages PMs = get_installed_pms(shell=shell) if len(self.pm_names) > 0: def pm_fliter(PM): return PM.name in self.pm_names PMs = list(filter(pm_fliter, PMs)) logger.debug(f"PMs after filtering: {PMs}") if PMs == []: raise PackageManagerNotInatalled(f"Not found Package Manager") self.PMs = PMs
class BenchBuild(cli.Application): """Frontend for running/building the benchbuild study framework.""" VERSION = settings.CFG["version"].value() _list_env = False verbosity = cli.CountOf('-v', help="Enable verbose output") debug = cli.Flag('-d', help="Enable debugging output") def main(self, *args): self.verbosity = self.verbosity if self.verbosity < 6 else 5 if self.debug: self.verbosity = 3 settings.CFG["verbosity"] = self.verbosity settings.CFG["debug"] = self.debug log.configure() log.set_defaults() if settings.CFG["db"]["create_functions"].value(): from benchbuild.utils.schema import init_functions, Session init_functions(Session()) if args: print("Unknown command {0!r}".format(args[0])) return 1 if not self.nested_command: self.help()
class ConfiguredApplication(cli.Application): 'Application with config' config_filename = cli.SwitchAttr( ['-c', '--config'], argtype=local.path, default=DEFAULT_CONF, argname='CONFIG', help=_("Use file CONFIG for config")) # noqa: Q000 verbose = cli.Flag( ['-v', '--verbose'], help=_("Verbose output - log everything."), # noqa: Q000 excludes=['-s', '--silent']) silence_level = cli.CountOf( ['-s', '--silent'], help=_("Make program more silent"), # noqa: Q000 excludes=['-v', '--verbose']) def main(self): self.config = load_conf(self.config_filename) self.log = logging.getLogger(str(self.__class__).split("'")[1]) self.log.addHandler(logging.StreamHandler()) if self.verbose: self.log.setLevel(logging.DEBUG) else: base_level = logging.INFO self.log.setLevel(base_level + 10 * self.silence_level)
class Search(cli.Application, MainMixin): """ Поиск пакета """ list_mode = cli.Flag(["l", "list"], help="List") def main(self, package_name: str): pretty.install() install() shell = AutoShell() self.init(shell) data = {} for pm in self.PMs: try: out = pm(shell=shell).search(package_name) if out != {}: data[pm.name] = out except NotImplementedError as e: logger.warning( f"{pm.name} not have search method!") # , exc_info=True) if self.list_mode: print_search_results(data) else: print_info(data)
class List(cli.Application): """List the projects in the central database""" useCache = cli.Flag( ['-c', '--cache'], default=False, help="Use cached result.") def main(self): PROJECT_YML_FILENAME = PROJECT_YML.name #TODO refresh cache after a certain time cache = local.path(__file__).dirname / '.dblist' if self.useCache and cache.exists(): with open(cache, 'r') as f: print(f.read()) return result = [] with open_db() as (url, machine, dbpath): ymlfiles = [y for y in dbpath // ('*/' + PROJECT_YML_FILENAME)] for ymlfile in ymlfiles: projdir = '/' + ymlfile.dirname.name.replace('---', '/') ymlstr = machine['cat'](ymlfile) yml = yaml.load(ymlstr, Loader=yaml.loader.BaseLoader) numpipelines = len(yml['pipelines']) row = {'name': yml['name'], 'directory': projdir, 'num. pipelines': numpipelines} result.append(row) result = formatTable( result, header=['name', 'directory', 'num. pipelines']) with open(cache, 'w') as f: f.write(result) print(result)
class ServidorTest(cli.Application): verbose = cli.Flag("-v", help="Arrancar el servidor en Verbose mode") port = 8080 # Puerto por defecto mode = "TCP" #Protocolo de red por defecto type = "HTTP" @cli.switch(["-p", "--port"], cli.Range(1024, 65535)) #Puerto entre 1024 y 65535 def server_port(self, port): self.port = port @cli.switch(["-m", "--mode"], cli.Set("TCP", "UDP", case_sensitive=False)) #Protocolo de red (TCP o UDP) def server_mode(self, mode): self.mode = mode @cli.switch(["-t", "--type"], cli.Set("HTTP", "HTTPS", case_sensitive=False)) def server_type(self, type): self.type = type def main(self): print self.port, self.mode, self.type, self.verbose
class ProsperSlackBot(cli.Application): """wrapper for slackbot Main()""" PROGNAME = PROGNAME VERSION = __version__ _log_builder = p_logging.ProsperLogger(PROGNAME, '/var/logs/prosper', config_obj=CONFIG) debug = cli.Flag(['d', '--debug'], help='debug mode, high verbosity for devs') def main(self): """bot main""" if self.debug: self._log_builder.configure_debug_logger() else: self._log_builder.configure_slack_logger() logger = self._log_builder.logger logger.info('Hello World') api_config.LOGGER = logger api_config.CONFIG = CONFIG logger.error('STARTING PROSPERBOT -- SLACK %s', platform.node()) try: bot = slackbot.bot.Bot() bot.run() except Exception: logger.critical('Going down in flames!', exc_info=True)
class AtlasCsv(cli.Application): """Specify training images and labelmaps via a csv file. Put the images with any header in the first column, and labelmaps with proper headers in the consecutive columns. The headers in the labelmap columns will be used to name the generated atlas labelmaps. """ target = cli.SwitchAttr( ['-t', '--target'], cli.ExistingFile, help='target image', mandatory=True) fusions = cli.SwitchAttr( ['--fusion'], cli.Set("avg", "wavg", "antsJointFusion", case_sensitive=False), help='Also create predicted labelmap(s) by combining the atlas labelmaps: ' 'avg is naive mathematical average, wavg is weighted average where weights are computed from MI ' 'between the warped atlases and target image, antsJointFusion is local weighted averaging', default='wavg') out = cli.SwitchAttr( ['-o', '--outPrefix'], help='output prefix, output labelmaps are saved as outPrefix-mask.nrrd, outPrefix-cingr.nrrd, ...', mandatory=True) threads= cli.SwitchAttr(['-n', '--nproc'], help='number of processes/threads to use (-1 for all available)', default= 8) debug = cli.Flag('-d', help='Debug mode, saves intermediate labelmaps to atlas-debug-<pid> in output directory') @cli.positional(cli.ExistingFile) def main(self, csvFile): trainingTable = pd.read_csv(csvFile._path) makeAtlases(self.target, trainingTable, self.out, self.fusions, int(self.threads), self.debug) logging.info('Made ' + self.out + '-*.nrrd')
class ProsperDiscordBot(cli.Application): """wrapper for slackbot Main()""" PROGNAME = PROGNAME VERSION = __version__ _log_builder = p_logging.ProsperLogger(PROGNAME, '/var/logs/prosper', config_obj=CONFIG) debug = cli.Flag(['d', '--debug'], help='debug mode, high verbosity for devs') def main(self): """bot main""" if self.debug: self._log_builder.configure_debug_logger() else: self._log_builder.configure_discord_logger() logger = self._log_builder.logger logger.info('Hello World') api_config.LOGGER = logger api_config.CONFIG = CONFIG logger.error('STARTING PROSPERBOT -- DISCORD %s', platform.node()) try: status = bot.run(CONFIG.get('DiscordBot', 'api_token')) except Exception: logger.critical('Going down in flames!', exc_info=True) logger.warning('Discord.py exited unexpectedly: {}'.format(status))
class YnabParse(cli.Application): @cli.switch('--loglevel', argtype=str, help='set the log level') def log_level(self, level): logConfigArgs = dict() numeric_level = getattr(logging, level.upper(), None) # Double-check it's a valid logging level if not isinstance(numeric_level, int): raise ValueError('Invalid log level: %s' % level) logging.basicConfig(level=numeric_level) output_sqlite = cli.SwitchAttr('--to-sqlite', argtype=local.path, help='Convert budget to sqlite') repl = cli.Flag('--repl') @cli.positional(local.path) def main(self, path): # pylint: disable=arguments-differ budget = load_budget(path) if self.output_sqlite: output_to_sqlite.do(budget, self.output_sqlite) else: from ad_hoc import liquid_position, non_liquidable_keywords print('liquid now') for m, balances in liquid_position(budget, ["Guillaume's Checking"]).items(): print(m, ', ', balances.total) # print('liquidable') # for m, balances in liquid_position(budget, non_liquidable_keywords).items(): # print(m, ', ', balances.total) if self.repl: from ptpython.repl import embed embed(globals(), locals())
class RunAll(cli.Application): profile = cli.Flag(["-p", "--profile"], help="Profile (longer) output") @cli.positional(int) def main(self, threads=None): env = local.env(OMP_NUM_THREADS=threads) if threads else local.env() with env: results = make_results(self.profile) failed = [result for result in results if result["code"] != 0] successes = [result for result in results if result["code"] == 0] if failed: colors.fatal.print("Failed:") for result in failed: colors.fatal.print(result["name"], result["code"]) else: colors.success.print("All programs completed.") print() colors.info.print( "{0:20}:\tTotal time (s)\tFit times".format("Program")) for result in successes: fit = ", ".join(MIN_TIME.findall(result["stdout"])) print((colors.success if result["code"] == 0 else colors.warn) | "{0[name]:20}:\t{0[time]}\t{1}".format(result, fit)) if threads: colors.info.print("OMP Threads:", threads)
class Build(cli.Application): publish = cli.Flag("--publish") def main(self): delete("build", "dist", "MANIFEST", local.cwd // "*.egg-info") # generate zip, tar.gz, and win32 installer if self.publish: print("registering...") local.python("setup.py", "register") print("uploading zip and tar.gz") local.python("setup.py", "sdist", "--formats=zip,gztar", "upload") print("uploading win installer") local.python("setup.py", "bdist_wininst", "--plat-name=win32", "upload") # upload to sourceforge print("uploading to sourceforge") dst = "gangesmaster,[email protected]:/home/frs/project/r/rp/rpyc/main/%s/" % ( version_string, ) local["rsync"]("-rv", "dist/", dst) else: local.python("setup.py", "sdist", "--formats=zip,gztar") local.python("setup.py", "bdist_wininst", "--plat-name=win32") delete("build", local.cwd // "*.egg-info") print("Built", [f.basename for f in local.cwd / "dist"])
class GeetPush(cli.ColorfulApplication): """pushes the current local branch to the remote one""" tags = cli.Flag("--tags", help="whether to push tags (default is False)") def main(self, remote, branch="master"): print("pushing to %s/%s..." % (remote, branch))
class Ak(cli.Application): PROGNAME = "ak" VERSION = "1.0" dryrunFlag = cli.Flag(["dry-run"], help="Dry run mode") def log_and_run(self, cmd, retcode=FG): """Log cmd before exec.""" logging.info(cmd) if (self.dryrunFlag): print cmd return True return cmd & RETCODE def log_and_exec(self, cmd, args=[], env=None): """Log cmd and execve.""" logging.info([cmd, args]) if (self.dryrunFlag): print "os.execvpe (%s, %s, env)" % (cmd, [cmd] + args) return True os.execvpe(cmd, [cmd] + args, env) @cli.switch("--verbose", help="Verbose mode") def set_log_level(self): logging.root.setLevel(logging.INFO) logging.info('Verbose mode activated') def main(self, *args): if args: print "Unkown command %r" % (args[0],) return 1 # return error if not self.nested_command: print "No command given" return 1
class GeetPush(cli.Application): """pushes the current local branch to the remote one""" tags = cli.Flag("--tags", help="whether to push tags (default is False)") def main(self, remote, branch="master"): print(f"pushing to {remote}/{branch}...")
class RegistryServer(cli.Application): mode = cli.SwitchAttr(["-m", "--mode"], cli.Set("UDP", "TCP"), default="UDP", help="Serving mode") ipv6 = cli.Flag(["-6", "--ipv6"], help="use ipv6 instead of ipv4") port = cli.SwitchAttr(["-p", "--port"], cli.Range(0, 65535), default=REGISTRY_PORT, help="The UDP/TCP listener port") logfile = cli.SwitchAttr(["--logfile"], str, default=None, help="The log file to use; the default is stderr") quiet = cli.SwitchAttr(["-q", "--quiet"], help="Quiet mode (only errors are logged)") pruning_timeout = cli.SwitchAttr(["-t", "--timeout"], int, default=DEFAULT_PRUNING_TIMEOUT, help="Set a custom pruning timeout (in seconds)") def main(self): if self.mode == "UDP": server = UDPRegistryServer(host='::' if self.ipv6 else '0.0.0.0', port=self.port, pruning_timeout=self.pruning_timeout) elif self.mode == "TCP": server = TCPRegistryServer(port=self.port, pruning_timeout=self.pruning_timeout) setup_logger(self.quiet, self.logfile) server.start()
class FileCopier(cli.Application): overwrite = cli.Flag("-o", help = "If given, overwrite existing files") @cli.switch(["-l", "--log-to-file"], argtype = str) def log_to_file(self, filename): """logs all output to the given file""" handler = logging.FileHandler(filename) logger.addHandler(handler) @cli.switch(["--verbose"], requires=["--log-to-file"]) def set_debug(self): """Sets verbose mode""" logger.setLevel(logging.DEBUG) def main(self, src, dst): if local.path(dst).exists(): if not self.overwrite: logger.debug("Oh no! That's terrible") raise ValueError("Destination already exists") else: delete(dst) logger.debug("I'm going to copy %s to %s", src, dst) copy(src, dst) logger.debug("Great success")