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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
import requests, json
from requests.auth import HTTPBasicAuth
import os.path as path
import time
def list_pubs(manual):
pub_params={}
user = "to_complete@mageia.org"
pw = "to_complete"
site = "http://mageia.calenco.com:8284/workspaces/"
ws = "Mga7"
#storsrv = "storageservers/STOR0504658793a605a18f558fcea37f7931"
storsrv = "storageservers/Default"
headers = {'content-type': 'application/json'}
if manual != '':
pub_params['file'] = manual
pub_params['input']= '/workspaces/%s/publications'.format(ws)
print("Wait to get the list of publications...\n")
resp = requests.get(site+ws+'/publications',
auth=HTTPBasicAuth(user, pw),
data=json.dumps(pub_params))
if int(resp.status_code) != 200:
# This means something went wrong.
print('GET /workspaces/ {}'.format(resp.status_code))
exit()
print("Writing liste.csv")
with open("listeMga7.csv",'w') as f:
f.write("Name\thref\tInput\tOutput\tupdated\tStatus\tAutomatic\n")
for item in resp.json():
print(item)
if item['output']['method'] in ('FTP','SFTP'):
serv=item['output']['storsrv']
f.write("{name}\t{href}\t{input}\t{output}\t{updated}\t{status}\t{automatic}\t{server}\t{path}\n".format(name=item["name"],href=item["href"],updated=item["updated"],
output=item['output']['name'],status=item["status"],automatic=item["automatic"], input=item['input']['href'], server = serv, path=item['output']['path']))
else:
serv=''
exit()
# Set a new storage server
for item in resp.json():
# Point to prestored server
if item['output']['method'] in ('FTP','SFTP'):
print('{site}{ws}/publications/{name}'.format(site=site, ws=ws,name=item['name']))
print(item['output']['path'], item['output']['storsrv'])
item['output']['rs-path']=item['output']['path']
if not item['output']['zip'] :
item['output']['rs-multifile']='multifile'
item['output']['storsrv']= '/workspaces/{ws}/strorageservers/{storsrv}'.format (ws=ws, storsrv=storsrv)
resp2 = requests.put('{site}{ws}/publications/{name}'.format(site=site, ws=ws,name=item['name']),
auth=HTTPBasicAuth(user, pw),
data=json.dumps(item),
headers=headers)
if int(resp2.status_code) != 200:
# This means something went wrong.
print('PUT /workspaces/ {}: {}'.format(resp2.status_code, resp2.text))
time.sleep(15)
exit()
# renew each publication
for item in resp.json():
if item['name'].find('WebHelp') != -1:
pub_params = {}
pub_params['name']= item['name']
print(item['name'], pub_params)
resp2 = requests.post('{site}{ws}/pubsqueue'.format(site=site, ws=ws),
auth=HTTPBasicAuth(user, pw),
data=json.dumps(pub_params),
headers=headers)
if int(resp2.status_code) != 202:
# This means something went wrong.
print('GET /workspaces/ {}'.format(resp2.status_code))
exit()
# Add delay of 30 seconds between each publication
time.sleep(30)
list_pubs('')
|