def update_licenses(quiet=False): utils.readConf() url = utils.URL.rstrip("/") + "/licenses" r = requests.get(url, auth=(utils.USERNAME, utils.PASSWORD)) htmlElements = html.document_fromstring(r.text) htmlElements.make_links_absolute(url + "/", resolve_base_href=True) folderPattern = re.compile(url + '/[a-z0-9\-]+/') downloadPattern = re.compile('\S+\.(license|key)') # Filter to only keep folders licenseFolders = list( filter(lambda x: folderPattern.match(x), [elem[2] for elem in htmlElements.iterlinks()])) if len(licenseFolders) == 0: logger.info("No license files found!") else: # Find the .licence and .key files under each folder for folderUrl in set(licenseFolders): r = requests.get(folderUrl, auth=(utils.USERNAME, utils.PASSWORD)) htmlElements = html.document_fromstring(r.text) htmlElements.make_links_absolute(folderUrl + "/", resolve_base_href=True) for link in set([elem[2] for elem in htmlElements.iterlinks()]): match = downloadPattern.search(link) if match is not None: logger.info("downloading %s" % (link)) utils.download( link, utils.LICENCES_PATH + "/" + os.path.basename(link), quiet)
def update(): utils.readConf() logging.debug('Updating the index') utils.getRudderKey() # backup the current indexFile if it exists logging.debug("backuping %s in %s"%(utils.INDEX_PATH, utils.INDEX_PATH + ".bkp")) if os.path.isfile(utils.INDEX_PATH): os.rename(utils.INDEX_PATH, utils.INDEX_PATH + ".bkp") try: utils.download(utils.URL + "/" + "rpkg.index") except Exception as e: traceback.print_exc(file=sys.stdout) if os.path.isfile(utils.INDEX_PATH + ".bkp"): logging.debug("restoring %s from %s"%(utils.INDEX_PATH, utils.INDEX_PATH + ".bkp")) os.rename(utils.INDEX_PATH + ".bkp", utils.INDEX_PATH) utils.fail(e)