1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-07-04 16:30:12 +02:00

upload release apk to AndroidObservatory

This commit is contained in:
thez3ro 2017-03-01 22:34:55 +01:00
parent 2242bb232b
commit d5e2d6f57a
No known key found for this signature in database
GPG Key ID: F628F9E41DD7C073
2 changed files with 45 additions and 2 deletions

View File

@ -220,6 +220,11 @@ The repository of older versions of applications from the main demo repository.
# nonstandardwebroot = False
# If you want to upload the release apk file to androidobservatory.org
#
# uploadto_androidobservatory = False
# The build logs can be posted to a mediawiki instance, like on f-droid.org.
# wiki_protocol = "http"
# wiki_server = "server"

View File

@ -225,6 +225,42 @@ def update_servergitmirrors(servergitmirrors, repo_section):
remote.push('master', force=True, set_upstream=True)
def upload_to_android_observatory(repo_section):
# depend on requests and lxml only if users enable AO
import requests
from lxml.html import fromstring
if repo_section == 'repo':
for f in glob.glob(os.path.join(repo_section, '*.apk')):
fpath = f
fname = os.path.basename(f)
logging.info('Uploading ' + fname + ' to androidobservatory.org')
# upload the file with a post request
r = requests.post('https://androidobservatory.org/upload', files={'apk': (fname, open(fpath, 'rb'))})
response = r.text
page = r.url
# from now on XPath will be used to retrieve the message in the HTML
# androidobservatory doesn't have a nice API to talk with
# so we must scrape the page content
tree = fromstring(response)
alert = tree.xpath("//html/body/div[@class='container content-container']/div[@class='alert alert-info']")[0]
message = ""
appurl = page
for el in alert:
# if the application was added successfully we retrive the url
# if the application was already uploaded we use the redirect page url
if el.attrib.get("href") is not None:
appurl = page + el.attrib["href"][1:]
message += el.text.replace(" here", "") + el.tail
else:
message += el.tail
message = message.strip() + " " + appurl
logging.info(message)
def main():
global config, options
@ -304,8 +340,9 @@ def main():
if not config.get('awsbucket') \
and not config.get('serverwebroot') \
and not config.get('servergitmirrors') \
and not config.get('uploadto_androidobservatory') \
and local_copy_dir is None:
logging.warn('No serverwebroot, local_copy_dir, or awsbucket set! '
logging.warn('No serverwebroot, servergitmirrors, local_copy_dir, awsbucket, or uploadto_androidobservatory set! '
+ 'Edit your config.py to set at least one.')
sys.exit(1)
@ -354,7 +391,8 @@ def main():
update_servergitmirrors(servergitmirrors, repo_section)
if config.get('awsbucket'):
update_awsbucket(repo_section)
if config.get('uploadto_androidobservatory'):
upload_to_android_observatory(repo_section)
sys.exit(0)