def main(): """Converter main dispatch.""" # CLI argument handling. input_docs = scrub_input_paths(args.files) path_export = args.get(1) puts_err(colored.blue('Redis Docs Converter')) with indent(2): if (input_docs is None) or (path_export is None): puts_err('{0} {1}'.format(colored.green('Usage:'), USAGE)) sys.exit(64) with indent(3, quote=' .'): puts_err('Converting docs from \'{0}\'.'.format( colored.red(args.get(0)))) mkdir_p(path_export) os.chdir(path_export) for path in progress.bar(input_docs, label=' '): fname = path.split(os.sep)[-1] fname = fname.replace('.html', '.rst') with open(path, 'r') as f: html = convert_html_to_rst(f.read()) with open(fname, 'w') as f: f.write(html) puts('Done! {0}'.format(colored.yellow(r'\o/')))
def cmd_sprout(args): """Legit Sprout command.""" off_branch = args.get(0) new_branch = args.get(1) if new_branch is None: new_branch = off_branch off_branch = repo.head.ref.name if not off_branch: display_available_branches() sys.exit() branch_names = get_branch_names() if off_branch not in branch_names: print "{0} doesn't exist. Use a branch that does.".format( colored.yellow(off_branch)) sys.exit(1) if new_branch in branch_names: print "{0} already exists. Use a unique name.".format( colored.yellow(new_branch)) sys.exit(1) if repo.is_dirty(): status_log(stash_it, 'Saving local changes.') status_log( sprout_branch, 'Branching {0} to {1}.'.format(colored.yellow(off_branch), colored.yellow(new_branch)), off_branch, new_branch)
def main(): """Primary Legit command dispatch.""" if (args.get(0) in cmd_map) or (args.get(0) in short_map): arg = args.get(0) args.remove(arg) if arg in short_map: arg = short_map.get(arg) cmd_map.get(arg).__call__(args) sys.exit() elif args.contains(('-h', '--help')): display_help() sys.exit(1) elif args.contains(('-v', '--version')): display_version() sys.exit(1) else: if settings.git_transparency: # Send everything to git git_args = list(sys.argv) if settings.git_transparency is True: settings.git_transparency = 'git' git_args[0] = settings.git_transparency sys.exit(call(' '.join(git_args), shell=True)) else: display_info() sys.exit(1)
def main(): services = sunlight.available_services() service = services.get(args.get(0), None) if service is not None: available_methods = [ m for m in dir(service) if not m.startswith('_') and m != 'get' ] if args.get(1) in available_methods: params = dict([ (g[0][2:], g[1].get(0)) for g in args.grouped.items()[1:] if g[0].startswith('--') ]) fn_args = [g.split(',') for g in args.grouped.get('_')[2:]] fn_args = list(itertools.chain.from_iterable(fn_args)) resp = getattr(service, args.get(1))(*fn_args, **params) if isinstance(resp, EntityList) or isinstance(resp, EntityDict): resp = resp.data sys.stdout.write(json.dumps(resp, indent=2) + '\n') else: help(methods=available_methods) # missing or invalid method param else: help(services=services) # missing or invalid service parameter
def cmd_graft(args): branch = args.get(0) into_branch = args.get(1) if not branch: display_available_branches() sys.exit() branch_names = get_branch_names() remote_branch_names = get_branch_names(local=False) if branch not in branch_names: print "{0} doesn't exist. Use a branch that does.".format( colored.yellow(branch)) sys.exit(1) if branch in remote_branch_names: print "{0} is published. To graft it, unpublish it first.".format( colored.yellow(branch)) sys.exit(1) if into_branch not in branch_names: print "{0} doesn't exist. Use a branch that does.".format( colored.yellow(into_branch)) sys.exit(1) # Go to new branch. switch_to(into_branch) status_log( graft_branch, 'Grafting {0} into {1}.'.format(colored.yellow(branch), colored.yellow(into_branch)), branch)
def main(): services = sunlight.available_services() service = services.get(args.get(0), None) if service is not None: available_methods = [ m for m in dir(service) if not m.startswith('_') and m != 'get' ] if args.get(1) in available_methods: params = dict([(g[0][2:], g[1].get(0)) for g in args.grouped.items()[1:] if g[0].startswith('--')]) fn_args = [g.split(',') for g in args.grouped.get('_')[2:]] fn_args = list(itertools.chain.from_iterable(fn_args)) resp = getattr(service, args.get(1))(*fn_args, **params) if isinstance(resp, EntityList) or isinstance(resp, EntityDict): resp = resp.data sys.stdout.write(json.dumps(resp, indent=2) + '\n') else: help(methods=available_methods) # missing or invalid method param else: help(services=services) # missing or invalid service parameter
def cmd_graft(args): branch = args.get(0) into_branch = args.get(1) if not branch: display_available_branches() sys.exit() branch_names = get_branch_names() remote_branch_names = get_branch_names(local=False) if branch not in branch_names: print "{0} doesn't exist. Use a branch that does.".format( colored.yellow(branch)) sys.exit(1) if branch in remote_branch_names: print "{0} is published. To graft it, unpublish it first.".format( colored.yellow(branch)) sys.exit(1) if into_branch not in branch_names: print "{0} doesn't exist. Use a branch that does.".format( colored.yellow(into_branch)) sys.exit(1) # Go to new branch. switch_to(into_branch) status_log(graft_branch, 'Grafting {0} into {1}.'.format( colored.yellow(branch), colored.yellow(into_branch)), branch)
def cmd_sprout(args): """Legit Sprout command.""" off_branch = args.get(0) new_branch = args.get(1) if new_branch is None: new_branch = off_branch off_branch = repo.head.ref.name if not off_branch: display_available_branches() sys.exit() branch_names = get_branch_names() if off_branch not in branch_names: print "{0} doesn't exist. Use a branch that does.".format( colored.yellow(off_branch)) sys.exit(1) if new_branch in branch_names: print "{0} already exists. Use a unique name.".format( colored.yellow(new_branch)) sys.exit(1) if repo.is_dirty(): status_log(stash_it, 'Saving local changes.') status_log(sprout_branch, 'Branching {0} to {1}.'.format( colored.yellow(off_branch), colored.yellow(new_branch)), off_branch, new_branch)
def cmd_resync(args): """Stashes unstaged changes, Fetches upstream data from master branch, Auto-Merge/Rebase from master branch Performs smart pull+merge, Pushes local commits up, and Unstashes changes. Defaults to current branch. """ if args.get(0): upstream = fuzzy_match_branch(args.get(0)) if upstream: is_external = True original_branch = repo.head.ref.name else: print("{0} doesn't exist. Use a branch that does.".format( colored.yellow(args.get(0)))) sys.exit(1) else: upstream = "master" original_branch = repo.head.ref.name if repo.is_dirty(): status_log(stash_it, 'Saving local changes.', sync=True) switch_to(upstream) status_log(smart_pull, 'Pulling commits from the server.') switch_to(original_branch) status_log(smart_merge, 'Grafting commits from {0}.'.format( colored.yellow(upstream)), upstream, allow_rebase=False) if unstash_index(sync=True): status_log(unstash_it, 'Restoring local changes.', sync=True) status_log(smart_pull, 'Pulling commits from the server.') status_log(push, 'Pushing commits to the server.', original_branch)
def main(): """Primary Legit command dispatch.""" command = Command.lookup(args.get(0)) if command: arg = args.get(0) args.remove(arg) command.__call__(args) sys.exit() elif args.contains(('-h', '--help')): display_help() sys.exit(1) elif args.contains(('-v', '--version')): display_version() sys.exit(1) else: if settings.git_transparency: # Send everything to git git_args = list(sys.argv) if settings.git_transparency is True: settings.git_transparency = os.environ.get("GIT_PYTHON_GIT_EXECUTABLE", 'git') git_args[0] = settings.git_transparency sys.exit(call(' '.join(git_args), shell=True)) else: show_error(colored.red('Unknown command {0}'.format(args.get(0)))) display_info() sys.exit(1)
def capitalone(user=None, quit_when_finished=True, browser=None): if not user: # Get the username from the command line arguments. user = args.get(0) # Must supply username. if user is None: puts(colored.red('You must supply a username like "python capitalone.py nick"')) sys.exit() # Get the user's password from the password backend. key = keyring.get_password('capitalone.com', user) # If the key doesn't exist in the password backend. if key is None: puts(colored.red("You must store the password for {} in your keyring's backend.".format(user))) puts('See: http://pypi.python.org/pypi/keyring/#configure-your-keyring-lib') sys.exit() # Log what we're currently working on. puts(colored.blue('\nCapital One ({})'.format(user))) if not browser: # Init the WebDriver. b = webdriver.Firefox() else: b = browser b.get('https://www.capitalone.com/') # Only credit card accounts are supported at this time. account_type = b.find_element_by_css_selector('option[value="credit cards"]') account_type.click() # Find the username field on the page. username = b.find_element_by_css_selector('input#eos-userid') username.send_keys(user) # Find the password field on the page. password = b.find_element_by_css_selector('input#eos-password') password.send_keys(key) password.submit() # Wait for an account list. try: WebDriverWait(b, timeout=10).until(_element_available(b, 'table.dataTable')) except TimeoutException: puts(colored.red("Couldn't find any accounts for that username.")) b.quit() sys.exit() amount = b.find_element_by_css_selector('table.dataTable tr.itemSummary td:nth-child(4) p') print 'Capital One ({}): {}'.format(user, amount.text) if quit_when_finished: b.quit() return b
def tarbell_install_template(args): """Install a project template.""" with ensure_settings(args) as settings: template_url = args.get(0) matches = [template for template in settings.config["project_templates"] if template["url"] == template_url] if matches: puts("\n{0} already exists. Nothing more to do.\n".format( colored.yellow(template_url) )) sys.exit() puts("\nInstalling {0}".format(colored.cyan(template_url))) tempdir = tempfile.mkdtemp() puts("\n- Cloning repo to {0}".format(colored.green(tempdir))) Repo.clone_from(template_url, tempdir) base_path = os.path.join(tempdir, "_base/") filename, pathname, description = imp.find_module('base', [base_path]) base = imp.load_module('base', filename, pathname, description) puts("\n- Found _base/base.py") try: name = base.NAME puts("\n- Name specified in base.py: {0}".format(colored.yellow(name))) except AttributeError: name = template_url.split("/")[-1] puts("\n- No name specified in base.py, using '{0}'".format(colored.yellow(name))) settings.config["project_templates"].append({"name": name, "url": template_url}) settings.save() _delete_dir(tempdir) puts("\n+ Added new project template: {0}".format(colored.yellow(name)))
def _get_project_name(args): """Get project name""" name = args.get(0) puts("") while not name: name = raw_input("What is the project's short directory name? (e.g. my_project) ") return name
def wellsfargo(user=None, quit_when_finished=True, browser=None): if not user: # Get the username from the command line arguments. user = args.get(0) # Must supply username. if user is None: puts(colored.red('You must supply a username like "python wellsfargo.py nick"')) sys.exit() # Get the user's password from the password backend. key = keyring.get_password('wellsfargo.com', user) # If the key doesn't exist in the password backend. if key is None: puts(colored.red("You must store the password for {} in your keyring's backend.".format(user))) puts('See: http://pypi.python.org/pypi/keyring/#configure-your-keyring-lib') sys.exit() # Log what we're currently working on. puts(colored.blue('\nWells Fargo ({})'.format(user))) if not browser: # Init the WebDriver. b = webdriver.Firefox() else: b = browser b.get('https://www.wellsfargo.com/') # Find the username field on the page. username = b.find_element_by_css_selector('input#userid') username.send_keys(user) # Find the password field on the page. password = b.find_element_by_css_selector('input#password') password.send_keys(key) password.submit() # Wait for an account list. try: WebDriverWait(b, timeout=10).until(_element_available(b, 'a.account')) except TimeoutException: puts(colored.red("Couldn't find any accounts for that username.")) b.quit() sys.exit() # Click the first account. b.find_element_by_css_selector('a.account').click() amount = b.find_element_by_css_selector('table#balanceDetails td.topRow a') print 'Wells Fargo ({}): {}'.format(user, amount.text) if quit_when_finished: b.quit() return b
def att(user=None, quit_when_finished=True, browser=None): if not user: # Get the username from the command line arguments. user = args.get(0) # Must supply username. if user is None: puts(colored.red('You must supply a username like "python att.py nick"')) sys.exit() # Get the user's password from the password backend. key = keyring.get_password('att.com', user) # If the key doesn't exist in the password backend. if key is None: puts(colored.red("You must store the password for {} in your keyring's backend.".format(user))) puts('See: http://pypi.python.org/pypi/keyring/#configure-your-keyring-lib') sys.exit() # Log what we're currently working on. puts(colored.blue('\nAT&T ({})'.format(user))) if not browser: # Init the WebDriver. b = webdriver.Firefox() else: b = browser b.get('https://www.att.com/') # Find the username field on the page. username = b.find_element_by_css_selector('input#userid') username.send_keys(user) # Find the password field on the page. password = b.find_element_by_css_selector('input#password') password.send_keys(key) password.submit() # Wait for an account page. try: WebDriverWait(b, timeout=15).until(_element_available(b, 'div.mybilldiv span.colorOrange.font30imp')) except TimeoutException: puts(colored.red("Looks like the system is down.")) if quit_when_finished: b.quit() else: return b amount = b.find_element_by_css_selector('div.mybilldiv span.colorOrange.font30imp') print 'AT&T ({}): {}'.format(user, amount.text) if quit_when_finished: b.quit() return b
def main(self): self._check_dependencies() if not args.get(0) or not len(args.files) or "--help" in args.flags: self._show_help() if "--watch" not in args.flags: self._iterate_over_files()
def main(): services = sunlight.available_services() service = services.get(args.get(0), None) if service is not None: available_methods = [m for m in dir(service) if not m.startswith("_") and m != "get"] if args.get(1) in available_methods: params = {g[0][2:]: g[1].get(0) for g in args.grouped.items()[1:] if g[0].startswith("--")} resp = getattr(service, args.get(1))(**params) sys.stdout.write(json.dumps(resp, indent=2) + "\n") else: help(methods=available_methods) # missing or invalid method param else: help(services=services) # missing or invalid service parameter
def _get_project_name(args): """Get project name""" name = args.get(0) puts("") while not name: name = raw_input( "What is the project's short directory name? (e.g. my_project) ") return name
def cmd_sync(args): """Stashes unstaged changes, Fetches remote data, Performs smart pull+merge, Pushes local commits up, and Unstashes changes. Defaults to current branch. """ if args.get(0): # Optional branch specifier. branch = fuzzy_match_branch(args.get(0)) if branch: is_external = True original_branch = repo.head.ref.name else: print("{0} doesn't exist. Use a branch that does.".format( colored.yellow(args.get(0)))) sys.exit(1) else: # Sync current branch. branch = repo.head.ref.name is_external = False if branch in get_branch_names(local=False): if is_external: switch_to(branch) if repo.is_dirty(): status_log(stash_it, 'Saving local changes.', sync=True) status_log(smart_pull, 'Pulling commits from the server.') status_log(push, 'Pushing commits to the server.', branch) if unstash_index(sync=True): status_log(unstash_it, 'Restoring local changes.', sync=True) if is_external: switch_to(original_branch) else: print('{0} has not been published yet.'.format( colored.yellow(branch))) sys.exit(1)
def main(self): if len(args) == 0 or args[0] in ('-h', '--help'): return self.usage() command = args.get(0) try: command = self.commands[command] except KeyError: puts(colored.red('Invalid command `%s`\n' % command)) return self.usage() command.parse(args.all[1:])
def cmd_sync(args): """Stashes unstaged changes, Fetches remote data, Performs smart pull+merge, Pushes local commits up, and Unstashes changes. Defaults to current branch. """ if args.get(0): # Optional branch specifier. if args.get(0) in get_branch_names(): branch = args.get(0) is_external = True original_branch = repo.head.ref.name else: print "{0} doesn't exist. Use a branch that does.".format( colored.yellow(args.get(0))) sys.exit(1) else: # Sync current branch. branch = repo.head.ref.name is_external = False if branch in get_branch_names(local=False): if is_external: switch_to(branch) if repo.is_dirty(): status_log(stash_it, 'Saving local changes.', sync=True) status_log(smart_pull, 'Pulling commits from the server.') status_log(push, 'Pushing commits to the server.', branch) if unstash_index(sync=True): status_log(unstash_it, 'Restoring local changes.', sync=True) if is_external: switch_to(original_branch) else: print '{0} has not been published yet.'.format( colored.yellow(branch)) sys.exit(1)
def cmd_publish(args): """Pushes an unpublished branch to a remote repository.""" branch = fuzzy_match_branch(args.get(0)) if not branch: branch = repo.head.ref.name display_available_branches() print("Branch {0} not found, using current branch {1}".format(colored.red(args.get(0)),colored.yellow(branch))) branch_names = get_branch_names(local=False) if branch in branch_names: print("{0} is already published. Use a branch that isn't.".format( colored.yellow(branch))) sys.exit(1) status_log(publish_branch, 'Publishing {0}.'.format( colored.yellow(branch)), branch)
def main(): # Arumengs were passed. if args.get(0) is not None: display_version() sys.exit(1) print 'SSH Server started. u: {0} p: {1}'.format( colored.yellow('kreitz'), colored.yellow('iwefhoihef') )
def cmd_harvest(args): """Syncs a branch with given branch. Defaults to current.""" from_branch = args.get(0) to_branch = args.get(1) if not from_branch: print 'Please specify a branch to harvest commits from:' display_available_branches() sys.exit() if to_branch: original_branch = repo.head.ref.name is_external = True else: is_external = False branch_names = get_branch_names(local=True, remote=False) if from_branch not in branch_names: print "{0} isn't an available branch. Use a branch that is.".format( colored.yellow(from_branch)) sys.exit(1) if is_external: switch_to(to_branch) if repo.is_dirty(): status_log(stash_it, 'Saving local changes.') status_log(smart_merge, 'Grafting commits from {0}.'.format( colored.yellow(from_branch)), from_branch, allow_rebase=False) if is_external: switch_to(original_branch) if unstash_index(): status_log(unstash_it, 'Restoring local changes.')
def cmd_graft(args): """Merges an unpublished branch into the given branch, then deletes it.""" branch = fuzzy_match_branch(args.get(0)) into_branch = args.get(1) if not branch: print('Please specify a branch to graft:') display_available_branches() sys.exit(64) # EX_USAGE if not into_branch: into_branch = get_current_branch_name() else: into_branch = fuzzy_match_branch(into_branch) branch_names = get_branch_names(local=True, remote_branches=False) remote_branch_names = get_branch_names(local=False, remote_branches=True) if branch not in branch_names: print("{0} doesn't exist. Use a branch that does.".format( colored.yellow(branch))) sys.exit(1) if branch in remote_branch_names: print("{0} is published. To graft it, unpublish it first.".format( colored.yellow(branch))) sys.exit(1) if into_branch not in branch_names: print("{0} doesn't exist. Use a branch that does.".format( colored.yellow(into_branch))) sys.exit(1) # Go to new branch. switch_to(into_branch) status_log( graft_branch, 'Grafting {0} into {1}.'.format(colored.yellow(branch), colored.yellow(into_branch)), branch)
def cmd_undo(args): """Makes last commit not exist. --hard for """ is_hard = args.get(0) == '--hard' if is_hard: repo.git.reset('--hard HEAD^') else: repo.git.reset('HEAD^') print('Last commit removed from history.')
def cmd_sprout(args): """Creates a new branch of given name from given branch. Defaults to current branch. """ off_branch = args.get(0) new_branch = args.get(1) if (off_branch is None) and (new_branch is None): # new_branch is required, so should be passed at least 1 arg show_error('Please pass new branch name to create.') help('sprout', to_stderr=True) sys.exit(1) elif new_branch is None: # off_branch is optional, so use specified one as new_branch new_branch = args.get(0) off_branch = get_current_branch_name() else: off_branch = fuzzy_match_branch(off_branch) branch_names = get_branch_names() if off_branch not in branch_names: print("{0} doesn't exist. Use a branch that does.".format( colored.yellow(off_branch))) sys.exit(1) if new_branch in branch_names: print("{0} already exists. Use a unique name.".format( colored.yellow(new_branch))) sys.exit(1) if repo.is_dirty(): status_log(stash_it, 'Saving local changes.') status_log( sprout_branch, 'Branching {0} to {1}.'.format(colored.yellow(off_branch), colored.yellow(new_branch)), off_branch, new_branch)
def cmd_graft(args): """Merges an unpublished branch into the given branch, then deletes it.""" branch = args.get(0) into_branch = args.get(1) if not branch: print 'Please specify a branch to graft:' display_available_branches() sys.exit() if not into_branch: into_branch = repo.head.ref.name branch_names = get_branch_names(local=True, remote=False) remote_branch_names = get_branch_names(local=False, remote=True) if branch not in branch_names: print "{0} doesn't exist. Use a branch that does.".format( colored.yellow(branch)) sys.exit(1) if branch in remote_branch_names: print "{0} is published. To graft it, unpublish it first.".format( colored.yellow(branch)) sys.exit(1) if into_branch not in branch_names: print "{0} doesn't exist. Use a branch that does.".format( colored.yellow(into_branch)) sys.exit(1) # Go to new branch. switch_to(into_branch) status_log( graft_branch, 'Grafting {0} into {1}.'.format(colored.yellow(branch), colored.yellow(into_branch)), branch)
def cmd_sprout(args): """Creates a new branch of given name from given branch. Defaults to current branch. """ off_branch = args.get(0) new_branch = args.get(1) if (off_branch is None) and (new_branch is None): # new_branch is required, so should be passed at least 1 arg show_error('Please pass new branch name to create.') help('sprout', to_stderr=True) sys.exit(1) elif new_branch is None: # off_branch is optional, so use specified one as new_branch new_branch = args.get(0) off_branch = get_current_branch_name() else: off_branch = fuzzy_match_branch(off_branch) branch_names = get_branch_names() if off_branch not in branch_names: print("{0} doesn't exist. Use a branch that does.".format( colored.yellow(off_branch))) sys.exit(1) if new_branch in branch_names: print("{0} already exists. Use a unique name.".format( colored.yellow(new_branch))) sys.exit(1) if repo.is_dirty(): status_log(stash_it, 'Saving local changes.') status_log(sprout_branch, 'Branching {0} to {1}.'.format( colored.yellow(off_branch), colored.yellow(new_branch)), off_branch, new_branch)
def main(): if len(args) != 1: puts('Usage' + cyan(': ') + 'coderwall ' + cyan('<') + 'username' + cyan('>')) sys.exit(1) try: coderwall = User(args.get(0)) except ConnectionError: puts('Error' + cyan(': ') + 'There seems to be a problem with the internet') sys.exit(1) except User_UserNotFoundError: puts('Error' + cyan(': ') + '%s does not seem to be a CoderWall user' % (args.get(0))) sys.exit(1) user = coderwall.user puts(user.get('name') + cyan(' (') + user.get('username') + cyan('), ') + user.get('location') + cyan(',') + ' Endorsed ' + cyan(str(user.get('endorsements'))) + ' times') puts('Badges' + cyan(':')) with indent(3): for badge in user.get('badges'): puts('%s%s%s %s' % (cyan('('), badge['name'], cyan(')'), badge['description']))
def cmd_graft(args): """Merges an unpublished branch into the given branch, then deletes it.""" branch = fuzzy_match_branch(args.get(0)) into_branch = args.get(1) if not branch: print('Please specify a branch to graft:') display_available_branches() sys.exit() if not into_branch: into_branch = repo.head.ref.name else: into_branch = fuzzy_match_branch(into_branch) branch_names = get_branch_names(local=True, remote_branches=False) remote_branch_names = get_branch_names(local=False, remote_branches=True) if branch not in branch_names: print("{0} doesn't exist. Use a branch that does.".format( colored.yellow(branch))) sys.exit(1) if branch in remote_branch_names: print("{0} is published. To graft it, unpublish it first.".format( colored.yellow(branch))) sys.exit(1) if into_branch not in branch_names: print("{0} doesn't exist. Use a branch that does.".format( colored.yellow(into_branch))) sys.exit(1) # Go to new branch. switch_to(into_branch) status_log(graft_branch, 'Grafting {0} into {1}.'.format( colored.yellow(branch), colored.yellow(into_branch)), branch)
def cmd_sync(args): """Legit Sync command.""" if args.get(0): # Optional branch specifier. if args.get(0) in get_branch_names(): branch = args.get(0) is_external = True original_branch = repo.head.ref.name else: print "{0} doesn't exist. Use a branch that does.".format( colored.yellow(args.get(0))) sys.exit(1) else: # Sync current branch. branch = repo.head.ref.name is_external = False if branch in get_branch_names(local=False): if is_external: switch_to(branch) if repo.is_dirty(): status_log(stash_it, 'Saving local changes.', sync=True) status_log(smart_pull, 'Pulling commits from the server.') status_log(push, 'Pushing commits to the server.', branch) if unstash_index(sync=True): status_log(unstash_it, 'Restoring local changes.', sync=True) if is_external: switch_to(original_branch) else: print '{0} has not been published yet.'.format(colored.yellow(branch)) sys.exit(1)
def cmd_sprout(args): """Creates a new branch of given name from given branch. Defaults to current branch. """ off_branch = args.get(0) new_branch = args.get(1) if new_branch is None: new_branch = off_branch off_branch = repo.head.ref.name else: off_branch = fuzzy_match_branch(off_branch) if not off_branch: print('Please specify branch to sprout:') display_available_branches() sys.exit() branch_names = get_branch_names() if off_branch not in branch_names: print("{0} doesn't exist. Use a branch that does.".format( colored.yellow(off_branch))) sys.exit(1) if new_branch in branch_names: print("{0} already exists. Use a unique name.".format( colored.yellow(new_branch))) sys.exit(1) if repo.is_dirty(): status_log(stash_it, 'Saving local changes.') status_log(sprout_branch, 'Branching {0} to {1}.'.format( colored.yellow(off_branch), colored.yellow(new_branch)), off_branch, new_branch)
def cmd_switch(args): """Legit Switch command.""" to_branch = args.get(0) to_branch = fuzzy_match_branch(to_branch) if repo.is_dirty(): status_log(stash_it, 'Saving local changes.') status_log(checkout_branch, 'Switching to {0}.'.format( colored.yellow(to_branch)), to_branch) if unstash_index(): status_log(unstash_it, 'Restoring local changes.')
def main(): """Primary Tarbell command dispatch.""" command = Command.lookup(args.get(0)) if len(args) == 0 or args.contains(('-h', '--help', 'help')): display_info(args) sys.exit(1) elif args.contains(('-v', '--version')): display_version() sys.exit(1) elif command: arg = args.get(0) args.remove(arg) command.__call__(args) sys.exit() else: show_error( colored.red('Error! Unknown command `{0}`.\n'.format(args.get(0)))) display_info(args) sys.exit(1)
def main(): """Primary Legit command dispatch.""" if (args.get(0) in cmd_map) or (args.get(0) in short_map): arg = args.get(0) args.remove(arg) if arg in short_map: arg = short_map.get(arg) cmd_map.get(arg).__call__(args) sys.exit() elif args.contains(('-h', '--help')): display_help() sys.exit(1) elif args.contains(('-v', '--version')): display_version() sys.exit(1) else: display_info() sys.exit(1)
def main(): """Primary Tarbell command dispatch.""" command = Command.lookup(args.get(0)) if len(args) == 0 or args.contains(('-h', '--help', 'help')): display_info(args) sys.exit(1) elif args.contains(('-v', '--version')): display_version() sys.exit(1) elif command: arg = args.get(0) args.remove(arg) command.__call__(args) sys.exit() else: show_error(colored.red('Error! Unknown command `{0}`.\n' .format(args.get(0)))) display_info(args) sys.exit(1)
def cmd_unpublish(args): branch = args.get(0) if not branch: display_available_branches() sys.exit() branch_names = get_branch_names(local=False) if branch not in branch_names: print "{0} isn't published. Use a branch that is.".format( colored.yellow(branch)) sys.exit(1) status_log(unpublish_branch, 'Unpublishing {0}.'.format( colored.yellow(branch)), branch)
def cmd_unpublish(args): branch = args.get(0) if not branch: display_available_branches() sys.exit() branch_names = get_branch_names(local=False) if branch not in branch_names: print "{0} isn't published. Use a branch that is.".format( colored.yellow(branch)) sys.exit(1) status_log(unpublish_branch, 'Unpublishing {0}.'.format(colored.yellow(branch)), branch)
def tarbell_switch(args): """Switch to a project""" with ensure_settings(args) as settings: projects_path = settings.config.get("projects_path") if not projects_path: show_error("{0} does not exist".format(projects_path)) sys.exit() project = args.get(0) args.remove(project) project_path = os.path.join(projects_path, project) if os.path.isdir(project_path): os.chdir(project_path) puts("\nSwitching to {0}".format(colored.red(project))) puts("Edit this project's templates at {0}".format(colored.yellow(project_path))) puts("Running preview server...") tarbell_serve(args) else: show_error("{0} isn't a tarbell project".format(project_path))
def cmd_publish(args): """Pushes an unpublished branch to a remote repository.""" branch = args.get(0) if not branch: display_available_branches() sys.exit() branch_names = get_branch_names(local=False) if branch in branch_names: print "{0} is already published. Use a branch that isn't.".format( colored.yellow(branch)) sys.exit(1) status_log(publish_branch, 'Publishing {0}.'.format( colored.yellow(branch)), branch)
def cmd_publish(args): """Pushes an unpublished branch to a remote repository.""" branch = args.get(0) if not branch: display_available_branches() sys.exit() branch_names = get_branch_names(local=False) if branch in branch_names: print "{0} is already published. Use a branch that isn't.".format( colored.yellow(branch)) sys.exit(1) status_log(publish_branch, 'Publishing {0}.'.format(colored.yellow(branch)), branch)
def tarbell_switch(args): """Switch to a project""" with ensure_settings(args) as settings: projects_path = settings.config.get("projects_path") if not projects_path: show_error("{0} does not exist".format(projects_path)) sys.exit() project = args.get(0) args.remove(project) project_path = os.path.join(projects_path, project) if os.path.isdir(project_path): os.chdir(project_path) puts("\nSwitching to {0}".format(colored.red(project))) puts("Edit this project's templates at {0}".format( colored.yellow(project_path))) puts("Running preview server...") tarbell_serve(args) else: show_error("{0} isn't a tarbell project".format(project_path))
def tarbell_install(args): """Install a project.""" with ensure_settings(args) as settings: project_url = args.get(0) puts("\n- Getting project information for {0}".format(project_url)) tempdir = tempfile.mkdtemp() Repo.clone_from(project_url, tempdir) filename, pathname, description = imp.find_module('tarbell', [tempdir]) config = imp.load_module('tarbell', filename, pathname, description) puts("\n- Found config.py") path = _get_path(config.NAME, settings) repo = Repo.clone_from(project_url, path) try: puts("\n- Adding remote 'updated_project_template' using {0}".format(config.TEMPLATE_REPO_URL)) repo.create_remote("update_project_template", config.TEMPLATE_REPO_URL) except AttributeError: pass _delete_dir(tempdir) puts("\n- Done installing project in {0}".format(path))
def cmd_unpublish(args): """Removes a published branch from the remote repository.""" branch = args.get(0) if not branch: print 'Please specify a branch to unpublish:' display_available_branches() sys.exit() branch_names = get_branch_names(local=False) if branch not in branch_names: print "{0} isn't published. Use a branch that is.".format( colored.yellow(branch)) sys.exit(1) status_log(unpublish_branch, 'Unpublishing {0}.'.format(colored.yellow(branch)), branch)
def cmd_switch(args): """Legit Switch command.""" from_branch = repo.head.ref.name to_branch = args.get(0) to_branch = fuzzy_match_branch(to_branch) if not to_branch: print('Please specify a branch to switch to:') display_available_branches() sys.exit() if repo.is_dirty(): status_log(stash_it, 'Saving local changes.') status_log(checkout_branch, 'Switching to {0}.'.format( colored.yellow(to_branch)), to_branch) if unstash_index(branch=from_branch): status_log(unstash_it, 'Restoring local changes.', branch=from_branch)
def tarbell_install_template(args): """Install a project template.""" with ensure_settings(args) as settings: template_url = args.get(0) matches = [ template for template in settings.config["project_templates"] if template["url"] == template_url ] if matches: puts("\n{0} already exists. Nothing more to do.\n".format( colored.yellow(template_url))) sys.exit() puts("\nInstalling {0}".format(colored.cyan(template_url))) tempdir = tempfile.mkdtemp() puts("\n- Cloning repo to {0}".format(colored.green(tempdir))) Repo.clone_from(template_url, tempdir) base_path = os.path.join(tempdir, "_base/") filename, pathname, description = imp.find_module('base', [base_path]) base = imp.load_module('base', filename, pathname, description) puts("\n- Found _base/base.py") try: name = base.NAME puts("\n- Name specified in base.py: {0}".format( colored.yellow(name))) except AttributeError: name = template_url.split("/")[-1] puts("\n- No name specified in base.py, using '{0}'".format( colored.yellow(name))) settings.config["project_templates"].append({ "name": name, "url": template_url }) settings.save() _delete_dir(tempdir) puts("\n+ Added new project template: {0}".format( colored.yellow(name)))
def tarbell_install(args): """Install a project.""" with ensure_settings(args) as settings: project_url = args.get(0) puts("\n- Getting project information for {0}".format(project_url)) tempdir = tempfile.mkdtemp() Repo.clone_from(project_url, tempdir) filename, pathname, description = imp.find_module('tarbell', [tempdir]) config = imp.load_module('tarbell', filename, pathname, description) puts("\n- Found config.py") path = _get_path(config.NAME, settings) repo = Repo.clone_from(project_url, path) try: puts("\n- Adding remote 'updated_project_template' using {0}". format(config.TEMPLATE_REPO_URL)) repo.create_remote("update_project_template", config.TEMPLATE_REPO_URL) except AttributeError: pass _delete_dir(tempdir) puts("\n- Done installing project in {0}".format(path))
def cmd_switch(args): """Legit Switch command.""" to_branch = args.get(0) if not to_branch: display_available_branches() sys.exit() if to_branch not in get_branch_names(): print 'Branch not found.' sys.exit(1) else: if repo.is_dirty(): status_log(stash_it, 'Saving local changes.') status_log(checkout_branch, 'Switching to {0}.'.format(colored.yellow(to_branch)), to_branch) if unstash_index(): status_log(unstash_it, 'Restoring local changes.')
def cmd_help(args): """Display help for individual commands.""" command = args.get(0) help(command)