source: devtools/generate_AppImage_catalogue/dl_XmlAppImageCat.py

Last change on this file was 6465, checked in by Juanma, 22 months ago

add firefox customizer

  • Property svn:executable set to *
File size: 5.8 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        th=threading.Thread(target=_th_write_xml, args = (app,outdir,semaphore))
48        th.start()
49
50def _th_write_xml(app,outdir,semaphore):
51    semaphore.acquire()
52    global descDict
53    lock=threading.Lock()
54    print("Generating "+app+" xml")
55    nameSplitted=app.split('-')
56    name=nameSplitted[0]
57    version=nameSplitted[1]
58    arch=nameSplitted[2]
59    f=open(outdir+'/'+name+"_"+version+".appdata.xml",'w')
60    f.write('<?xml version="1.0" encoding="UTF-8"?>'+"\n")
61    f.write("<components version=\"0.10\">\n")
62    f.write("<component  type=\"desktop-application\">\n")
63    f.write("  <id>"+app.lower()+"</id>\n")
64    f.write("  <pkgname>"+app+"</pkgname>\n")
65    f.write("  <name>"+name+"</name>\n")
66    f.write("  <summary>"+name+" AppImage Bundle</summary>\n")
67    f.write("  <metadata_license>CC0-1.0</metadata_license>\n")
68    f.write("  <provides><binary>"+app+"</binary></provides>\n")
69    f.write("  <releases>\n")
70    f.write("  <release version=\""+version+"\" timestamp=\"1408573857\"></release>\n")
71    f.write("  </releases>\n")
72    f.write("  <launchable type=\"desktop-id\">"+name+".desktop</launchable>\n")
73    with lock:
74        if name in descDict.keys():
75            description=descDict[name]
76        else:
77            description=get_description(name)
78            descDict.update({name:description})
79    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")
80    f.write("  <bundle type=\"appimage\">"+app+"</bundle>\n")
81    f.write("  <keywords>\n")
82    f.write("    <keyword>"+name+"</keyword>\n")
83    f.write("    <keyword>appimage</keyword>\n")
84    f.write("  </keywords>\n")
85    f.write("  <categories>\n")
86    f.write("    <category>AppImage</category>\n")
87    f.write("    <category>GTK</category>\n")
88    f.write("  </categories>\n")
89    f.write("<icon type=\"cached\">"+name+"_"+name+".png</icon>\n")
90    f.write("</component>\n")
91    f.write("</components>\n")
92    f.close()
93    semaphore.release()
94
95def write_yml(applist,outfile):
96    oldName=''
97    oldDesc=''
98    f=open(outfile,'w')
99    f.write("---\nFile: DEP-11\nVersion: '0.8'\nOrigin: xenial-main\n")
100    for app in applist:
101        nameSplitted=app.split('-')
102        name=nameSplitted[0]
103        version=nameSplitted[1]
104        arch=nameSplitted[2]
105        f.write("---\n")
106        f.write("Categories:\n  - GTK\n  - AppImage\n")
107        f.write("ID: "+app.lower()+"\n")
108        f.write("Icon:\n  stock: "+name+"_"+name+".png\n")
109        f.write("Name:\n C: "+name+"\n")
110        f.write("Package: "+app+"\n")
111        f.write("Summary:\n  C: "+name+" AppImage Bundle\n")
112        f.write("Description:\n")
113        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")
114        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")
115        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")
116        description=oldDesc
117        if oldName!=name:
118            description=get_description(name)
119            oldName=name
120            oldDesc=description
121        f.write("  "+description+"</p>\n")
122        f.write("Type: desktop-app\n")
123        f.write("Keywords:\n")
124        f.write("  C:\n")
125        f.write("    - "+name+"\n")
126        f.write("    - "+app+"\n")
127        f.write("Bundle:\n- type: appimage\n  id: "+app+"\n")
128        f.write("Releases:\n")
129        f.write("  - version: "+version+"\n")
130    f.close()
131
132args=sys.argv[1:]
133if '-y' in args:
134    sw_generate='yml'
135    print("Generating dep11 catalogue...")
136else:
137    sw_generate='xml'
138    print("Generating xml catalogue...")
139outfile='appimage.yml'
140outdir="/usr/share/metainfo"
141outdir="/tmp"
142content=''
143applist=[]
144repolist=['https://dl.bintray.com/probono/AppImages']
145descDict={}
146for repo in repolist:
147    print(("Fetching repo %s")%(repo))
148    applist=generate_applist(fetch_repo(repo))
149    print("Processing info...")
150    if sw_generate=='yml':
151        write_yml(applist,outfile)
152    else:
153        th_generate_xml_catalog(applist,outdir)
154    print("Work done!")
155
156
Note: See TracBrowser for help on using the repository browser.