mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-11-09 00:40:11 +01:00
Port urllib and HTMLParser imports to python3
This commit is contained in:
parent
fc21dbc667
commit
d39bf37ce8
@ -20,12 +20,13 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import urllib2
|
import urllib.request
|
||||||
|
import urllib.error
|
||||||
import time
|
import time
|
||||||
import subprocess
|
import subprocess
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
import traceback
|
import traceback
|
||||||
import HTMLParser
|
from html.parser import HTMLParser
|
||||||
from distutils.version import LooseVersion
|
from distutils.version import LooseVersion
|
||||||
import logging
|
import logging
|
||||||
import copy
|
import copy
|
||||||
@ -51,8 +52,8 @@ def check_http(app):
|
|||||||
vercode = "99999999"
|
vercode = "99999999"
|
||||||
if len(urlcode) > 0:
|
if len(urlcode) > 0:
|
||||||
logging.debug("...requesting {0}".format(urlcode))
|
logging.debug("...requesting {0}".format(urlcode))
|
||||||
req = urllib2.Request(urlcode, None)
|
req = urllib.request.Request(urlcode, None)
|
||||||
resp = urllib2.urlopen(req, None, 20)
|
resp = urllib.request.urlopen(req, None, 20)
|
||||||
page = resp.read()
|
page = resp.read()
|
||||||
|
|
||||||
m = re.search(codeex, page)
|
m = re.search(codeex, page)
|
||||||
@ -64,8 +65,8 @@ def check_http(app):
|
|||||||
if len(urlver) > 0:
|
if len(urlver) > 0:
|
||||||
if urlver != '.':
|
if urlver != '.':
|
||||||
logging.debug("...requesting {0}".format(urlver))
|
logging.debug("...requesting {0}".format(urlver))
|
||||||
req = urllib2.Request(urlver, None)
|
req = urllib.request.Request(urlver, None)
|
||||||
resp = urllib2.urlopen(req, None, 20)
|
resp = urllib.request.urlopen(req, None, 20)
|
||||||
page = resp.read()
|
page = resp.read()
|
||||||
|
|
||||||
m = re.search(verex, page)
|
m = re.search(verex, page)
|
||||||
@ -275,11 +276,11 @@ def check_gplay(app):
|
|||||||
time.sleep(15)
|
time.sleep(15)
|
||||||
url = 'https://play.google.com/store/apps/details?id=' + app.id
|
url = 'https://play.google.com/store/apps/details?id=' + app.id
|
||||||
headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux i686; rv:18.0) Gecko/20100101 Firefox/18.0'}
|
headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux i686; rv:18.0) Gecko/20100101 Firefox/18.0'}
|
||||||
req = urllib2.Request(url, None, headers)
|
req = urllib.request.Request(url, None, headers)
|
||||||
try:
|
try:
|
||||||
resp = urllib2.urlopen(req, None, 20)
|
resp = urllib.request.urlopen(req, None, 20)
|
||||||
page = resp.read()
|
page = resp.read()
|
||||||
except urllib2.HTTPError as e:
|
except urllib.error.HTTPError as e:
|
||||||
return (None, str(e.code))
|
return (None, str(e.code))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return (None, 'Failed:' + str(e))
|
return (None, 'Failed:' + str(e))
|
||||||
@ -288,7 +289,7 @@ def check_gplay(app):
|
|||||||
|
|
||||||
m = re.search('itemprop="softwareVersion">[ ]*([^<]+)[ ]*</div>', page)
|
m = re.search('itemprop="softwareVersion">[ ]*([^<]+)[ ]*</div>', page)
|
||||||
if m:
|
if m:
|
||||||
html_parser = HTMLParser.HTMLParser()
|
html_parser = HTMLParser()
|
||||||
version = html_parser.unescape(m.group(1))
|
version = html_parser.unescape(m.group(1))
|
||||||
|
|
||||||
if version == 'Varies with device':
|
if version == 'Varies with device':
|
||||||
|
@ -26,7 +26,7 @@ import socket
|
|||||||
import zipfile
|
import zipfile
|
||||||
import hashlib
|
import hashlib
|
||||||
import pickle
|
import pickle
|
||||||
import urlparse
|
import urllib.parse
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from xml.dom.minidom import Document
|
from xml.dom.minidom import Document
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
@ -773,7 +773,7 @@ def make_index(apps, sortedids, apks, repodir, archive, categories):
|
|||||||
|
|
||||||
mirrorcheckfailed = False
|
mirrorcheckfailed = False
|
||||||
for mirror in config.get('mirrors', []):
|
for mirror in config.get('mirrors', []):
|
||||||
base = os.path.basename(urlparse.urlparse(mirror).path.rstrip('/'))
|
base = os.path.basename(urllib.parse.urlparse(mirror).path.rstrip('/'))
|
||||||
if config.get('nonstandardwebroot') is not True and base != 'fdroid':
|
if config.get('nonstandardwebroot') is not True and base != 'fdroid':
|
||||||
logging.error("mirror '" + mirror + "' does not end with 'fdroid'!")
|
logging.error("mirror '" + mirror + "' does not end with 'fdroid'!")
|
||||||
mirrorcheckfailed = True
|
mirrorcheckfailed = True
|
||||||
@ -787,9 +787,9 @@ def make_index(apps, sortedids, apks, repodir, archive, categories):
|
|||||||
repoel.setAttribute("icon", os.path.basename(config['archive_icon']))
|
repoel.setAttribute("icon", os.path.basename(config['archive_icon']))
|
||||||
repoel.setAttribute("url", config['archive_url'])
|
repoel.setAttribute("url", config['archive_url'])
|
||||||
addElement('description', config['archive_description'], doc, repoel)
|
addElement('description', config['archive_description'], doc, repoel)
|
||||||
urlbasepath = os.path.basename(urlparse.urlparse(config['archive_url']).path)
|
urlbasepath = os.path.basename(urllib.parse.urlparse(config['archive_url']).path)
|
||||||
for mirror in config.get('mirrors', []):
|
for mirror in config.get('mirrors', []):
|
||||||
addElement('mirror', urlparse.urljoin(mirror, urlbasepath), doc, repoel)
|
addElement('mirror', urllib.parse.urljoin(mirror, urlbasepath), doc, repoel)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
repoel.setAttribute("name", config['repo_name'])
|
repoel.setAttribute("name", config['repo_name'])
|
||||||
@ -798,9 +798,9 @@ def make_index(apps, sortedids, apks, repodir, archive, categories):
|
|||||||
repoel.setAttribute("icon", os.path.basename(config['repo_icon']))
|
repoel.setAttribute("icon", os.path.basename(config['repo_icon']))
|
||||||
repoel.setAttribute("url", config['repo_url'])
|
repoel.setAttribute("url", config['repo_url'])
|
||||||
addElement('description', config['repo_description'], doc, repoel)
|
addElement('description', config['repo_description'], doc, repoel)
|
||||||
urlbasepath = os.path.basename(urlparse.urlparse(config['repo_url']).path)
|
urlbasepath = os.path.basename(urllib.parse.urlparse(config['repo_url']).path)
|
||||||
for mirror in config.get('mirrors', []):
|
for mirror in config.get('mirrors', []):
|
||||||
addElement('mirror', urlparse.urljoin(mirror, urlbasepath), doc, repoel)
|
addElement('mirror', urllib.parse.urljoin(mirror, urlbasepath), doc, repoel)
|
||||||
|
|
||||||
repoel.setAttribute("version", "15")
|
repoel.setAttribute("version", "15")
|
||||||
repoel.setAttribute("timestamp", str(int(time.time())))
|
repoel.setAttribute("timestamp", str(int(time.time())))
|
||||||
|
Loading…
Reference in New Issue
Block a user