def dump_sql_groups(self): self.app.log.debug('Dumping SQL code for groups.') # schema keys key_group = self.app.config.get('core', 'users_schema_key_group') key_github = self.app.config.get('core', 'users_schema_key_github') # groups setup course_id = int(self.app.config.get('evaltool', 'course_id')) group_pattern = self.app.config.get('evaltool', 'group_pattern') user_repository = data.UserRepository(self.app.config) print colored("-- Groups", 'green') for group in user_repository.groups(): group_name = group_pattern % int(group) print colored( "INSERT INTO GROUPS(id, group_name, course_id) VALUES (%d, '%s', %d);" % (course_id * 1000 + int(group), group_name, course_id), 'green') print colored("-- Group Authorities", 'green') for group in user_repository.groups(): print colored( "INSERT INTO GROUP_AUTHORITIES(group_id, authority) values (%d, 'ROLE_USER');" % (course_id * 1000 + int(group)), 'green') print colored("-- Group Members", 'green') for group in user_repository.groups(): print colored("-- Group %02d" % int(group), 'green') for u in user_repository.users(lambda x: x[key_group] == group): print colored( "INSERT INTO GROUP_MEMBERS(group_id, username) values (%d, '%s');" % (course_id * 1000 + int(group), u[key_github]), 'green')
def create_repos(self): self.app.log.debug('Creating GitHub repositories.') # validate required config parameters if not self.app.config.get('github', 'auth_token') or not self.app.config.get( 'github', 'auth_id'): raise error.ConfigError( "Missing config parameter 'github.auth_id' and/or 'github.auth_token'! " "Please run 'scrum-tools github authorize' first! ") # organization organization = self.app.config.get('github', 'organization') # teams setup team_admins = self.app.config.get('github', 'team_admins') team_users = self.app.config.get('github', 'team_users') team_pattern = self.app.config.get('github', 'team_pattern') # repos setup repo_admins = self.app.config.get('github', 'repo_admins') repo_users = self.app.config.get('github', 'repo_users') repo_pattern = self.app.config.get('github', 'repo_pattern') # get the users user_repository = data.UserRepository(self.app.config) # create github session gh = login(token=self.app.config.get('github', 'auth_token')) # get the organization org = gh.organization(organization) if not org: raise RuntimeError("Organization '%s' not found" % organization) # get all organization repos teams = dict((t.name, t) for t in org.iter_teams()) repos = dict((r.name, r) for r in org.iter_repos()) # create group repos for group in user_repository.groups(): repo_group = repo_pattern % int(group) team_group = team_pattern % int(group) repo_teams = [ v for (k, v) in teams.iteritems() if k in [team_group, team_admins] ] self.__class__.__create_repo(org, repo_group, repo_teams, repos) # create admins repo repo_teams = [v for (k, v) in teams.iteritems() if k in [team_admins]] self.__class__.__create_repo(org, repo_admins, repo_teams, repos) # create users repo repo_teams = [ v for (k, v) in teams.iteritems() if k in [team_admins, team_users] ] self.__class__.__create_repo(org, repo_users, repo_teams, repos)
def create_boards(self): self.app.log.debug('Creating Trello boards.') # validate required config parameters if not self.app.config.get('trello', 'auth_key') or not self.app.config.get( 'trello', 'auth_token'): raise error.ConfigError( "Missing config parameter 'trello.auth_key' and/or 'trello.auth_token'! " "Please run 'scrum-tools trello authorize' first! ") # schema keys key_group = self.app.config.get('core', 'users_schema_key_group') key_trello = self.app.config.get('core', 'users_schema_key_trello') # organization organization = self.app.config.get('trello', 'organization') # boards setup board_admins_name = self.app.config.get('trello', 'board_admins') board_pattern = self.app.config.get('trello', 'board_pattern') board_lists = self.app.config.get('trello', 'board_lists') admins_group = self.app.config.get('trello', 'board_admins_group') # get the users user_repository = data.UserRepository(self.app.config) # create trello session tl = TrelloApi(self.app.config.get('trello', 'auth_key'), self.app.config.get('trello', 'auth_token')) # get the organization org = tl.organizations.get(organization) if not org: raise RuntimeError("Organization '%s' not found" % organization) # get all organization boards boards = dict( (b['name'], b) for b in tl.organizations.get_board(organization)) # create group boards for group in user_repository.groups(): board_name = board_pattern % int(group) board_admins = set(u[key_trello] for u in user_repository.users( lambda x: x[key_group] == admins_group)) board_members = set(u[key_trello] for u in user_repository.users( lambda x: x[key_group] == group)) self.__create_board(tl, org, board_name, set(board_lists), board_admins, board_members, boards) # create admins board board_admins = set(u[key_trello] for u in user_repository.users( lambda x: x[key_group] == admins_group)) board_members = set() self.__create_board(tl, org, board_admins_name, set(board_lists), board_admins, board_members, boards)
def delete_teams(self): if not self.__class__.prompt_confirm( colored('This cannot be undone! Proceed? (yes/no): ', 'red')): cprint("Aborting delete command.", 'yellow', file=sys.stdout) return self.app.log.debug('Deleting GitHub teams.') # validate required config parameters if not self.app.config.get('github', 'auth_token') or not self.app.config.get( 'github', 'auth_id'): raise error.ConfigError( "Missing config parameter 'github.auth_id' and/or 'github.auth_token'! " "Please run 'scrum-tools github authorize' first! ") # organization organization = self.app.config.get('github', 'organization') # teams setup team_admins = self.app.config.get('github', 'team_admins') team_users = self.app.config.get('github', 'team_users') team_pattern = self.app.config.get('github', 'team_pattern') user_repository = data.UserRepository(self.app.config) gh = login(token=self.app.config.get('github', 'auth_token')) # get the organization org = gh.organization(organization) if not org: raise RuntimeError("Organization '%s' not found" % organization) # get all organization teams teams = dict((t.name, t) for t in org.iter_teams()) # delete group teams for group in user_repository.groups(): team_name = team_pattern % int(group) self.__class__.__delete_team(team_name, teams) # delete admins team self.__class__.__delete_team(team_admins, teams) # delete users team self.__class__.__delete_team(team_users, teams)
def dump_sql_users(self): self.app.log.debug('Dumping SQL code for users.') # schema keys key_id = self.app.config.get('core', 'users_schema_key_id') key_github = self.app.config.get('core', 'users_schema_key_github') user_repository = data.UserRepository(self.app.config) print colored("-- Users", 'green') for u in user_repository.users(): if not u[key_github]: cprint("Skipping empty GitHub account for user '%s'." % u[key_id], 'yellow', file=sys.stdout) continue print colored( "INSERT INTO USERS(username, password, enabled) VALUES ('%s', md5('%s{%s}'), true);" % (u[key_github], u[key_id], u[key_github]), 'green')
def validate_users(self): self.app.log.debug('Validating GitHub account names.') # validate required config parameters if not self.app.config.get('github', 'auth_token') or not self.app.config.get( 'github', 'auth_id'): raise error.ConfigError( "Missing config parameter 'github.auth_id' and/or 'github.auth_token'! " "Please run 'scrum-tools github authorize' first! ") key_username = self.app.config.get('core', 'users_schema_key_username') key_github = self.app.config.get('core', 'users_schema_key_github') user_repository = data.UserRepository(self.app.config) gh = login(token=self.app.config.get('github', 'auth_token')) for u in user_repository.users(): if not u[key_github]: cprint("Skipping empty GitHub account for user '%s'." % u[key_username], 'yellow', file=sys.stdout) continue print colored( "Validating GitHub account '%s' for user '%s'..." % (u[key_github], u[key_username]), 'green'), try: if gh.user(u[key_github]): print colored('OK', 'green', attrs=['bold']) else: raise RuntimeError("Github user '%s' not found" % u[key_github]) except RuntimeError: print colored('Not OK', 'red', attrs=['bold'])
def validate_users(self): self.app.log.debug('Validating Trello account names.') # validate required config parameters if not self.app.config.get('trello', 'auth_key') or not self.app.config.get( 'trello', 'auth_token'): raise error.ConfigError( "Missing config parameter 'trello.auth_key' and/or 'trello.auth_token'! " "Please run 'scrum-tools trello authorize' first! ") key_username = self.app.config.get('core', 'users_schema_key_username') key_trello = self.app.config.get('core', 'users_schema_key_trello') # get the users user_repository = data.UserRepository(self.app.config) # create trello session tl = TrelloApi(self.app.config.get('trello', 'auth_key'), self.app.config.get('trello', 'auth_token')) for u in user_repository.users(): if not u[key_trello]: cprint("Skipping empty Trello account for user '%s'." % u[key_username], 'yellow', file=sys.stdout) continue print colored( "Validating Trello account '%s' for user '%s'..." % (u[key_trello], u[key_username]), 'green'), try: tl.members.get(u[key_trello]) print colored('OK', 'green', attrs=['bold']) except RequestException: print colored('Not OK', 'red', attrs=['bold'])
def create_teams(self): self.app.log.debug('Creating GitHub teams.') # validate required config parameters if not self.app.config.get('github', 'auth_token') or not self.app.config.get( 'github', 'auth_id'): raise error.ConfigError( "Missing config parameter 'github.auth_id' and/or 'github.auth_token'! " "Please run 'scrum-tools github authorize' first! ") # schema keys key_group = self.app.config.get('core', 'users_schema_key_group') key_github = self.app.config.get('core', 'users_schema_key_github') # organization organization = self.app.config.get('github', 'organization') # teams setup team_admins = self.app.config.get('github', 'team_admins') team_admins_group = self.app.config.get('github', 'team_admins_group') team_users = self.app.config.get('github', 'team_users') team_pattern = self.app.config.get('github', 'team_pattern') # repos setup repo_admins = self.app.config.get('github', 'repo_admins') repo_users = self.app.config.get('github', 'repo_users') repo_pattern = self.app.config.get('github', 'repo_pattern') # get the users user_repository = data.UserRepository(self.app.config) # create github session gh = login(token=self.app.config.get('github', 'auth_token')) # get the organization org = gh.organization(organization) if not org: raise RuntimeError("Organization '%s' not found" % organization) # get all organization teams teams = dict((t.name, t) for t in org.iter_teams()) # create group teams for group in user_repository.groups(): team_name = team_pattern % int(group) repo_names = ['%s/%s' % (organization, repo_pattern % int(group))] self.__class__.__create_team(org, team_name, repo_names, 'push', teams) # update group teams members for group in user_repository.groups(): team = teams[team_pattern % int(group)] members_act = set(m.login for m in team.iter_members()) members_exp = set(u[key_github] for u in user_repository.users( lambda x: x[key_group] == group)) self.__class__.__update_team_members(team, members_act, members_exp) # create admins team repo_names = ['%s/%s' % (organization, repo_admins)] + \ ['%s/%s' % (organization, repo_users)] + \ ['%s/%s' % (organization, repo_pattern % int(group)) for group in user_repository.groups()] self.__class__.__create_team(org, team_admins, repo_names, 'admin', teams) # update admins team members team = teams[team_admins] members_act = set(m.login for m in team.iter_members()) members_exp = set(u[key_github] for u in user_repository.users( lambda x: x[key_group] == team_admins_group)) self.__class__.__update_team_members(team, members_act, members_exp) # create users team repo_names = ['%s/%s' % (organization, repo_users)] self.__class__.__create_team(org, team_users, repo_names, 'pull', teams) # update users team members team = teams[team_users] members_act = set(m.login for m in team.iter_members()) members_exp = set(u[key_github] for u in user_repository.users()) self.__class__.__update_team_members(team, members_act, members_exp)
def create_card(self): self.app.log.debug('Creating Trello boards.') # validate required config parameters if not self.app.config.get('trello', 'auth_key') or not self.app.config.get( 'trello', 'auth_token'): raise error.ConfigError( "Missing config parameter 'trello.auth_key' and/or 'trello.auth_token'! " "Please run 'scrum-tools trello authorize' first! ") if not self.app.pargs.card_name: raise error.ConfigError( "Missing card name! Please set a '--card-name' option value!") # card parameters card_list = self.app.pargs.card_list card_name = self.app.pargs.card_name card_desc = self.app.pargs.card_description # organization organization = self.app.config.get('trello', 'organization') # boards setup board_pattern = self.app.config.get('trello', 'board_pattern') # get the users user_repository = data.UserRepository(self.app.config) # create trello session tl = TrelloApi(self.app.config.get('trello', 'auth_key'), self.app.config.get('trello', 'auth_token')) # get the organization org = tl.organizations.get(organization) if not org: raise RuntimeError("Organization '%s' not found" % organization) # get all user group boards board_names = [ board_pattern % int(group) for group in user_repository.groups() ] boards = [ b for b in tl.organizations.get_board(organization) if b['name'] in board_names ] # add new card to all boards for board in boards: # get lists for this board board_lists = dict([(l['name'], l) for l in tl.boards.get_list(board['id'])]) # skip if given card list does not exist in board if not card_list in board_lists: print colored("Skipping board '%s' (no list found)..." % (board['name']), 'green', attrs=['bold']), continue print colored("Adding card to list '%s' in '%s'..." % (card_list, board['name']), 'green', attrs=['bold']), try: tl.cards.new(name=card_name, idList=[board_lists[card_list]['id']], desc=card_desc) print colored('OK', 'green', attrs=['bold']) except RequestException: print colored('Not OK', 'red', attrs=['bold'])