def main(): """ Main function of the Swarmrob CLI :return: """ if os.geteuid(): sys.exit( colored.red("Swarmrob needs to be started with root privileges")) llogger = local_logger.LocalLogger() llogger.log_call(sys._getframe().f_code.co_name) params = CMDParser(include_help=False).parse_arguments() llogger.enable = params.verbose args = Args() with indent(4, quote=''): puts( colored.green( "Swarmbot - Container Orchestration for Robotic Applications")) try: switch_command(str(args.get(0))) except KeyError: with indent(4, quote='>>'): puts(colored.red(str(args.get(0)) + " is not a valid command")) puts(colored.red("Type 'swarmrob help' for a command list")) except Exception as e: puts(colored.red("An unknown error occurred")) llogger.exception(e, "An unknown error occurred") llogger.error(traceback.format_exc()) sys.exit(1)
def __init__(self, cnf): """ Initializes storage client by given configuration file :param cnf: path to configuration file :type cnf: str """ self.storage = VStorage(cnf) self.cli = Args() self.process()
def main(): puts(colored.green('Welcome to Golf!')) puts() args = Args() if args.contains(['-r', '--rules']): _do_rules() return _do_game()
def main(): """ Main method of the worker :return: """ llogger = local_logger.LocalLogger() llogger.log_call(sys._getframe().f_code.co_name) args = Args() try: switch_command(str(args.get(1))) except KeyError: with indent(4, quote='>>'): puts(colored.red(str(args.get(1)) + " is not a valid command")) puts(colored.red("Type 'swarmrob help' for a command list"))
def parse_args(): args = {} for a in Args().all: if a.startswith('--'): if '=' in a: # named param i = a.index('=') k = a[2:i] v = a[i + 1:] if not k in args: args[k] = [] args[k].append(v) else: # flag args[a[2:]] = True elif a.startswith('-') and '=' not in a: # short flag for f in a[1:]: args[f] = True else: # nameless param if 'params' not in args: args['params'] = [] args['params'].append(a) return args
def main(): """ Main function of the Swarmrob Master CLI :return: """ llogger = local_logger.LocalLogger() llogger.log_call(sys._getframe().f_code.co_name) console_arguments = Args() try: switch_command(str(console_arguments.get(1))) except KeyError: llogger.exception(traceback.format_exc()) with indent(4, quote='>>'): puts( colored.red( str(console_arguments.get(1)) + " is not a valid command")) puts(colored.red("Type 'swarmrob help' for a command list"))
def main(): args = Args() input_path = os.path.realpath(args.get(0)) output_path = os.path.realpath(args.get(1)) image_names = ['homographies', 'masks', 'stitched'] # Scan the input directory to get the structure whiteboards = {} # whiteboards[whiteboard name] = list of stitching names num_stitchings = 0 for whiteboard_path in subdirs(input_path): stitchings = [] for stitching_path in subdirs(whiteboard_path): files = [os.path.join(stitching_path, part + '.png') for part in image_names] if all(os.path.exists(file) for file in files): stitchings.append(os.path.basename(stitching_path)) num_stitchings += 1 if stitchings: whiteboards[os.path.basename(whiteboard_path)] = stitchings # Remake the output directory shutil.rmtree(output_path) os.mkdir(output_path) # Write the structure with open(os.path.join(output_path, 'whiteboards.json'), 'w') as f: json.dump(whiteboards, f) # Write the deepzooms num_deepzooms_written = 0 for whiteboard_name, stitchings in whiteboards.iteritems(): input_whiteboard_path = os.path.join(input_path, whiteboard_name) output_whiteboard_path = os.path.join(output_path, whiteboard_name) os.mkdir(output_whiteboard_path) for stitching_name in stitchings: input_stitching_path = os.path.join(input_whiteboard_path, stitching_name) output_stitching_path = os.path.join(output_whiteboard_path, stitching_name) os.mkdir(output_stitching_path) for image_name in image_names: print (num_deepzooms_written + 1), '/', len(image_names) * num_stitchings cached_deepzoom( os.path.join(input_stitching_path, image_name + '.png'), os.path.join(output_stitching_path, image_name) ) num_deepzooms_written += 1
def cli(): # args = Args() # puts(colored.red('Aruments passed in: ') + str(args.all)) # puts(colored.red('Aruments grouped passed in: ') + str(args.grouped)) all_args = Args().grouped args_len = len(all_args) # print(args_len) if args_len == 1: run() elif args_len == 2: # print(all_args.keys()) arg = list(all_args.keys())[1] # print(arg) if arg in ['-show']: show_config() elif arg in ['-q']: qids = [int(x.strip()) for x in all_args[arg].all] # print(qids) run_by_id(qids) elif arg in ['-h', '-help']: show_help() elif arg in ['-set']: cli_set_config() elif arg in ['-readme']: readme() else: puts('You entered wrong command') show_help() else: puts('You entered wrong command') show_help()
def logy(argsx): from clint.arguments import Args from clint.textui import puts, colored as coloredx, indent args = Args() print() with indent(4, quote='>>>'): puts(coloredx.blue('Command Arguments: ') + str(argsx)) puts(coloredx.blue('Arguments passed in: ') + str(args.all)) puts(coloredx.blue('Flags detected: ') + str(args.flags)) puts(coloredx.blue('Files detected: ') + str(args.files)) puts(coloredx.blue('NOT Files detected: ') + str(args.not_files)) puts(coloredx.blue('Grouped Arguments: ') + str(dict(args.grouped))) print()
def main(): cli = DouBanCLI() args = Args() # grouped['_'] does not contain flags grouped_args = args.grouped['_'].all if len(grouped_args) <= 1: print(colored.yellow('USAGE: douban book book_name')) print(colored.yellow('USAGE: douban movie movie_name')) else: action = grouped_args[0] name = fetch_names(grouped_args) show_detail = True if '-d' in args.flags.all else False cli.route(action, name, {'show_detail': show_detail})
def main(): f = Figlet(font='slant') print(f.renderText('Website Classifier')) args = Args() with indent(4, quote='>>>'): puts( colored.blue( "This program classifies program into 11 different categories. The model is trained on 59k+ websites using tfidf features and Logistic regression model." )) puts(colored.blue('Args received: ') + str(args.all)) print() website_url = args[0] # Initializing the WebsiteClassifierTool Object to predic the website class. wct = lib.WebsiteClassifierTool() result = wct.predict(website_url) # print the final results of the classification print(colored.yellow("Result:")) print(colored.green(result))
def parse_cmdline(): ''' Will parse our commandline flags and set up our dictionary :param: :return: configfile, config ''' cfgfile = 'private/config.ini' # This was sane defaults, but now I don't want it configs = {} args = Args() gargs = args.grouped if args.contains('-h'): print_help() sys.exit(0) # Bit hacky, but whatever if args.contains('-c'): cfgfile = gargs['-c'][0] if args.contains('-l'): configs['logging']['logfile'] = gargs['-l'][0] puts(colored.green('setting logfile location')) if args.contains('-d'): configs['status'] = ['recreate'] return cfgfile, configs if args.contains('-state'): configs['status'] = ['query_state', gargs['-state'][0]] return cfgfile, configs if args.contains('-date'): configs['status'] = ['query_date', gargs['-date'][0]] return cfgfile, configs return cfgfile, configs
def main(): ''' Main application for queryinmt ''' # argparsing made easy args = Args() gargs = args.grouped cfg = get_config() if args.contains('-h'): print_help(args[0]) sys.exit(0) # Get our db object dbobj = queryObj(cfg) if args.contains('-state'): state = gargs['-state'][0].upper() puts(colored.yellow('Calling with state "{}"'.format(state))) result = dbobj.do_qry('states', state) if result: dbobj.print_results() elif args.contains('-date'): dt = gargs['-date'][0] result = dbobj.do_qry('dates', dt) if result: dbobj.print_results() elif args.contains('-get'): dt = gargs['-get'][0] result = dbobj.do_qry('get_state') if result: dbobj.print_results() else: print_help(args[0]) sys.exit(0)
#!/usr/bin/env python # -*- coding: utf-8 -*- # Print text in all colors from clint.textui import colored, puts, indent from clint.arguments import Args args = Args() if __name__ == '__main__': puts('Tests:') with indent(4): puts('%s All tests passed 1.' % colored.green('✔')) puts('%s Failed? ' % colored.red('✖')) puts('') puts('Greet:') with indent(4): puts(colored.red('Здравствуйте')) puts(colored.blue('नमस्ते')) puts(colored.cyan('γειά σου')) puts('') puts('Arguments:') with indent(4): puts('%s' % colored.red(args[0])) puts('')
def migrate(argv=sys.argv): args = Args(argv) puts( colored.blue( "This program will guide you through migrating your Cloud 9 workspace " "onto the school's servers.")) puts() # Try to figure out if we're on one of the lab machines. It is unlikely # that someone would have their user's home directory mounted on their # local system. home_path = os.environ["HOME"] if "--force-on-lab" not in args and not os.path.ismount(home_path): raise RuntimeError("You are not on a lab machine.") downloads = lambda: os.listdir( os.path.join(os.environ["HOME"], "Downloads")) if "--use-old-zip" not in args and "cs010_assignments.zip" in downloads(): puts( colored.red("You have an old cs010_assignments.zip file in your " "downloads directory, delete it.")) puts() puts("Waiting...", newline=False) while "cs010_assignments.zip" in downloads(): sys.stdout.flush() time.sleep(4) puts(".", newline=False) puts(" Done.") puts( colored.blue( "The first thing you need to do is download your entire Cloud 9 " "workspace. To do this...")) with indent(4): puts("1. Go into your private workspace: " + colored.green("cs010_assignments")) puts("2. Click File->Download Project") puts("3. Make sure it saves into your Downloads folder as " + colored.green("cs010_assignments.zip")) puts() puts("Waiting...", newline=False) while "cs010_assignments.zip" not in downloads(): sys.stdout.flush() time.sleep(4) puts(".", newline=False) puts(" Done.") # Inspect the zip file and make sure the assignments are there. zip_path = os.path.join(home_path, "Downloads", "cs010_assignments.zip") zipped = zipfile.ZipFile(zip_path) desired_files = ["assignment0%d/" % (i, ) for i in xrange(10)] + \ ["assignment10/"] if "--ignore-bad-zip" not in args and \ not all(i in zipped.namelist() for i in desired_files): puts(colored.red("Files in zip file: " + str(zipped.namelist()))) raise RuntimeError("Bad zip file found.") zipped.close() # Make a backup of the zip file backup_file = tempfile.NamedTemporaryFile(prefix="assignments-backup", dir=home_path, delete=False) shutil.copyfileobj(open(zip_path, "rb"), backup_file) puts(colored.green("Created backup of assignments at " + backup_file.name)) puts() backup_file.close() puts( colored.blue( "Now you have to delete your private workspace on Cloud 9.")) with indent(4): puts("1. Click your cs010_assignments workspace.") puts("2. Click delete on the right middle of the page.") puts( colored.red("Note that we're ONLY delete the one private " "workspace, no others.")) puts() while raw_input("Have you done this? [y/n]: ") != "y": pass puts() puts(colored.blue("Now you must create your new workspace.")) with indent(4): puts("1. Click Create New Workspace->Create New Workspace") puts("2. Select SSH (has a little red beta above it)") puts("3. Type " + colored.green("hammer.cs.ucr.edu") + " for the hostname") puts("4. Type your UCR username (ex: mine is jsull003)") puts("5. Copy and paste all of the text under " + colored.green("Your SSH key") + " into the prompt below") puts() KEY_RE = re.compile("ssh-rsa \S{300,} [A-Za-z0-9]+@*.") while True: ssh_key = raw_input("Paste Your SSH Key: ").strip() if "--ignore-bad-key" not in args and KEY_RE.match(ssh_key) is None: puts(colored.red("This is not your SSH key, try again.")) else: break key_path = "/extra/si/%s/pub.key" % (os.environ["LOGNAME"], ) open(key_path, "wb").write(ssh_key + "\n") puts(colored.blue("All done! Key saved to " + key_path))
def line_count_in_path(node_path, ext='.php', with_comment=True, with_empty_line=False): if path.isfile(node_path): return line_count(node_path, with_comment, with_empty_line, ext) elif path.isdir(node_path): return line_count_in_dir(node_path, ext, with_comment, with_empty_line) else: raise Exception("错误的文件路径") if __name__ == '__main__': all_args = Args().grouped for item in all_args: if item == '-p' or item == '--path': all_path = all_args[item].all elif item == '-e' or item == '--ext': all_ext = all_args[item].all try: all_path except NameError as e: all_path = ['.'] try: all_ext except NameError as e: all_ext = ['.php']
import os import glob import sys from clint.arguments import Args import yaml import stitching import spimage if __name__ == "__main__": args = Args() config_path_rel = args.get(0) config = yaml.load(open(config_path_rel)) c_files = config['files'] c_feature_detection = config['feature_detection'] c_stitching = config['stitching'] config_dir = os.path.dirname(os.path.realpath(config_path_rel)) establishing = spimage.Image.from_file(os.path.join(config_dir, c_files['establishing'])) # TODO: allow arrays of images rather than just globs closes = map(spimage.Image.from_file, glob.glob(os.path.join(config_dir, c_files['closes']))) output_dir = os.path.join( config_dir, os.path.basename(config_path_rel).replace('.', '_') + '_out') if not os.path.exists(output_dir):
#puts(colored.magenta("Total Data: ") + tds[4].text) sd = str(tds[4].text) # print(float(filter(str.isdigit, sd))) x = map(float, re.findall(r'[+-]?[0-9.]+', sd)) textmyself.textmyself("Hey! Rahul you have used " + sd) print "-" * 40 if __name__ == '__main__': print "-" * 40 puts(colored.white(" " * 15 + "ProntoUsage")) print "-" * 40 debug = False args = Args().grouped if '--debug' in args.keys(): debug = True if '--delete' in args.keys(): try: os.remove('cred.json') except OSError: pass if os.path.isfile('cred.json'): with open('cred.json', 'r') as f: data = json.load(f) username = data['username'] password = data['password'] else:
class VCLIApplication: APP = "vgrepo" VER = "1.1.0" DESC = "Utility for managing Vagrant repositories written in Python" COLUMN_WIDTH = 16 @staticmethod def success(msg="OK"): """ Displays message with a green color :param msg: message string :type msg: str :return: """ puts(colored.green(msg)) @staticmethod def error(msg="FAIL"): """ Displays message with a red color and then exit :param msg: message string :type msg: str :return: """ puts(colored.red(msg)) sys.exit(1) @staticmethod def print_column(text, size): """ Displays text in the column with a specified width :param text: message string :type text: str :param size: width of the column :type size: int :return: """ puts(min_width(text, size), newline=False) @staticmethod def print_row(els): """ Display line with a set of columns :param els: list of columns :type els: list :return: """ for f in els: VCLIApplication.print_column(f['name'], f['width']) puts() def process(self): """ Handles arguments and execute commands :return: """ if self.cli.contains(['h', 'help']): self.help_command() elif self.cli.contains(['a', 'add']): self.add_command() elif self.cli.contains(['l', 'list']): self.list_command() elif self.cli.contains(['r', 'remove']): self.remove_command() else: self.help_command() def __init__(self, cnf): """ Initializes storage client by given configuration file :param cnf: path to configuration file :type cnf: str """ self.storage = VStorage(cnf) self.cli = Args() self.process() def add_command(self): """ Adds image or repository to the storage :return: """ args = { 'src': self.cli.files[0] if self.cli.files and len(self.cli.files) > 0 else None, 'name': self.cli.value_after('-n') or self.cli.value_after('--name'), 'version': self.cli.value_after('-v') or self.cli.value_after('--version'), 'desc': self.cli.value_after('-d') or self.cli.value_after('--desc'), 'provider': self.cli.value_after('-p') or self.cli.value_after('--provider') } if not args['src']: self.error("Error: source is not specified") if not args['version']: self.error("Error: version is not specified") try: self.storage.add( src=args['src'], name=args['name'], version=args['version'], desc=args['desc'], provider=args['provider'], ) except VImageVersionFoundError: self.error("Error: version is already exists") else: self.success() def list_command(self): """ Displays list of available repositories and images inside of them :return: """ args = { 'name': self.cli.value_after('-n') or self.cli.value_after('--name') } self.print_row([ { 'name': colored.yellow("NAME"), 'width': self.COLUMN_WIDTH }, { 'name': colored.yellow("VERSION"), 'width': self.COLUMN_WIDTH }, { 'name': colored.yellow("PROVIDER"), 'width': self.COLUMN_WIDTH }, { 'name': colored.yellow("URL"), 'width': self.COLUMN_WIDTH * 4 }, ]) for repo in self.storage.list(args['name']): meta = repo.info for version in meta.versions: for provider in version.providers: self.print_row([ { 'name': meta.name, 'width': self.COLUMN_WIDTH }, { 'name': version.version, 'width': self.COLUMN_WIDTH }, { 'name': provider.name, 'width': self.COLUMN_WIDTH }, { 'name': repo.repo_url, 'width': self.COLUMN_WIDTH * 4 }, ]) def remove_command(self): """ Removes image or repository from the storage :return: """ args = { 'name': self.cli.value_after('r') or self.cli.value_after('remove'), 'version': self.cli.value_after('-v') or self.cli.value_after('--version') } if not args['name']: self.error("Error: name is not specified") if not args['version']: self.error("Error: version is not specified") try: self.storage.remove( name=args['name'], version=args['version'], ) except [IOError, OSError]: self.error("Error: unable to delete image or repository") else: self.success() @staticmethod def help_command(): """ Displays usage message :return: """ usage = VCLIUsage(VCLIApplication.APP, VCLIApplication.VER, VCLIApplication.DESC) usage.add_command(cmd="a:add", desc="Add image into the Vagrant's repository") usage.add_command(cmd="l:list", desc="Show list of available images") usage.add_command(cmd="r:remove", desc="Remove image from the repository") usage.add_command(cmd="h:help", desc="Display current help message") usage.add_option(option="v:version", desc="Value of version of the box") usage.add_option(option="n:name", desc="Name of box in the repository") usage.add_option(option="d:desc", desc="Description of the box in the repository") usage.add_option(option="p:provider", desc="Name of provider (e.g. virtualbox)") usage.add_example( "{app} add image.box --name box --version 1.0.1".format( app=VCLIApplication.APP)) usage.add_example("{app} remove powerbox --version 1.1.0".format( app=VCLIApplication.APP)) usage.add_example("{app} list".format(app=VCLIApplication.APP)) usage.render()
import unittest from lib.etl.dispatcher import ETLDispatcher from lib.history.dao import create_tables from lib.new_relic.client import NewRelicClient from tests.test_app_loads import AppLoadsTestCase from tests.test_errors import ExceptionsTestCase, CrashesTestCase from tests.test_history import HistoryTestCase from tests.test_performance import PerformanceTestCase from tests.test_transactions import TransactionsTestCase sys.path.insert(0, os.path.abspath('..')) from clint.arguments import Args from clint.textui import puts, colored, indent all_args = Args() logging.getLogger().addHandler(logging.StreamHandler()) logging.getLogger().setLevel(logging.DEBUG) NR_ACCOUNT_ID = str(os.environ.get('NR_ACCOUNT_ID')) NR_INSERT_KEY = str(os.environ.get('NR_INSERT_KEY')) MODE_SPECIFIER = ('^test|upload$') with indent(4, quote='>>>'): puts(colored.green('Arguments passed in: ') + str(all_args.all)) args = all_args.not_flags if not len(args): puts(colored.red('Mode Required. Valid input: %s' % MODE_SPECIFIER))
def main(): args = Args() puts(colored.yellow('Aruments passed in: ') + str(args.all)) puts(colored.yellow('Flags detected: ') + str(args.flags)) arg_cmd = args.get(0) puts(colored.cyan('Command: ') + str(arg_cmd)) if arg_cmd == 'start': start_ec2() elif arg_cmd == 'stop': stop_ec2() elif arg_cmd == 'ssh': ssh_login() elif arg_cmd == 'launch': ssh_launch() elif arg_cmd == 'scp': scp() elif arg_cmd == 'attach-volume': attach_volume() elif arg_cmd == 'detach-volume': detach_volume() elif arg_cmd == 'create-stack': arg1 = args.get(1) if arg1: stack_name = args.get(1) stack_exists = validate_stack_exists(stack_name) else: stack_name = prompt.query("What's the name of your stack?") stack_exists = validate_stack_exists(stack_name) if (stack_exists): puts(colored.red(f'Stack named {stack_name} already exists')) else: create_stack(stack_name) elif arg_cmd == 'update-stack': arg1 = args.get(1) if arg1: stack_name = args.get(1) stack_exists = validate_stack_exists(stack_name) else: stack_name = choose_stack() stack_exists = True if not stack_exists: puts(colored.red(f'Stack named {stack_name} does not exist')) else: update_stack(stack_name) elif arg_cmd == 'check-status': list_all_ec2() elif arg_cmd == 'create-ecr': # Should this be part of the stack? create_ecr_registry() elif arg_cmd == 'attach-volume': attach_volume() elif arg_cmd == 'choose-stack': choose_stack() elif arg_cmd == 'list-keypairs': list_keypairs() elif arg_cmd == 'upload-keys': upload_keys() elif arg_cmd == 'delete-stack': arg1 = args.get(1) if arg1: stack_name = args.get(1) stack_exists = validate_stack_exists(stack_name) else: stack_name = choose_stack() stack_exists = True if stack_exists: delete_stack(stack_name) else: puts(colored.red(f'Stack {stack_name} does not exist'))
def get_arg(name: str, default=None, optional: bool = False): if args.grouped.get(name) and args.grouped.get(name)[0]: return args.grouped.get(name)[0] if optional or default != None: return default print("Expected argument \"{}\" but got nothing!".format(name)) exit(1) def get_bool_arg(name: str): return args.grouped.get(name) != None # Parse args flags args = Args() flags = set() # remove flags from args for flag in args.flags.all: if flag[:2] == '--': continue args.remove(flag) flags = flags.union(flag[1:]) # if verbose mode is on, print args if 'v' in flags: puts(colored.blue('Grouped Arguments: ') + str(dict(args.grouped))) puts(colored.blue('Flags: ') + str(flags)) print()
print "-" * 40 puts(colored.cyan(" " * 17 + "Usage")) print "-" * 40 puts(colored.magenta("Total Time: ") + tds[1].text) puts(colored.magenta("Uploaded: ") + tds[2].text) puts(colored.magenta("Downloaded: ") + tds[3].text) puts(colored.magenta("Total Data: ") + tds[4].text) print "-" * 40 if __name__ == '__main__': print "-" * 40 puts(colored.white(" " * 15 + "ProntoUsage")) print "-" * 40 debug = False args = Args().grouped if '--debug' in args.keys(): debug = True if '--delete' in args.keys(): try: os.remove('cred.json') except OSError: pass if os.path.isfile('cred.json'): with open('cred.json', 'r') as f: data = json.load(f) username = data['username'] password = data['password'] else: