Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def exit(self):
try:
self.cmd().exit()
except Pyro4.errors.ConnectionClosedError:
pass
def cmd(self):
return self._cmd
class TestApplication(cli.Application):
connections = cli.SwitchAttr(['-c'], int, default = 1, help = "Number of connections per instance" )
instances = cli.SwitchAttr(['-i'], int, default = 3, help = "Number of instances to spawn" )
delay = cli.SwitchAttr(['-d'], int , default = 1, help = "Delay in seconds for probing test results")
packet_size = cli.SwitchAttr(['-s'], int, default = 10 ** 3, help = "Size of websocket frame")
ws_server = cli.SwitchAttr(['-w'], str, default = "127.0.0.1:8080", help = "Websocket server host[:port]")
iteration = cli.SwitchAttr(['--iterations'], int, default = 10, help = "Number of test results probing iterations")
remotes = cli.SwitchAttr(['--remote'], str, list = True, default = [],
help = "remote user@address of the remote machine to run client process on")
@cli.switch('--python-path', str, help = "Alternative python interpitor path.")
def python_path(self, new_path):
global python_cmd
python_cmd = new_path
@cli.switch('--script-path', str, help = "Alternative worker script path")
def script_path(self, new_path):
global client_script_path
client_script_path = new_path
def main(self):
def calcTotalMem(mems):
return "{}K".format(reduce(lambda x, y: x + int(y.replace('K','')), mems, 0))
self._host = cmd & BG
uri = self._host.proc.stdout.readline().decode('ascii').strip()
logger.debug ("Process spawned, Pyro4 uri: {}".format(uri))
self._cmd = Pyro4.Proxy(uri)
def exit(self):
try:
self.cmd().exit()
except Pyro4.errors.ConnectionClosedError:
pass
def cmd(self):
return self._cmd
class TestApplication(cli.Application):
connections = cli.SwitchAttr(['-c'], int, default = 1, help = "Number of connections per instance" )
instances = cli.SwitchAttr(['-i'], int, default = 3, help = "Number of instances to spawn" )
delay = cli.SwitchAttr(['-d'], int , default = 1, help = "Delay in seconds for probing test results")
packet_size = cli.SwitchAttr(['-s'], int, default = 10 ** 3, help = "Size of websocket frame")
ws_server = cli.SwitchAttr(['-w'], str, default = "127.0.0.1:8080", help = "Websocket server host[:port]")
iteration = cli.SwitchAttr(['--iterations'], int, default = 10, help = "Number of test results probing iterations")
remotes = cli.SwitchAttr(['--remote'], str, list = True, default = [],
help = "remote user@address of the remote machine to run client process on")
@cli.switch('--python-path', str, help = "Alternative python interpitor path.")
def python_path(self, new_path):
global python_cmd
python_cmd = new_path
@cli.switch('--script-path', str, help = "Alternative worker script path")
def script_path(self, new_path):
global client_script_path
print("hello world")
class AppA(cli.Application):
@cli.switch(['--one'])
def one(self):
pass
two = cli.SwitchAttr(['--two'])
class AppB(AppA):
@cli.switch(['--three'])
def three(self):
pass
four = cli.SwitchAttr(['--four'])
def main(self):
pass
# Testing #363
class TestInheritedApp:
def test_help(self, capsys):
_, rc = AppB.run(["AppB", "-h"], exit = False)
assert rc == 0
stdout, stderr = capsys.readouterr()
assert "--one" in stdout
assert "--two" in stdout
assert "--three" in stdout
assert "--four" in stdout
class TestCLI:
be given multiple times
-e VALUE:str sets the eggs attribute
-v increases the verbosity level; may be given multiple times
"""
class TestApp(CompApplication):
@cli.switch(["a"])
def spam(self):
print("!!a")
@cli.switch(["b", "bacon"], argtype=int, mandatory = True)
def bacon(self, param):
"""give me some bacon"""
print ("!!b", param)
eggs = cli.SwitchAttr(["e"], str, help = "sets the eggs attribute")
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 ArgTest(unittest.TestCase):
def test_firstword(self):
self.assertEqual(TestApp._autocomplete_args('./TestApp ', 9), [''])
def write(self, text):
pass
def close(self, *args, **kw):
"""
This will force the thread to exit.
"""
self.exiting = True
# # #
class TwisterRunner(cli.Application):
userName = cli.SwitchAttr(['-u', '--user'], str, default='',
help='The username')
epName = cli.SwitchAttr(['-e', '-ep', '--epname'], str, default='',
help='The Execution Process name')
cePath = cli.SwitchAttr(['-s', '--server'], str, default='',
help='The Central Engine RPyc IP:Port')
logFile = cli.Flag(['-l', '--log'], default=False,
help='Log stdout in a file? Default: DISABLED.')
def __del__(self):
print('Caught Execution Process EXIT !\n')
self.exit()
def main(self):
global userName, epName, cePath
N_zero = cli.SwitchAttr(
'--nzero',
help= 'number of zero padding for denoising skull region during signal reconstruction',
default= 10)
force = cli.Flag(
['--force'],
help='turn on this flag to overwrite existing data',
default= False)
travelHeads = cli.Flag(
['--travelHeads'],
help='travelling heads',
default= False)
resample = cli.SwitchAttr(
'--resample',
help='voxel size MxNxO to resample into',
default= False)
bvalMap = cli.SwitchAttr(
'--bvalMap',
help='specify a bmax to scale bvalues into',
default= False)
denoise = cli.Flag(
'--denoise',
help='turn on this flag to denoise voxel data',
default= False)
create = cli.Flag(
'--create',
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):
servers. In order for clients to use discovery, a registry service must
be running somewhere on their local network.
"""
from plumbum import cli
from rpyc.utils.registry import REGISTRY_PORT, DEFAULT_PRUNING_TIMEOUT
from rpyc.utils.registry import UDPRegistryServer, TCPRegistryServer
from rpyc.lib import setup_logger
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)
process = cli.Flag(
'--process',
help= 'turn on this flag to harmonize',
default= False)
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