Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
for bit in tids.split(','):
try:
if '-' in bit:
start, stop = [int(e) for e in bit.split('-')]
task_ids.extend(range(start, stop + 1))
else:
task_ids.append(int(bit))
except ValueError:
task_ids.append(bit)
return [e - 1 if isinstance(e, int) else e for e in task_ids] # type: ignore
class TasksChange(ApplicationWithApi):
"""find all tasks specified by user and do self.op on them"""
domain = '' # type: str
noop = cli.Flag(
['--dry-run', '--noop'],
help=_("If passed, won't actually change anything on habitipy server"), # noqa: Q000
default=False)
more_tasks = [] # type: List[Dict[str, Any]]
ids_can_overlap = False
NO_TASK_ID = _("No task_ids found!") # noqa: Q000
TASK_ID_INVALID = _("Task id {} is invalid") # noqa: Q000
PARSED_TASK_IDS = _("Parsed task ids {}") # noqa: Q000
def main(self, *task_ids: TaskId): # type: ignore
super().main()
task_id = [] # type: List[Union[str,int]]
for tids in task_ids:
task_id.extend(tids)
if not task_id:
self.log.error(self.NO_TASK_ID)
return 1
def fix_files(src, version):
for name in src:
with name.open('r') as f:
contents = f.read()
new_contents = fix_text(contents, version)
if contents != new_contents:
print('Converted: {0}'.format(name))
with name.open('w') as f:
f.write(new_contents)
class ModernizeGooFit(cli.Application):
set_version = cli.SwitchAttr(['-v','--version'], cli.Set(*conversion), default='2.0', help='The version to convert')
source = cli.Flag(['--source'], help="Run on the GooFit Source")
@cli.positional(cli.ExistingFile)
def main(self, *src):
if not src:
assert self.source, "You must use the --source flag to run over GooFit's source"
git = local['git']
with local.cwd(DIR / '../'):
src = [local.path(n) for n in
git('ls-files', '--', '*.cpp', '*.h', '*.cu').splitlines()]
fix_files(src, self.set_version)
if __name__ == '__main__':
ModernizeGooFit()
import plumbum
# from plumbum.colorlib import HTMLStyle, StyleFactory
# plumbum.colors = StyleFactory(HTMLStyle)
from plumbum import cli, colors
class MyApp(cli.Application):
PROGNAME = colors.green
VERSION = colors.blue | "1.0.2"
COLOR_GROUPS = {"Meta-switches": colors.bold & colors.yellow}
opts = cli.Flag("--ops", help=colors.magenta | "This is help")
def main(self):
print("HI")
if __name__ == "__main__":
MyApp.run()
#!/usr/bin/env python
import logging
from plumbum import cli, local
from plumbum.path.utils import delete, copy
logger = logging.getLogger("FileCopier")
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")
"the default is stderr", group="Logging")
quiet = cli.Flag(["-q", "--quiet"], help="Quiet mode (only errors will be logged)",
group="Logging")
ssl_keyfile = cli.SwitchAttr("--ssl-keyfile", cli.ExistingFile,
help="The keyfile to use for SSL. Required for SSL", group="SSL",
requires=["--ssl-certfile"])
ssl_certfile = cli.SwitchAttr("--ssl-certfile", cli.ExistingFile,
help="The certificate file to use for SSL. Required for SSL", group="SSL",
requires=["--ssl-keyfile"])
ssl_cafile = cli.SwitchAttr("--ssl-cafile", cli.ExistingFile,
help="The certificate authority chain file to use for SSL. "
"Optional; enables client-side authentication",
group="SSL", requires=["--ssl-keyfile"])
auto_register = cli.Flag("--register", help="Asks the server to attempt registering with "
"a registry server. By default, the server will not attempt to register",
group="Registry")
registry_type = cli.SwitchAttr("--registry-type", cli.Set("UDP", "TCP"),
default="UDP", help="Specify a UDP or TCP registry", group="Registry")
registry_port = cli.SwitchAttr("--registry-port", cli.Range(0, 65535), default=REGISTRY_PORT,
help="The registry's UDP/TCP port", group="Registry")
registry_host = cli.SwitchAttr("--registry-host", str, default=None,
help="The registry host machine. For UDP, the default is 255.255.255.255; "
"for TCP, a value is required", group="Registry")
def main(self):
if not self.host:
self.host = "::1" if self.ipv6 else "127.0.0.1"
if self.registry_type == "UDP":
if self.registry_host is None:
Verbose: True
Include dirs: ['foo/bar', 'spam/eggs']
Compiling: ()
$ python simple_cli.py -v -I foo/bar -Ispam/eggs x.cpp y.cpp z.cpp
Verbose: True
Include dirs: ['foo/bar', 'spam/eggs']
Compiling: ('x.cpp', 'y.cpp', 'z.cpp')
"""
from __future__ import print_function
import logging
from plumbum import cli
class MyCompiler(cli.Application):
verbose = cli.Flag(["-v", "--verbose"], help = "Enable verbose mode")
include_dirs = cli.SwitchAttr("-I", list = True, help = "Specify include directories")
@cli.switch("-loglevel", int)
def set_log_level(self, level):
"""Sets the log-level of the logger"""
logging.root.setLevel(level)
def main(self, *srcfiles):
print("Verbose:", self.verbose)
print("Include dirs:", self.include_dirs)
print("Compiling:", srcfiles)
if __name__ == "__main__":
MyCompiler()
requires=["--ssl-certfile"])
ssl_certfile = cli.SwitchAttr(
"--ssl-certfile",
cli.ExistingFile,
help="The certificate file to use for SSL. Required for SSL",
group="SSL",
requires=["--ssl-keyfile"])
ssl_cafile = cli.SwitchAttr(
"--ssl-cafile",
cli.ExistingFile,
help="The certificate authority chain file to use for SSL. Optional; enables client-side "
"authentication",
group="SSL",
requires=["--ssl-keyfile"])
auto_register = cli.Flag(
"--register",
help="Asks the server to attempt registering with "
"a registry server. By default, the server will not attempt to register",
group="Registry")
registry_type = cli.SwitchAttr(
"--registry-type",
cli.Set(
"UDP",
"TCP"),
default="UDP",
help="Specify a UDP or TCP registry",
group="Registry")
registry_port = cli.SwitchAttr(
"--registry-port",
cli.Range(
0,
import colorlog
from plumbum import cli
import sys
from local_executor import LocalExecutor
from orchestrator import Orchestrator
from vagrant_executor import VagrantExecutor
from urlparse import urlparse
logger = logging.getLogger("orchestrator")
class OrchestratorCli(cli.Application):
PROGNAME = "orchestrator"
VERSION = "0.0.1"
host_orchestrator = cli.Flag(["--host-orchestrator"], help = "If given, the orchestrator assumes to be running on the host OS, and execute all datastream commands via vagrant."+
" The default assumption is that the orchestrator is running on the same (virtual) box as the datastream components (hence doesn't have to go via vagrant)." )
new_topic = cli.Flag(["--new-topic"], help = "If given, new Kafka topics will be created for data and recommendations feeds.", excludes = ['--data-topic', '--recommendations-topic'] )
skip_training_cycle = cli.Flag(["--skip-training"], help = "If given, the training phase in the orchestrator lifecycle is skipped.")
no_control_messages = cli.Flag(["--no-control-messages", '-n'], help = "If given, the orchestrator won't send control messages to the computing environment.")
comp_env = None
data_source = None
recommendation_target = 'fs:/tmp/recommendations'
#The data_topic is meaningless and should be removed
data_topic = 'data'
input_topic = 'input'
recommendation_requests_topic = 'recommendation-requests'
debug = cli.Flag(
'--debug',
help= 'turn on this flag to debug harmonized data (valid only with --process)',
default= False)
reference = cli.SwitchAttr(
'--ref_name',
help= 'reference site name',
mandatory= False)
target = cli.SwitchAttr(
'--tar_name',
help= 'target site name',
mandatory= True)
stats = cli.Flag(
'--stats',
help='print statistics of all sites, useful for recomputing --debug statistics separately')
diffusionMeasures = ['MD', 'FA', 'GFA']
def createTemplate(self):
from buildTemplate import difference_calc, antsMult, warp_bands, \
dti_stat, rish_stat, template_masking, createAntsCaselist
from preprocess import common_processing
# check directory existence
check_dir(self.templatePath, self.force)
from vagrant_executor import VagrantExecutor
from urlparse import urlparse
logger = logging.getLogger("orchestrator")
class OrchestratorCli(cli.Application):
PROGNAME = "orchestrator"
VERSION = "0.0.1"
host_orchestrator = cli.Flag(["--host-orchestrator"], help = "If given, the orchestrator assumes to be running on the host OS, and execute all datastream commands via vagrant."+
" The default assumption is that the orchestrator is running on the same (virtual) box as the datastream components (hence doesn't have to go via vagrant)." )
new_topic = cli.Flag(["--new-topic"], help = "If given, new Kafka topics will be created for data and recommendations feeds.", excludes = ['--data-topic', '--recommendations-topic'] )
skip_training_cycle = cli.Flag(["--skip-training"], help = "If given, the training phase in the orchestrator lifecycle is skipped.")
no_control_messages = cli.Flag(["--no-control-messages", '-n'], help = "If given, the orchestrator won't send control messages to the computing environment.")
comp_env = None
data_source = None
recommendation_target = 'fs:/tmp/recommendations'
#The data_topic is meaningless and should be removed
data_topic = 'data'
input_topic = 'input'
recommendation_requests_topic = 'recommendation-requests'
recommendation_results_topic = 'recommendation-results'
ground_truth_topic = 'ground-truth'
input_data = 'split'
newsreel = False