forked from Azure/azure-storage-fuse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
releaseVersionUpdate.py
36 lines (31 loc) · 1.41 KB
/
releaseVersionUpdate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import json
import requests
import sys
from xml.dom import minidom
sasUrl = sys.argv[1]
releaseVersion = sys.argv[2].split(' ')[2]
print('Release Version: ' + releaseVersion)
if(len(releaseVersion)==0):
print('Incorrect Release Version')
sys.exit(1)
containerUrl = sasUrl.split('?')[0]
sasToken = sasUrl.split('?')[1]
# list latest version file in the container
listUrl = sasUrl + '&restype=container&comp=list&prefix=latest/'
resp = requests.get(listUrl)
sys.exit(1) if(resp.status_code<200 or resp.status_code>202) else print('Listed latest version container')
listData = minidom.parseString(resp.content)
name = listData.getElementsByTagName('Name')
if(len(name)!=1):
print('Latest version container should have exactly one file. Number of files present is ' + str(len(name)))
sys.exit(1)
latestVersion = name[0].firstChild.data
print('Last release version: ' + latestVersion)
# delete latest version file in the container
deleteUrl = containerUrl + '/' + latestVersion + '?' + sasToken
resp = requests.delete(deleteUrl)
sys.exit(1) if(resp.status_code<200 or resp.status_code>202) else print('Deleted last release file')
# create release version file in the container
createUrl = containerUrl + '/latest/' + releaseVersion + '?' + sasToken
resp = requests.put(createUrl, headers={'x-ms-blob-type': 'BlockBlob'})
sys.exit(1) if(resp.status_code<200 or resp.status_code>202) else print('Created new release version file')