def get_latest_image(self,url):

        auth = str(
            base64.b64encode(
                bytes('%s:%s' % (cicd_user,cicd_pw ), 'utf-8')
            ),
            'ascii'
        ).strip()
        headers = {'Authorization': 'Basic ' + auth}

        ''' FIND THE LATEST FILE NAME'''
        print(url)
        req = urllib.request.Request(url, headers=headers)
        response = urllib.request.urlopen(req)
        html = response.read()
        soup = BeautifulSoup(html, features="html.parser")
        last_link = soup.find_all('a', href=True)[-1]
        latest_file=last_link['href']

        filepath = local_dir
        os.chdir(filepath)
        #file_url = url + latest_file

        ''' Download the binary file from Jfrog'''
        path = ArtifactoryPath(url,auth=(cicd_user, cicd_pw))
        path.touch()
        for file in path:
            print('File =', file)

        path = ArtifactoryPath(file, auth=(cicd_user, cicd_pw))
        print("file to be downloaded :" ,latest_file)
        print("File Path:",file)
        with path.open() as des:
            with open(latest_file, "wb") as out:
                out.write(des.read())
        des.close()
        print("Extract the tar.gz file and upgrade the AP ")
        housing_tgz = tarfile.open(latest_file)
        housing_tgz.extractall()
        housing_tgz.close()
        return "pass"
        print("Extract the tar file, and copying the file to  Linksys AP directory")
        #with open("/Users/syamadevi/Desktop/syama/ea8300/ap_sysupgrade_output.log", "a") as output:
         #   subprocess.call("scp /Users/syamadevi/Desktop/syama/ea8300/openwrt-ipq40xx-generic-linksys_ea8300-squashfs-sysupgrade.bin [email protected]:/tmp/openwrt-ipq40xx-generic-linksys_ea8300-squashfs-sysupgrade.bin",shell=True, stdout=output,
          #                 stderr=output)

        print('SSH to Linksys and upgrade the file')

        '''
Esempio n. 2
0
artifactory_url = os.getenv('HELM_CHART_ARTIFACTORY_URL')
if not artifactory_url:
    exit_environment_not_set('HELM_CHART_ARTIFACTORY_URL')
helm_repo = os.getenv('HELM_CHART_MUSEUM_REPO')
if not helm_repo:
    exit_environment_not_set('HELM_CHART_MUSEUM_REPO')

# Login to artifactory
credentials = (username, password)

full_artifactory_url = artifactory_url + helm_repo + '/'
artifactory_path = ArtifactoryPath(
    full_artifactory_url,
    auth=credentials,
)
artifactory_path.touch()

# List from html website as GET API does not provide creation timestamp
r = requests.get(full_artifactory_url)

# Split response body per artifact
artifact_list = re.search("<a href(.*)</pre>",
                          str(r.content)).group(0).split('<a href')
artifact_list_trimmed = list(filter(lambda x: x != "", artifact_list))

# Extract artifact name and date
clean_artifact_map = map(
    lambda p: re.search(">(.*)</a>[ ]+(.*)  ", str(p)).group(1, 2),
    artifact_list_trimmed,
)
# Extract chart name for sorting