import requests, json, time from requests.auth import HTTPBasicAuth ''' This script can create a collection of publications in Calenco. It use Rest API to launch requests to Calenco. Specify: - your credentials - the workspace ws - the storsrv, defined in Calenco and pointing to the server storing the publications Check the publication list, in particular the collection of language in each manual ''' def test(): resp = requests.get('http://mageia.calenco.com:8284/workspaces/Documentation/publications/DrakX-FR-WebHelp', auth=HTTPBasicAuth('name','pw')) if resp.status_code != 200: # This means something went wrong. print('GET /workspaces/ {}'.format(resp.status_code)) exit() #for item in resp.json(): item = resp.json() print(item) #print('name: {}\nhref: {}\nautomatic: {}\n isOutdatad: {}\n xsl : :{}\n input : :{}\n output ::{}\n'.format(item['name'], # item['href'], item['automatic'], item['isOutdated'], item['xsl'], item['input'], item['output'])) def create_pub(pub_params,ws): user = "to_complete@mageia.org" pw = "password_to_complete" site = "http://mageia.calenco.com:8284/workspaces/" resp = requests.post('{}{}/publications'.format(site,ws), auth=HTTPBasicAuth(user, pw), data=json.dumps(pub_params)) #item = resp.json() print('Pour : %s'% pub_params['name'] ) print(resp.status_code, resp.text) if resp.status_code == 201: time.sleep(10) ws = "Mga7" dest = "/public_html/{}".format(ws) #storsrv = "storageservers/STOR0504658793a605a18f558fcea37f7931" Documentation storsrv = "storageservers/STOR5fa984e7e2ee1d4be873674cf37561b1" pub_params={} pub_paths = {'DrakLive' : 'draklive', 'MCC' : 'mcc', 'DrakX' : 'installer', 'NetInstall' : 'netinstall'} # code de deux lettres de la langue, manuel parmi DrakLive, MCC, DrakX, NetInstall listLang = { "DrakLive": ('cs','de','el','en','es','et','eu','fr','hr','ja','nb','nl','pt_BR','ro','ru','sk','sq','sl','sv','tr','uk','zh_CN'), 'DrakX' : ('ca','cs','de','el','en','eo','es','et','eu','fr','hr','hu','ja','nb','nl','pl', 'pt_BR','ro','ru','sk','sl','sq','sv','tr','uk','zh_CN') , 'MCC' : ('ca','cs','da','de','el','en','es','et','eu','fr','hu','id','it','ja','nb','nl','pl', 'pt_BR','ro','ru','sk','sl','sq','sv','tr','uk','zh_CN'), 'NetInstall' : ('ca','cs','de','el','en','es','et','eu','fr','hu','ja','nb','nl', 'pt_BR','ru','sl','sv','tr','uk','zh_CN') } pubs = [] for manual in listLang.keys(): for lang in listLang[manual]: pubs.append([lang,manual]) for pub in pubs: #WebHelp pub_params['input']= '/workspaces/{ws}/content/{lang}/{manual}.xml'.format(manual=pub[1], lang=pub[0],ws = ws) pub_params['name'] = '{manual}-{lang}-WebHelp'.format(manual=pub[1], lang=pub[0].upper()) pub_params['rs-path'] = "{dest}/{lang}/{path}".format( lang=pub[0].lower(), path=pub_paths[pub[1]], dest=dest) pub_params['outname'] = '{manual}'.format(manual=pub_paths[pub[1]]) pub_params['intype'] = 'DocBook5.0' pub_params['toolchain'] = 'DocBook_Screen_WebHelp' pub_params['xsl'] = '/workspaces/{}/content/WebHelp-DrakX.xsl'.format(ws) if (pub[1] == "DrakLive"): pub_params['xslparams'] = 'profile.condition=live' elif(pub[1] == "DrakX"): pub_params['xslparams'] = 'profile.condition=classical' pub_params['method'] = 'FTP' pub_params['storsrv'] = '/workspaces/{}/{}'.format(ws,storsrv) pub_params['rs-multifile'] = True pub_params['automatic'] = True create_pub(pub_params,ws) # WebHelp-zipped pub_params['name'] = '{manual}-{lang}-WebHelp-zipped'.format(manual=pub[1], lang=pub[0].upper()) del pub_params['rs-multifile'] pub_params['rs-path'] = "{dest}/zipped/{path}/{lang}".format(dest = dest, lang=pub[0].lower(), path=pub_paths[pub[1]]) pub_params['outname'] = '{manual}-{lang}-WebHelp-zipped.zip'.format(lang=pub[0].upper(), manual=pub[1]) create_pub(pub_params,ws) # Epub pub_params['name'] = '{manual}-{lang}-EPUB'.format(manual=pub[1], lang=pub[0].upper()) pub_params['rs-path'] = "/public_html/EPUB/{path}".format( path=pub_paths[pub[1]]) pub_params['toolchain'] = 'DocBook_EPUB3_Chunk' pub_params['xsl'] = 'http://www.calenco.com/xsl/epub3/epub.xsl' pub_params['outname'] = '{manual}-{lang}-EPUB.epub'.format(lang=pub[0].upper(), manual=pub[1]) create_pub(pub_params,ws) # PDF (cover) pub_params['input']= '/workspaces/{ws}/content/{lang}/{manual}-cover.xml'.format(manual=pub[1], lang=pub[0], ws = ws) pub_params['name'] = '{manual}-cover-{lang}-PDF'.format(manual=pub[1], lang=pub[0].upper()) pub_params['rs-path'] = "{dest}/PDF/{path}".format( path=pub_paths[pub[1]],dest=dest) pub_params['xsl'] = 'http://www.calenco.com/xsl/docbook/ns/fo/calenco-fo.xsl' pub_params['outname'] = '{manual}-cover-{lang}-PDF.pdf'.format(lang=pub[0].upper(), manual=pub[1]) pub_params['toolchain'] = 'DocBook_to_PDF_FOP' create_pub(pub_params,ws)