def run(self, options, args): opts, args = self.parser.parse_args(args) if not args: self.parser.error('You must provide a name for your repository') return self.FAILURE name = args.pop(0) self.login() org = None if opts.organization: org = self.gh.organization(opts.organization) conf = {} conf['description'] = input('Description: ') conf['homepage'] = input('Website: ') conf['private'] = bool(input('Private [False]: ') or False) repo = None status = self.SUCCESS if org: teams = [t for t in org.iter_teams()] print('(Optional) Select team to add this to:') for i, t in enumerate(teams): print('\t[{0}] {1}'.format(i, t.name)) i = int(input('')) conf['team_id'] = teams[i].id repo = org.create_repo(name, **conf) else: repo = self.gh.create_repo(name, **conf) if not repo: status = self.FAILURE else: print("{0} {0.html_url}".format(repo)) return status
def login(self): # Get the full path to the configuration file config = github_config() parser = ConfigParser() # Check to make sure the file exists and we are allowed to read it if os.path.isfile(config) and os.access(config, os.R_OK | os.W_OK): parser.readfp(open(config)) self.gh.login(token=parser.get('github', 'token')) else: # Either the file didn't exist or we didn't have the correct # permissions user = '' while not user: # We will not stop until we are given a username user = input('Username: '******'' while not pw: # Nor will we stop until we're given a password pw = getpass('Password: '******'user', 'repo', 'gist'], 'github-cli', 'http://git.io/MEmEmw' ) parser.add_section('github') parser.set('github', 'token', auth.token) self.gh.login(token=auth.token) # Create the file if it doesn't exist. Otherwise completely blank # out what was there before. Kind of dangerous and destructive but # somewhat necessary parser.write(open(config, 'w+'))