def sync_repos(repos): try: # If it's a list, we need to unpack it if type(repos) == list: p = Popen(['repo', 'sync', '--force-sync'] + repos) else: p = Popen(['repo', 'sync', '--force-sync', repos]) out, err = p.communicate() except KeyboardInterrupt: cprint._exit(USER_ABORT_MSG)
def fetch_dependencies(repo_path): cprint.bold('\n- Looking for dependencies..') dependencies_path = repo_path + '/' + DEPENDENCY_FILE # List containing only the target_path(s), i.e: 'vendor/google' syncable_repos = [] if os.path.exists(dependencies_path): # Load up *.dependencies dependencies = None with open(dependencies_path, 'r') as dep_file: dependencies = json.loads(dep_file.read()) dep_file.close() if len(dependencies) == 0: cprint._exit('%s exists but it is empty.' % DEPENDENCY_FILE) # List containing the repositories to be added inside LOCAL_MANIFEST fetch_list = [] for dep in dependencies: name, remote = process_repo(dep['repository']) # If the dependency is not inside the LOCAL_MANIFEST if not is_in_manifest(name, dep['branch']): fetch_list.append(dep) # If the repository doesn't exist, append it to the syncable repos if not os.path.exists(dep['target_path']): syncable_repos.append(dep['target_path']) # If new manifest entries have to be added if fetch_list: cprint.bold('\n- Adding dependencies to local manifest..') add_to_manifest(fetch_list) # Synchronise repos if syncable_repos: cprint.bold('\n- Syncing dependencies..') sync_repos(syncable_repos) else: cprint._exit('Dependencies file not found, bailing out.')
def gather_device_repo(device_name): # Initial page to check page = 1 # Access token for GitHub token = get_github_token() while True: if sys.version_info < (3, 8): req = Request(GITHUB_API % (DEFAULT_ORG, page)) else: req = urllib.request.Request(GITHUB_API % (DEFAULT_ORG, page)) if token: req.add_header('Authorization', 'token %s' % token) try: if sys.version_info < (3, 8): resp = json.loads(urllib2.urlopen(req).read()) else: resp = json.loads(urllib.request.urlopen(req).read().decode()) except urllib2.HTTPError as e: if e.code == 403: cprint._exit( 'You were limited by GitHub, create a personal access token and write it inside $HOME/api_token\ncat $HOME/api_token >> <YOUR_API_TOKEN>\nFor more information on access token visit:\n%s' % GH_TOKEN_HELP) elif e.code == 401: cprint._exit( 'The GitHub access token you have used is invalid.\n') else: cprint._exit('%d: %s' % (e.code, e.reason)) except urllib2.URLError as e: cprint._exit(e.reason) # If we do not have more items, get out. if not resp: break for e in resp: repo_name = e['name'] if re.match('android_device_.*_%s$' % device_name, repo_name): return repo_name # We need moar page += 1 return None