diff --git a/add_collaborators.py b/add_collaborators.py index 633f969..0cf9dce 100755 --- a/add_collaborators.py +++ b/add_collaborators.py @@ -43,18 +43,15 @@ def add_collaborators_deco(parser): def add_collaborators(opt): g = Github(opt.githubToken()) - repo_full_name = '{}/{}'.format(opt.owner, opt.repo) + repo_full_name = f'{opt.owner}/{opt.repo}' repo = g.get_repo(repo_full_name) - if not opt.promptYes(('Are you sure you would like to add users from {} ' - 'as collaborators to {} with {} permissions?') - .format(opt.users.name, repo_full_name, - opt.permission), True): + if not opt.promptYes((f'Are you sure you would like to add users from {opt.users.name} ' + f'as collaborators to {repo_full_name} with {opt.permission} permissions?'), True): opt.warn('Aborting') return - opt.info('Proceeding to add {} as collaborators to {} with {} permissions' - .format(opt.users.name, repo_full_name, opt.permission)) + opt.info(f'Proceeding to add {opt.users.name} as collaborators to {repo_full_name} with {opt.permission} permissions' do_add = opt.begin is None begin, added, total = 0, 0, 0 @@ -71,15 +68,14 @@ def add_collaborators(opt): do_add_collaborator(repo, user, opt.permission, opt) added = added + 1 else: - opt.info('Skipped {}'.format(user)) + opt.info(f'Skipped {user}') except Exception as e: opt.error(e) - opt.error('{} failed on {} ({})'.format(CMD_NAME, user, total)) + opt.error(f'{CMD_NAME} failed on {user} ({total})') return - opt.info('Added {} users of {} total users, starting from index {}' - .format(added, total, begin)) + opt.info(f'Added {added} users of {total} total users, starting from index {begin}') def main(args=None, config_path=None): diff --git a/add_team_members.py b/add_team_members.py index 4c63523..3593f53 100755 --- a/add_team_members.py +++ b/add_team_members.py @@ -48,7 +48,7 @@ def add_team_members_deco(parser): def do_create_team(org, team_name, opt): - opt.info('Creating secret team {} in org {}'.format(team_name, org.name)) + opt.info(f'Creating secret team {team_name} in org {org.name}') if opt.noop: opt.log('--noop option specified; not creating team') @@ -58,14 +58,13 @@ def do_create_team(org, team_name, opt): team = org.create_team(team_name, privacy='secret') - opt.info('Team {} successfully created'.format(team.name)) + opt.info(f'Team {team.name} successfully created') return team def do_add_team_member(team, user, role, opt): - opt.info('Adding {} as team member to {} with {} permissions' - .format(user.login, team.name, role)) + opt.info(f'Adding {user.login} as team member to {team.name} with {role} permissions') if opt.noop: opt.log('--noop option specified; not adding team member') @@ -73,7 +72,7 @@ def do_add_team_member(team, user, role, opt): team.add_membership(user, role=role) - opt.info('User {} successfully added'.format(user.login)) + opt.info(f'User {user.login} successfully added') def add_team_members(opt): @@ -96,12 +95,11 @@ def add_team_members(opt): break if team is None: - opt.error('Team {} not found in org {}'.format(opt.team, opt.org)) + opt.error(f'Team {opt.team} not found in org {opt.org}') opt.error('You may try passing the --create flag to create it') return - opt.info('Adding users from {} as team members to {}/{} with {} permissions' - .format(opt.users.name, org.name, team.name, opt.role)) + opt.info(f'Adding users from {opt.users.name} as team members to {org.name}/{team.name} with {opt.role} permissions') if not opt.promptYes('Are you sure you would like to proceed?', True): opt.warn('Aborting') diff --git a/boatswain_env.py b/boatswain_env.py index e6da2ad..a808259 100755 --- a/boatswain_env.py +++ b/boatswain_env.py @@ -71,7 +71,7 @@ def log(self, fmt, *args, tag=None): if len(args) > 0: fmt = fmt.format(*args) if tag is not None: - fmt = '=={}==\t{}'.format(tag, fmt) + fmt = f'=={tag}==\t{fmt}' # TODO: logging to file print(fmt) @@ -183,9 +183,9 @@ def ParseOption( ) except configparser.NoOptionError: print('[WARN]: You appear to be missing a Canvas token in your ' - + 'Boatswain configuration ({}). Please add this information ' + + f'Boatswain configuration ({config_path}). Please add this information ' + 'to your config file under section [canvas] with key "token".' - + '\n'.format(config_path)) + + '\n') parser.add_argument('canvas_token', type=str, help='Canvas LMS auth token', @@ -202,9 +202,9 @@ def ParseOption( ) except configparser.NoOptionError: print('[WARN]: You appear to be missing the Canvas URL in your ' - + 'Boatswain configuration ({}). Please add this information ' + + f'Boatswain configuration ({config_path}). Please add this information ' + 'to your config file under section [canvas] with key "url".' - + '\n'.format(config_path)) + + '\n') parser.add_argument('canvas_url', type=str, help='Canvas LMS URL', @@ -222,9 +222,9 @@ def ParseOption( ) except configparser.NoOptionError: print('[WARN]: You appear to be missing a GitHub token in your ' - + 'Boatswain configuration ({}). Please add this information ' + + f'Boatswain configuration ({config_path}). Please add this information ' + 'to your config file under section [github] with key "token".' - + '\n'.format(config_path)) + + '\n') parser.add_argument('github_token', type=str, help='GitHub auth token', @@ -299,7 +299,7 @@ def createConfigInteractive(): config = newPopulatedConfigInteractive() config.write(open(path, 'w+')) - itv.output('Boatswain config file created at {}'.format(path)) + itv.output(f'Boatswain config file created at {path}') except EOFError: itv.output() diff --git a/canvas-wrangler.py b/canvas-wrangler.py index c36b6f3..565942c 100755 --- a/canvas-wrangler.py +++ b/canvas-wrangler.py @@ -55,7 +55,7 @@ def retrieve_index(header_row, target): for i, cell in enumerate(header_row): if cell == target: return i - raise LookupError('{} index not found'.format(target)) + raise LookupError(f'{target} index not found') def retrieve_indices(header, opt): @@ -103,18 +103,18 @@ def build_grade_data(grades, student_i, grade_i, comment_i, opt): else: comment = None - opt.info('{} ({}): {}'.format(user_id, grade, comment)) - grade_data['sis_user_id:{}'.format(user_id)] = grade_entry + opt.info(f'{user_id} ({grade}): {comment}') + grade_data[f'sis_user_id:{user_id}'] = grade_entry return grade_data def log_dump_wrangler(grade_data, course, assignment, opt): - opt.info('Course: {}'.format(course)) - opt.info('Assignment: {}'.format(assignment)) + opt.info(f'Course: {course}') + opt.info(f'Assignment: {assignment}') opt.info('Grade Data: {') for k in grade_data: - opt.info('{} : {}'.format(k, grade_data[k])) + opt.info(f'{k} : {grade_data[k]}') opt.info('}') opt.info('') diff --git a/interactive.py b/interactive.py index 9818b58..6792faa 100644 --- a/interactive.py +++ b/interactive.py @@ -7,13 +7,13 @@ def output(*args): def promptInput(prompt, fmt='', default=''): if fmt != '': - promptf = '{} [{}]'.format(prompt, fmt) + promptf = f'{prompt} [{fmt}]' elif default != '': - promptf = '{} [{}]'.format(prompt, default) + promptf = f'{prompt} [{default}]' else: promptf = prompt - promptf = '{}: '.format(promptf) + promptf = '{promptf}: ' while True: inp = input(promptf) @@ -31,7 +31,7 @@ def promptValidate(prompt, validator, fmt='', default=''): v = validator(inp) if v == '': return inp - output('Invalid input (case-insensitive): {}'.format(v)) + output(f'Invalid input (case-insensitive): {v}') def selectorValidator(options, default=''): @@ -70,7 +70,7 @@ def newFileValidator(): def validator(inp): try: if os.path.exists(inp): - return '{} already exists'.format(inp) + return f'{inp} already exists' else: open(inp, 'w').close() os.unlink(inp) diff --git a/mk_group_repos.py b/mk_group_repos.py index b0bbd68..e042f79 100755 --- a/mk_group_repos.py +++ b/mk_group_repos.py @@ -49,16 +49,12 @@ def mk_group_repos(opt): org = g.get_organization(opt.org) if not opt.promptYes(('Are you sure you would like to create group repos ' - 'for users in {} under org {} with name {}') - .format(opt.groups.name, opt.org, - fmt_hyphen(opt.prefix, '')), + f'for users in {opt.groups.name} under org {opt.org} with name {fmt_hyphen(opt.prefix, '')}'), True): opt.warn('Aborting') return - opt.info('Creating repos under {} for groups in {}, with name {}' - .format(opt.groups.name, opt.org, - fmt_hyphen(opt.prefix, ''))) + opt.info(f'Creating repos under {opt.groups.name} for groups in {opt.org}, with name {fmt_hyphen(opt.prefix, '')}') for g in csv.reader(opt.groups): group, members = g[0], [m.strip() for m in g[1:] if m != ''] @@ -69,19 +65,18 @@ def mk_group_repos(opt): action = 'creating' else: action = 'looking up' - opt.info('{} {}/{} and adding members {}' - .format(action, opt.org, repo_name, members)) + opt.info(f'{action} {opt.org}/{repo_name} and adding members {members}') if opt.create: repo = do_mk_repo(org, repo_name, opt) else: repo = org.get_repo(repo_name) - opt.info('Looked up repo {}/{}'.format(org.name, repo_name)) + opt.info(f'Looked up repo {org.name}/{repo_name}') if opt.permission == 'none': - opt.info('Not adding {} to {}'.format(members, repo_name)) + opt.info(f'Not adding {members} to {repo_name}') else: - opt.info('Adding {} to {}'.format(members, repo_name)) + opt.info(f'Adding {members} to {repo_name}') for member in members: do_add_collaborator(repo, member, opt.permission, opt) diff --git a/mk_repo.py b/mk_repo.py index 4be1c1b..e076bd7 100755 --- a/mk_repo.py +++ b/mk_repo.py @@ -31,14 +31,13 @@ def mk_repo_deco(parser): def fmt_hyphen(prefix, name): if prefix[-1] == '-': - return '{}{}'.format(prefix, name) + return f'{prefix}{name}' else: - return '{}-{}'.format(prefix, name) + return f'{prefix}-{name}' def do_mk_repo(org, repo_name, opt): - opt.info('Creating private repo {} under organization {}' - .format(repo_name, org)) + opt.info(f'Creating private repo {repo_name} under organization {org}') if opt.noop: opt.log('--noop option specified; not creating repo') @@ -49,7 +48,7 @@ def do_mk_repo(org, repo_name, opt): repo = org.create_repo(repo_name, private=True) # funky output so easily greppable - opt.log('@CREATED_REPO: {} {}'.format(repo_name, repo.git_url)) + opt.log(f'@CREATED_REPO: {repo_name} {repo.git_url}') return repo @@ -61,14 +60,12 @@ def mk_repo(opt): repo_name = fmt_hyphen(opt.prefix, opt.repo) if not opt.promptYes(('Are you sure you would like to create a private ' - 'repo under organization {} named {}?') - .format(opt.org, repo_name), + f'repo under organization {opt.org} named {repo_name}?'), True): opt.warn('Aborting') return - opt.info('Proceeding to create private repo {}/{}' - .format(opt.org, repo_name)) + opt.info(f'Proceeding to create private repo {opt.org}/{repo_name}') do_mk_repo(org, repo_name, opt) diff --git a/scrub-deck.py b/scrub-deck.py index 457119e..70c571c 100755 --- a/scrub-deck.py +++ b/scrub-deck.py @@ -32,10 +32,10 @@ def scrub_deco(parser): def do_scrub(repo, opt): if opt.noop: - opt.log('--noop option specified; not deleting {}'.format(repo.name)) + opt.log(f'--noop option specified; not deleting {repo.name}') return - opt.warn('Deleting {}...'.format(repo.name)) + opt.warn(f'Deleting {repo.name}...') repo.delete() @@ -43,7 +43,7 @@ def scrub_org(opt): g = Github(opt.githubToken()) org = g.get_organization(opt.org_name) - opt.warn('Scrubbing Github Org: {} ({})'.format(org.login, org.url)) + opt.warn(f'Scrubbing Github Org: {org.login} ({org.url})') if not opt.promptYes('Are you sure you want to scrub this org?', False): # deliberately disallow --yes to work @@ -58,13 +58,11 @@ def scrub_org(opt): repo_name = repo.full_name.split('/')[-1] if opt.invert: if opt.filter.fullmatch(repo_name): - opt.info('Skipping {}; matched with inverted filter: {}' - .format(repo_name, opt.filter)) + opt.info(f'Skipping {repo_name}; matched with inverted filter: {opt.filter}') continue else: if not opt.filter.fullmatch(repo_name): - opt.info('Skipping {}; did not match with filter: {}' - .format(repo_name, opt.filter)) + opt.info(f'Skipping {repo_name}; did not match with filter: {opt.filter}') continue do_scrub(repo, opt)