source: devtools/generate_AppImage_catalogue/dl_XmlAppImageCat.py @ 5166

Last change on this file since 5166 was 5166, checked in by Juanma, 21 months ago

added appImage catalogue generator

  • Property svn:executable set to *
File size: 5.9 KB
Line 
1#!/usr/bin/env python3
2#Download and generate a yml catalog from appimage repository at https://dl.bintray.com/probono/AppImages/
3import sys
4import urllib.request
5import threading
6from bs4 import BeautifulSoup
7import random
8def fetch_repo(repo):
9    with urllib.request.urlopen('https://dl.bintray.com/probono/AppImages') as f:
10        content=(f.read().decode('utf-8'))
11    return(content)
12
13def generate_applist(content):
14    garbageList=[]
15    garbageList=content.split(' ')
16    for garbageLine in garbageList:
17        if garbageLine.endswith('AppImage"'):
18            app=garbageLine.replace('href=":','')
19            applist.append(app.replace('"',''))
20    return(applist)
21
22def get_description(appName):
23    desc=''
24    print("Getting description from 'https://bintray.com/probono/AppImages/'"+appName)
25    try:
26        with urllib.request.urlopen('https://bintray.com/probono/AppImages/'+appName) as f:
27            content=(f.read().decode('utf-8'))
28        soup=BeautifulSoup(content,"html.parser")
29        descDiv=soup.findAll('div', attrs={ "class" : "description-text"})
30        if len(descDiv)>0:
31            desc=descDiv[0].text
32            desc=desc.replace(':','.')
33            desc=desc.replace('&','&')
34    except:
35        pass
36    return(desc)
37
38def th_generate_xml_catalog(applist,outdir):
39    oldName=''
40    oldDesc=''
41    descDict={}
42    maxconnections = 10
43    semaphore = threading.BoundedSemaphore(value=maxconnections)
44    randomList = list(applist)
45    random.shuffle(randomList)
46    for app in randomList:
47        print("Launching thread")
48        th=threading.Thread(target=_th_write_xml, args = (app,outdir,semaphore))
49        th.start()
50
51def _th_write_xml(app,outdir,semaphore):
52    semaphore.acquire()
53    global descDict
54    lock=threading.Lock()
55    print("Generating "+app+" xml")
56    nameSplitted=app.split('-')
57    name=nameSplitted[0]
58    version=nameSplitted[1]
59    arch=nameSplitted[2]
60    f=open(outdir+'/'+name+"_"+version+".appdata.xml",'w')
61    f.write('<?xml version="1.0" encoding="UTF-8"?>'+"\n")
62    f.write("<components version=\"0.10\">\n")
63    f.write("<component  type=\"desktop-application\">\n")
64    f.write("  <id>"+app.lower()+"</id>\n")
65    f.write("  <pkgname>"+app+"</pkgname>\n")
66    f.write("  <name>"+name+"</name>\n")
67    f.write("  <summary>"+name+" AppImage Bundle</summary>\n")
68    f.write("  <metadata_license>CC0-1.0</metadata_license>\n")
69    f.write("  <provides><binary>"+app+"</binary></provides>\n")
70    f.write("  <releases>\n")
71    f.write("  <release version=\""+version+"\" timestamp=\"1408573857\"></release>\n")
72    f.write("  </releases>\n")
73    f.write("  <launchable type=\"desktop-id\">"+name+".desktop</launchable>\n")
74    with lock:
75        if name in descDict.keys():
76            description=descDict[name]
77        else:
78            description=get_description(name)
79            descDict.update({name:description})
80    f.write("  <description><p>This is an AppImage bundle of app "+name+". It hasn't been tested by our developers and comes from a 3rd party dev team. Please use it carefully.</p><p>"+description+"</p></description>\n")
81    f.write("  <bundle type=\"appimage\">"+app+"</bundle>\n")
82    f.write("  <keywords>\n")
83    f.write("    <keyword>"+name+"</keyword>\n")
84    f.write("    <keyword>appimage</keyword>\n")
85    f.write("  </keywords>\n")
86    f.write("  <categories>\n")
87    f.write("    <category>AppImage</category>\n")
88    f.write("    <category>GTK</category>\n")
89    f.write("  </categories>\n")
90    f.write("<icon type=\"cached\">"+name+"_"+name+".png</icon>\n")
91    f.write("</component>\n")
92    f.write("</components>\n")
93    f.close()
94    semaphore.release()
95
96def write_yml(applist,outfile):
97    oldName=''
98    oldDesc=''
99    f=open(outfile,'w')
100    f.write("---\nFile: DEP-11\nVersion: '0.8'\nOrigin: xenial-main\n")
101    for app in applist:
102        nameSplitted=app.split('-')
103        name=nameSplitted[0]
104        version=nameSplitted[1]
105        arch=nameSplitted[2]
106        f.write("---\n")
107        f.write("Categories:\n  - GTK\n  - AppImage\n")
108        f.write("ID: "+app.lower()+"\n")
109        f.write("Icon:\n  stock: "+name+"_"+name+".png\n")
110        f.write("Name:\n C: "+name+"\n")
111        f.write("Package: "+app+"\n")
112        f.write("Summary:\n  C: "+name+" AppImage Bundle\n")
113        f.write("Description:\n")
114        f.write("  C:<p>This is an AppImage bundle of app "+name+". It hasn't been tested by our developers and comes from a 3rd party dev team. Please use it carefully\n")
115        f.write("  Este es el paquete AppImage de la aplicación "+name+". No ha sido testado por nuestros desarrolladores y proviene de equipo de desarrollo externo. Por favor, utilizalo con cuidado\n")
116        f.write("  This is an AppImage bundle of app "+name+". It hasn't been tested by our developers and comes from a 3rd party dev team. Please use it carefully<p>\n")
117        description=oldDesc
118        if oldName!=name:
119            description=get_description(name)
120            oldName=name
121            oldDesc=description
122        f.write("  "+description+"</p>\n")
123        f.write("Type: desktop-app\n")
124        f.write("Keywords:\n")
125        f.write("  C:\n")
126        f.write("    - "+name+"\n")
127        f.write("    - "+app+"\n")
128        f.write("Bundle:\n- type: appimage\n  id: "+app+"\n")
129        f.write("Releases:\n")
130        f.write("  - version: "+version+"\n")
131    f.close()
132
133args=sys.argv[1:]
134if '-y' in args:
135    sw_generate='yml'
136    print("Generating dep11 catalogue...")
137else:
138    sw_generate='xml'
139    print("Generating xml catalogue...")
140outfile='appimage.yml'
141outdir="/usr/share/metainfo"
142outdir="/tmp"
143content=''
144applist=[]
145repolist=['https://dl.bintray.com/probono/AppImages']
146descDict={}
147for repo in repolist:
148    print(("Fetching repo %s")%(repo))
149    applist=generate_applist(fetch_repo(repo))
150    print("Processing info...")
151    if sw_generate=='yml':
152        write_yml(applist,outfile)
153    else:
154        th_generate_xml_catalog(applist,outdir)
155    print("Work done!")
156
157
Note: See TracBrowser for help on using the repository browser.