switch to python3 (#68601)

This commit is contained in:
Frédéric Péters 2022-09-01 08:39:30 +02:00
parent fefd51d8d8
commit 16c85eee7e
1 changed files with 13 additions and 12 deletions

View File

@ -1,4 +1,4 @@
#! /usr/bin/env python
#! /usr/bin/env python3
import json
import os
@ -9,7 +9,6 @@ import tempfile
import re
import urllib2
import urlparse
import xml.etree.ElementTree as ET
MAL_NS = 'http://projectmallard.org/1.0/'
@ -25,6 +24,7 @@ if not os.path.exists('jhbuild'):
if not os.path.exists(checkouts_directory):
os.mkdir(checkouts_directory)
def checkout(module):
checkout_dir = os.path.join(checkouts_directory, module)
@ -42,12 +42,12 @@ def checkout(module):
subprocess.call(cmd, **kws)
def download(url):
filename = os.path.split(urlparse.urlparse(url)[2])[-1]
if not os.path.exists(os.path.join(checkouts_directory, filename)):
fd = file(os.path.join(checkouts_directory, filename), 'w')
fd.write(urllib2.urlopen(url).read())
fd.close()
with open(os.path.join(checkouts_directory, filename), 'w') as fd:
fd.write(urllib2.urlopen(url).read())
def publish_mallard(module, branch, directory):
@ -93,8 +93,8 @@ def publish_mallard(module, branch, directory):
pages = []
for page_file in page_files:
text = open(page_file).read()
text = re.sub('<title.*type="sort".*</title>', '', text)
titles = re.findall('<title.*>(.*)<\/title>', text)
text = re.sub(r'<title.*type="sort".*</title>', '', text)
titles = re.findall(r'<title.*>(.*)<\/title>', text)
if not titles:
continue
pages.append({
@ -136,12 +136,12 @@ def publish_mallard(module, branch, directory):
if not os.path.exists(os.path.join(temp_dir, 'doc-%s.pdf' % module_name)):
break
else:
fd = file(os.path.join(output_dir, 'doc-%s.pdf' % module_name), 'w')
fd.write(file(os.path.join(temp_dir, 'doc-%s.pdf' % module_name)).read())
fd.close()
with open(os.path.join(output_dir, 'doc-%s.pdf' % module_name), 'wb') as fd:
fd.write(open(os.path.join(temp_dir, 'doc-%s.pdf' % module_name), 'rb').read())
shutil.rmtree(temp_dir)
def publish_tarball(module):
output_dir = os.path.join(web_directory, module.get('name'), 'stable')
url = module.get('url')
@ -157,7 +157,7 @@ def publish_tarball(module):
os.makedirs(output_filename)
else:
fd = tar.extractfile(tarinfo)
file(output_filename, 'w').write(fd.read())
open(output_filename, 'wb').write(fd.read())
def publish_sphinx(module):
@ -172,7 +172,8 @@ def publish_sphinx(module):
shutil.copytree(build_dir, output_dir)
modules = json.load(file('modules.json'))
with open('modules.json') as fd:
modules = json.load(fd)
for module in modules:
if module.get('type') == 'tarball':