How to use configure_parser method in Slash

Best Python code snippet using slash

syncrypt

Source:syncrypt Github

copy

Full Screen

...22logger = logging.getLogger('syncrypt')23class SyncryptCmd():24 command = None25 description = None26 def configure_parser(self, parser):27 parser.add_argument('-l', metavar='LOGLEVEL', type=str, default='INFO',28 dest='loglevel', choices=LOGLEVELS,29 help='log level: ' + ', '.join(LOGLEVELS)+ ' (default: INFO)')30 parser.add_argument('-c', metavar='CONFIG', type=str, default=None,31 dest='config', help='work with another config file')32 def __init__(self):33 self.parser = argparse.ArgumentParser(34 description=self.description,35 prog='%s %s' % ('syncrypt', self.command)36 )37 self.configure_parser(self.parser)38 self.config = None39 self.vault_dirs = []40 def parse(self, args):41 self.config = self.parser.parse_args(args)42 async def setup(self, nursery):43 self.app_config = AppConfig(self.config.config)44 setup_logging(self.config.loglevel)45 self.app = SyncryptCLIApp(self.app_config, vault_dirs=self.vault_dirs,46 nursery=nursery)47 await self.app.initialize()48 async def shutdown(self):49 await self.app.close()50 async def run(self):51 raise NotImplementedError()52class SingleVaultCmd(SyncryptCmd):53 '''command that supports only a single vault directory'''54 def __init__(self):55 super(SingleVaultCmd, self).__init__()56 # By default, we operate in the current directory57 self.vault_dirs = ['.']58 def configure_parser(self, parser):59 super(SingleVaultCmd, self).configure_parser(parser)60 parser.add_argument('-d', metavar='DIRECTORY', type=str,61 default='.', dest='directory', help='directory (default: .)')62 async def setup(self, nursery):63 self.vault_dirs = [self.config.directory]64 await super(SingleVaultCmd, self).setup(nursery)65class MultipleVaultCmd(SyncryptCmd):66 '''command that supports multiple vault directories'''67 def __init__(self):68 super(MultipleVaultCmd, self).__init__()69 # By default, we operate in the current directory70 self.vault_dirs = ['.']71 def configure_parser(self, parser):72 super(MultipleVaultCmd, self).configure_parser(parser)73 parser.add_argument('-d', metavar='DIRECTORY', type=str,74 action='append', dest='directory', help='directory (default: .)')75 async def setup(self, nursery):76 # For now, each command will work on a default AppConfig object. When77 # you want app-level configuration, use ``syncrypt_daemon``.78 if self.config.directory: # not None and not empty79 self.vault_dirs = self.config.directory80 await super(MultipleVaultCmd, self).setup(nursery)81class NoVaultCmd(SyncryptCmd):82 '''command that operates without a vault'''83class Clone(NoVaultCmd):84 command = 'clone'85 description = 'clone a remote vault to a local directory'86 def configure_parser(self, parser):87 super(Clone, self).configure_parser(parser)88 parser.add_argument('vault_id', help='vault id or name')89 parser.add_argument('directory', nargs='?', help='local directory')90 async def run(self):91 try:92 from uuid import UUID93 vault_id = str(UUID(self.config.vault_id))94 vault_name = None95 except ValueError:96 vault_id = None97 vault_name = self.config.vault_id98 if vault_id:99 vault = await self.app.clone(vault_id, self.config.directory or vault_id)100 else:101 vault = await self.app.clone_by_name(vault_name, self.config.directory or vault_name)102class Pull(MultipleVaultCmd):103 command = 'pull'104 description = 'pull all files from the latest revision'105 def configure_parser(self, parser):106 super(Pull, self).configure_parser(parser)107 parser.add_argument('-f', '--full', action='store_true',108 help='retrieve complete history instead of changes')109 async def run(self):110 await self.app.pull(full=self.config.full)111class AddUser(SingleVaultCmd):112 command = 'add-user'113 description = 'add another user to this vault'114 def configure_parser(self, parser):115 super(AddUser, self).configure_parser(parser)116 parser.add_argument('email', help='the user\'s email')117 async def run(self):118 await self.app.add_user(self.config.email)119class RemoveFile(SingleVaultCmd):120 command = 'remove-file'121 description = 'remove a file from the vault'122 def configure_parser(self, parser):123 super(RemoveFile, self).configure_parser(parser)124 parser.add_argument('path', nargs='+', help='path to the file(s)')125 async def run(self):126 await self.app.remove_files(self.config.path)127class DeleteVault(MultipleVaultCmd):128 command = 'delete-vault'129 description = 'permanently delete this vault from server (use with care)'130 async def run(self):131 await self.app.delete_vaults()132class UploadVaultKey(SingleVaultCmd):133 command = 'upload-vault-key'134 description = 'upload the vault key encrypted with my user key'135 async def run(self):136 await self.app.upload_vault_key()137class ListVaults(NoVaultCmd):138 command = 'list-vaults'139 description = 'list vaults'140 def configure_parser(self, parser):141 super(ListVaults, self).configure_parser(parser)142 parser.add_argument('-a', '--all', dest='all', action='store_true',143 help='also list vaults without key')144 async def run(self):145 if self.config.all:146 await self.app.print_list_of_all_vaults()147 else:148 await self.app.print_list_of_vaults()149class ListKeys(NoVaultCmd):150 command = 'list-keys'151 description = 'list keys'152 def configure_parser(self, parser):153 super(ListKeys, self).configure_parser(parser)154 parser.add_argument('-u', '--user', action='store', dest='user',155 help='user email to list keys for')156 parser.add_argument('--upload', action='store_true',157 help='upload your public keys to the server')158 parser.add_argument('--art', action='store_true', dest='art',159 help='show ascii art for each key')160 async def run(self):161 if self.config.upload:162 await self.app.upload_identity()163 else:164 await self.app.list_keys(self.config.user, with_art=self.config.art)165class Push(MultipleVaultCmd):166 command = 'push'167 description = 'push local changes to the server'168 def configure_parser(self, parser):169 super(Push, self).configure_parser(parser)170 async def run(self):171 await self.app.push()172class Init(SingleVaultCmd):173 command = 'init'174 description = 'register the directory as a Syncrypt vault'175 def configure_parser(self, parser):176 super(Init, self).configure_parser(parser)177 parser.add_argument('--host', help='remote host (default: storage.syncrypt.space)')178 parser.add_argument('-k', '--upload-vault-key', action='store_true',179 dest='upload_vault_key', help='upload encrypted vault key')180 async def run(self):181 await self.app.init(182 host=self.config.host,183 upload_vault_key=self.config.upload_vault_key184 )185class Info(MultipleVaultCmd):186 command = 'info'187 description = 'show vault information'188 async def run(self):189 await self.app.info()190class ConfigSet(SingleVaultCmd):191 command = 'set'192 description = 'set a vault config parameter'193 def configure_parser(self, parser):194 super(ConfigSet, self).configure_parser(parser)195 parser.add_argument('setting', help='the thing to set')196 parser.add_argument('value', help='the value to set it to')197 async def run(self):198 await self.app.set(self.config.setting, self.config.value)199class ConfigUnset(SingleVaultCmd):200 command = 'unset'201 description = 'unset a vault config parameter'202 def configure_parser(self, parser):203 super(ConfigUnset, self).configure_parser(parser)204 parser.add_argument('setting', help='the thing to unset')205 async def run(self):206 await self.app.unset(self.config.setting)207class Log(MultipleVaultCmd):208 command = 'log'209 description = 'show recent changes (file uploads, deletions, etc)'210 def configure_parser(self, parser):211 super(Log, self).configure_parser(parser)212 parser.add_argument('-v', '--verbose', action='store_true',213 help='print more information')214 async def run(self):215 await self.app.print_log(verbose=self.config.verbose)216class Login(NoVaultCmd):217 command = 'login'218 description = 'login to server and store auth token'219 async def run(self):220 await self.app.login()221class UploadKey(NoVaultCmd):222 command = 'upload-key'223 description = 'uploads your current public user key'224 async def run(self):225 await self.app.upload_identity()226class Register(NoVaultCmd):227 command = 'register'228 description = 'register a new user'229 async def run(self):230 await self.app.register()231class Logout(NoVaultCmd):232 command = 'logout'233 description = 'logout and remove auth token'234 async def run(self):235 await self.app.logout()236class ExportVault(SingleVaultCmd):237 command = 'export-vault'238 description = 'export vault config and keys to backup or share'239 def configure_parser(self, parser):240 super(ExportVault, self).configure_parser(parser)241 parser.add_argument('-o', '--output', dest='filename', help='export filename')242 async def run(self):243 await self.app.export_package(self.config.filename)244class ImportVault(SingleVaultCmd):245 command = 'import-vault'246 description = 'import vault package that has previously been exported'247 def configure_parser(self, parser):248 super(ImportVault, self).configure_parser(parser)249 parser.add_argument(dest='filename', help='filename of the package')250 parser.add_argument(dest='target', help='vault folder to create')251 async def run(self):252 await self.app.import_package(self.config.filename, self.config.target)253class CheckUpdate(NoVaultCmd):254 command = 'check-update'255 description = 'compare the installed version to the latest one'256 async def run(self):257 await self.app.check_update()258class GenerateKey(NoVaultCmd):259 command = 'generate-key'260 description = 'generate your user key'261 async def run(self):262 await self.app.identity.generate_keys()263class ExportKey(NoVaultCmd):264 command = "export-key"265 description = "export your user-key"266 def configure_parser(self, parser):267 super(ExportKey, self).configure_parser(parser)268 parser.add_argument(dest="filename", help="filename of the package")269 async def run(self):270 await self.app.export_user_key(self.config.filename)271class ImportKey(NoVaultCmd):272 command = "import-key"273 description = "import your user-key"274 def configure_parser(self, parser):275 super(ImportKey, self).configure_parser(parser)276 parser.add_argument(dest="filename", help="filename of the package")277 async def run(self):278 await self.app.import_user_key(self.config.filename)279COMMANDS = [280 # Administrative281 Register(),282 Login(),283 Logout(),284 CheckUpdate(),285 # Vault286 Init(),287 Pull(),288 Push(),289 ListVaults(),...

Full Screen

Full Screen

rappelledev.py

Source:rappelledev.py Github

copy

Full Screen

...55 @classmethod56 def get_name(self):57 raise NotImplementedError()58 @classmethod59 def configure_parser(cls, parser):60 raise NotImplementedError()61 def __call__(self, args):62 raise NotImplementedError()63# Commands64class RunPostgresCmd(Command):65 @classmethod66 def get_name(self):67 return "run-postgres"68 @classmethod69 def configure_parser(cls, parser):70 parser.add_argument(71 "args",72 nargs="*",73 help="Arguments passed to docker-compose up"74 )75 def __call__(self, args):76 self._runner.run_docker_compose(77 [78 "up",79 "--force-recreate",80 *(args.args or []),81 "postgres"82 ]83 )84class RunRappelleBeCmd(Command):85 @classmethod86 def get_name(self):87 return "run-rappelle-be"88 @classmethod89 def configure_parser(cls, parser):90 pass91 def __call__(self, args):92 self._runner.run_docker_compose(93 [94 "up",95 "--force-recreate",96 "--build",97 "rappelle-be"98 ]99 )100class RunRappelleWebCmd(Command):101 @classmethod102 def get_name(self):103 return "run-rappelle-web"104 @classmethod105 def configure_parser(cls, parser):106 pass107 def __call__(self, args):108 self._runner.run_docker_compose(["up", "--force-recreate", "--build", "rappelle-web"])109class RunReverseProxyCmd(Command):110 @classmethod111 def get_name(self):112 return "run-revproxy"113 @classmethod114 def configure_parser(cls, parser):115 pass116 def __call__(self, args):117 self._runner.run_docker_compose(118 [119 "up",120 "--force-recreate",121 "--build",122 "--no-deps",123 "revproxy"124 ]125 )126class DockerComposeCmd(Command):127 """ Runs a docker-compose command in the right context """128 @classmethod129 def get_name(self):130 return "docker-compose"131 @classmethod132 def configure_parser(cls, parser):133 parser.add_argument("args", nargs='+', help="Command to run")134 def __call__(self, args):135 self._runner.run_docker_compose(args.args)136class RunHostRevproxyCmd(Command):137 """ Runs a reversr proxy at the host network """138 @classmethod139 def get_name(self):140 return "run-host-revproxy"141 @classmethod142 def configure_parser(cls, parser):143 pass144 def __call__(self, args):145 self._runner.run_docker_compose(["build", "local-revproxy"])146 self._runner.run_docker_compose(["run", "local-revproxy"])147class PostgresShellCmd(Command):148 """ Runs a postgres shell """149 @classmethod150 def get_name(self):151 return "postgres-shell"152 @classmethod153 def configure_parser(cls, parser):154 parser.add_argument("-t", "--test", help="Connect to the test db instead", action="store_true")155 def __call__(self, args):156 db = (TEST_DB_NAME if args.test else DB_NAME)157 self._runner.run_docker_compose(['exec', 'postgres', 'psql', db, POSTGRES_USER])158# ArgumentParser159# Arg parsing160parser = argparse.ArgumentParser(description="Development tools for rappelle")161parser.add_argument(162 "-D",163 "--directory",164 help="the directory with the github repo root"165)166parser.add_argument(167 "--docker-compose-cmd",168 help="json array with comand to use for docker compose"169)170parser.add_argument(171 "-e",172 "--env",173 help="Environment. One of dev or prod.",174 choices=list((x.value for x in Env))175)176subparsers = parser.add_subparsers()177for cmd_cls in Command.__subclasses__():178 name = cmd_cls.get_name()179 doc = cmd_cls.__doc__180 sub_parser = subparsers.add_parser(name, help=doc)181 sub_parser.set_defaults(cmd_cls=cmd_cls)182 cmd_cls.configure_parser(sub_parser)183def main():184 args = parser.parse_args()185 config = read_json_file(CONFIG_FILE) or {}186 env = args.env or config.get("env") or Env.prod.value187 assert env in (x.value for x in Env), f"Invalid env \"{env}\""188 docker_compose_cmd = (189 args.docker_compose_cmd190 or config.get("docker-compose-cmd", None)191 or ["/bin/env", "docker-compose"]192 )193 directory = os.path.expanduser(args.directory or config.get("directory") or "~/rappelledev")194 logging.info("Starting with env=%s directory=%s docker_compose_cmd=%s", env, directory, docker_compose_cmd)195 runner = Runner(cwd=directory, docker_compose_cmd=docker_compose_cmd, env=env)196 args.cmd_cls(runner)(args)...

Full Screen

Full Screen

utils.py

Source:utils.py Github

copy

Full Screen

1from argparse import ArgumentParser2from contextlib import contextmanager3from tempfile import mkdtemp4from conda.gateways.disk.delete import rm_rf5from conda_env.cli.main import do_call as do_call_conda_env6from conda_env.cli.main_create import configure_parser as create_configure_parser7from conda_env.cli.main_update import configure_parser as update_configure_parser8from conda_env.cli.main_export import configure_parser as export_configure_parser9from conda.utils import massage_arguments10class Commands:11 CREATE = "create"12 UPDATE = "update"13 EXPORT = "export"14parser_config = {15 Commands.CREATE: create_configure_parser,16 Commands.UPDATE: update_configure_parser,17 Commands.EXPORT: export_configure_parser,18}19@contextmanager20def make_temp_envs_dir():21 envs_dir = mkdtemp()22 try:23 yield envs_dir24 finally:25 rm_rf(envs_dir)26def run_command(command, env_name, *arguments):27 arguments = massage_arguments(arguments)28 args = [command, "-n", env_name, "-f"] + arguments29 p = ArgumentParser()30 sub_parsers = p.add_subparsers(metavar='command', dest='cmd')31 parser_config[command](sub_parsers)32 args = p.parse_args(args)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful