Port gnome-shell to Python 3
https://bugzilla.gnome.org/show_bug.cgi?id=732478
This commit is contained in:
parent
568454abb8
commit
be3c3c64c1
@ -37,7 +37,7 @@ AC_PATH_PROG([XSLTPROC], [xsltproc])
|
|||||||
GLIB_GSETTINGS
|
GLIB_GSETTINGS
|
||||||
|
|
||||||
# Get a value to substitute into gnome-shell.in
|
# Get a value to substitute into gnome-shell.in
|
||||||
AM_PATH_PYTHON([2.5])
|
AM_PATH_PYTHON([3])
|
||||||
AC_SUBST(PYTHON)
|
AC_SUBST(PYTHON)
|
||||||
|
|
||||||
# We need at least this, since gst_plugin_register_static() was added
|
# We need at least this, since gst_plugin_register_static() was added
|
||||||
|
@ -14,7 +14,7 @@ except ImportError:
|
|||||||
try:
|
try:
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print 'The Python simplejson module is required'
|
print('The Python simplejson module is required')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
from gi.repository import Gio
|
from gi.repository import Gio
|
||||||
@ -88,36 +88,36 @@ function disable() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def create_extension():
|
def create_extension():
|
||||||
print
|
print()
|
||||||
print '''Name should be a very short (ideally descriptive) string.
|
print('''Name should be a very short (ideally descriptive) string.
|
||||||
Examples are: "Click To Focus", "Adblock", "Shell Window Shrinker".
|
Examples are: "Click To Focus", "Adblock", "Shell Window Shrinker".
|
||||||
'''
|
''')
|
||||||
name = raw_input('Name: ').strip()
|
name = input('Name: ').strip()
|
||||||
print
|
print()
|
||||||
print '''Description is a single-sentence explanation of what your extension does.
|
print('''Description is a single-sentence explanation of what your extension does.
|
||||||
Examples are: "Make windows visible on click", "Block advertisement popups"
|
Examples are: "Make windows visible on click", "Block advertisement popups"
|
||||||
"Animate windows shrinking on minimize"
|
"Animate windows shrinking on minimize"
|
||||||
'''
|
''')
|
||||||
description = raw_input('Description: ').strip()
|
description = input('Description: ').strip()
|
||||||
underifier = re.compile('[^A-Za-z]')
|
underifier = re.compile('[^A-Za-z]')
|
||||||
sample_uuid = underifier.sub('_', name)
|
sample_uuid = underifier.sub('_', name)
|
||||||
# TODO use evolution data server
|
# TODO use evolution data server
|
||||||
hostname = socket.gethostname()
|
hostname = socket.gethostname()
|
||||||
sample_uuid = sample_uuid + '@' + hostname
|
sample_uuid = sample_uuid + '@' + hostname
|
||||||
|
|
||||||
print
|
print()
|
||||||
print '''Uuid is a globally-unique identifier for your extension.
|
print('''Uuid is a globally-unique identifier for your extension.
|
||||||
This should be in the format of an email address (foo.bar@extensions.example.com), but
|
This should be in the format of an email address (foo.bar@extensions.example.com), but
|
||||||
need not be an actual email address, though it's a good idea to base the uuid on your
|
need not be an actual email address, though it's a good idea to base the uuid on your
|
||||||
email address. For example, if your email address is janedoe@example.com, you might
|
email address. For example, if your email address is janedoe@example.com, you might
|
||||||
use an extension title clicktofocus@janedoe.example.com.'''
|
use an extension title clicktofocus@janedoe.example.com.''')
|
||||||
uuid = raw_input('Uuid [%s]: ' % (sample_uuid, )).strip()
|
uuid = input('Uuid [%s]: ' % (sample_uuid, )).strip()
|
||||||
if uuid == '':
|
if uuid == '':
|
||||||
uuid = sample_uuid
|
uuid = sample_uuid
|
||||||
|
|
||||||
extension_path = os.path.join(os.path.expanduser('~/.local'), 'share', 'gnome-shell', 'extensions', uuid)
|
extension_path = os.path.join(os.path.expanduser('~/.local'), 'share', 'gnome-shell', 'extensions', uuid)
|
||||||
if os.path.exists(extension_path):
|
if os.path.exists(extension_path):
|
||||||
print "Extension path %r already exists" % (extension_path, )
|
print("Extension path %r already exists" % (extension_path, ))
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
os.makedirs(extension_path)
|
os.makedirs(extension_path)
|
||||||
meta = { 'name': name,
|
meta = { 'name': name,
|
||||||
@ -132,13 +132,13 @@ use an extension title clicktofocus@janedoe.example.com.'''
|
|||||||
f.write(json.write(meta) + '\n')
|
f.write(json.write(meta) + '\n')
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
for filename, contents in SAMPLE_EXTENSION_FILES.iteritems():
|
for filename, contents in SAMPLE_EXTENSION_FILES.items():
|
||||||
path = os.path.join(extension_path, filename)
|
path = os.path.join(extension_path, filename)
|
||||||
f = open(path, 'w')
|
f = open(path, 'w')
|
||||||
f.write(contents)
|
f.write(contents)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
print "Created extension in %r" % (extension_path, )
|
print("Created extension in %r" % (extension_path, ))
|
||||||
extensionjs_path = os.path.join(extension_path, 'extension.js')
|
extensionjs_path = os.path.join(extension_path, 'extension.js')
|
||||||
subprocess.Popen(['xdg-open', extensionjs_path])
|
subprocess.Popen(['xdg-open', extensionjs_path])
|
||||||
|
|
||||||
@ -149,19 +149,19 @@ def enable_extension(uuid):
|
|||||||
extensions = settings.get_strv(ENABLED_EXTENSIONS_KEY)
|
extensions = settings.get_strv(ENABLED_EXTENSIONS_KEY)
|
||||||
|
|
||||||
if uuid in extensions:
|
if uuid in extensions:
|
||||||
print >> sys.stderr, "%r is already enabled." % (uuid,)
|
print("%r is already enabled." % (uuid,), file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
extensions.append(uuid)
|
extensions.append(uuid)
|
||||||
settings.set_strv(ENABLED_EXTENSIONS_KEY, extensions)
|
settings.set_strv(ENABLED_EXTENSIONS_KEY, extensions)
|
||||||
print >> sys.stderr, "%r is now enabled." % (uuid,)
|
print("%r is now enabled." % (uuid,), file=sys.stderr)
|
||||||
|
|
||||||
def disable_extension(uuid):
|
def disable_extension(uuid):
|
||||||
settings = Gio.Settings(schema='org.gnome.shell')
|
settings = Gio.Settings(schema='org.gnome.shell')
|
||||||
extensions = settings.get_strv(ENABLED_EXTENSIONS_KEY)
|
extensions = settings.get_strv(ENABLED_EXTENSIONS_KEY)
|
||||||
|
|
||||||
if uuid not in extensions:
|
if uuid not in extensions:
|
||||||
print >> sys.stderr, "%r is not enabled or installed." % (uuid,)
|
print("%r is not enabled or installed." % (uuid,), file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Use a while loop here to remove *all* mentions instances
|
# Use a while loop here to remove *all* mentions instances
|
||||||
@ -170,7 +170,7 @@ def disable_extension(uuid):
|
|||||||
extensions.remove(uuid)
|
extensions.remove(uuid)
|
||||||
|
|
||||||
settings.set_strv(ENABLED_EXTENSIONS_KEY, extensions)
|
settings.set_strv(ENABLED_EXTENSIONS_KEY, extensions)
|
||||||
print >> sys.stderr, "%r is now disabled." % (uuid,)
|
print("%r is now disabled." % (uuid,), file=sys.stderr)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = optparse.OptionParser()
|
parser = optparse.OptionParser()
|
||||||
|
@ -14,15 +14,14 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import base64
|
import base64
|
||||||
from ConfigParser import RawConfigParser
|
from configparser import RawConfigParser
|
||||||
import hashlib
|
import hashlib
|
||||||
import hmac
|
import hmac
|
||||||
import httplib
|
from http import client
|
||||||
import urlparse
|
from urllib import parse
|
||||||
import urllib
|
|
||||||
|
|
||||||
def show_version(option, opt_str, value, parser):
|
def show_version(option, opt_str, value, parser):
|
||||||
print "GNOME Shell Performance Test @VERSION@"
|
print("GNOME Shell Performance Test @VERSION@")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
def wait_for_dbus_name(wait_name):
|
def wait_for_dbus_name(wait_name):
|
||||||
@ -41,7 +40,7 @@ def wait_for_dbus_name(wait_name):
|
|||||||
None)
|
None)
|
||||||
|
|
||||||
def on_timeout():
|
def on_timeout():
|
||||||
print "\nFailed to start %s: timed out" % (wait_name,)
|
print("\nFailed to start %s: timed out" % (wait_name,))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
GLib.timeout_add_seconds(7, on_timeout)
|
GLib.timeout_add_seconds(7, on_timeout)
|
||||||
|
|
||||||
@ -131,15 +130,15 @@ def upload_performance_report(report_text):
|
|||||||
base_url = config.get('upload', 'url')
|
base_url = config.get('upload', 'url')
|
||||||
system_name = config.get('upload', 'name')
|
system_name = config.get('upload', 'name')
|
||||||
secret_key = config.get('upload', 'key')
|
secret_key = config.get('upload', 'key')
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
print "Can't read upload configuration from %s: %s" % (config_file, str(e))
|
print("Can't read upload configuration from %s: %s" % (config_file, str(e)))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Determine host, port and upload URL from provided data, we're
|
# Determine host, port and upload URL from provided data, we're
|
||||||
# a bit extra-careful about normalization since the URL is part
|
# a bit extra-careful about normalization since the URL is part
|
||||||
# of the signature.
|
# of the signature.
|
||||||
|
|
||||||
split = urlparse.urlsplit(base_url)
|
split = parse.urlsplit(base_url)
|
||||||
scheme = split[0].lower()
|
scheme = split[0].lower()
|
||||||
netloc = split[1]
|
netloc = split[1]
|
||||||
base_path = split[2]
|
base_path = split[2]
|
||||||
@ -151,7 +150,7 @@ def upload_performance_report(report_text):
|
|||||||
host, port = m.group(1), None
|
host, port = m.group(1), None
|
||||||
|
|
||||||
if scheme != "http":
|
if scheme != "http":
|
||||||
print "'%s' is not a HTTP URL" % base_url
|
print("'%s' is not a HTTP URL" % base_url)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if port is None:
|
if port is None:
|
||||||
@ -166,7 +165,7 @@ def upload_performance_report(report_text):
|
|||||||
normalized_base = "%s://%s:%d%s" % (scheme, host, port, base_path)
|
normalized_base = "%s://%s:%d%s" % (scheme, host, port, base_path)
|
||||||
|
|
||||||
upload_url = normalized_base + '/system/%s/upload' % system_name
|
upload_url = normalized_base + '/system/%s/upload' % system_name
|
||||||
upload_path = urlparse.urlsplit(upload_url)[2] # path portion
|
upload_path = parse.urlsplit(upload_url)[2] # path portion
|
||||||
|
|
||||||
# Create signature based on upload URL and the report data
|
# Create signature based on upload URL and the report data
|
||||||
|
|
||||||
@ -174,7 +173,7 @@ def upload_performance_report(report_text):
|
|||||||
h = hmac.new(secret_key, digestmod=hashlib.sha1)
|
h = hmac.new(secret_key, digestmod=hashlib.sha1)
|
||||||
h.update(signature_data)
|
h.update(signature_data)
|
||||||
h.update(report_text)
|
h.update(report_text)
|
||||||
signature = urllib.quote(base64.b64encode(h.digest()), "~")
|
signature = parse.quote(base64.b64encode(h.digest()), "~")
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
'User-Agent': 'gnome-shell-performance-tool/@VERSION@',
|
'User-Agent': 'gnome-shell-performance-tool/@VERSION@',
|
||||||
@ -182,15 +181,15 @@ def upload_performance_report(report_text):
|
|||||||
'X-Shell-Signature': 'HMAC-SHA1 ' + signature
|
'X-Shell-Signature': 'HMAC-SHA1 ' + signature
|
||||||
};
|
};
|
||||||
|
|
||||||
connection = httplib.HTTPConnection(host, port)
|
connection = client.HTTPConnection(host, port)
|
||||||
connection.request('POST', upload_path, report_text, headers)
|
connection.request('POST', upload_path, report_text, headers)
|
||||||
response = connection.getresponse()
|
response = connection.getresponse()
|
||||||
|
|
||||||
if response.status == 200:
|
if response.status == 200:
|
||||||
print "Performance report upload succeeded"
|
print("Performance report upload succeeded")
|
||||||
else:
|
else:
|
||||||
print "Performance report upload failed with status %d" % response.status
|
print("Performance report upload failed with status %d" % response.status)
|
||||||
print response.read()
|
print(response.read())
|
||||||
|
|
||||||
def gnome_hwtest_log(*args):
|
def gnome_hwtest_log(*args):
|
||||||
command = ['gnome-hwtest-log', '-t', 'gnome-shell-perf-tool']
|
command = ['gnome-hwtest-log', '-t', 'gnome-shell-perf-tool']
|
||||||
@ -207,7 +206,7 @@ def run_performance_test():
|
|||||||
|
|
||||||
start_perf_helper()
|
start_perf_helper()
|
||||||
|
|
||||||
for i in xrange(0, iters):
|
for i in range(0, iters):
|
||||||
# We create an empty temporary file that the shell will overwrite
|
# We create an empty temporary file that the shell will overwrite
|
||||||
# with the contents.
|
# with the contents.
|
||||||
handle, output_file = tempfile.mkstemp(".json", "gnome-shell-perf.")
|
handle, output_file = tempfile.mkstemp(".json", "gnome-shell-perf.")
|
||||||
@ -306,12 +305,12 @@ def run_performance_test():
|
|||||||
gnome_hwtest_log('--finished')
|
gnome_hwtest_log('--finished')
|
||||||
else:
|
else:
|
||||||
# Write a human readable summary
|
# Write a human readable summary
|
||||||
print '------------------------------------------------------------';
|
print('------------------------------------------------------------')
|
||||||
for metric in sorted(metric_summaries.keys()):
|
for metric in sorted(metric_summaries.keys()):
|
||||||
summary = metric_summaries[metric]
|
summary = metric_summaries[metric]
|
||||||
print "#", summary['description']
|
print("#", summary['description'])
|
||||||
print metric, ", ".join((str(x) for x in summary['values']))
|
print(metric, ", ".join((str(x) for x in summary['values'])))
|
||||||
print '------------------------------------------------------------';
|
print('------------------------------------------------------------')
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python3
|
||||||
#
|
#
|
||||||
# This is a simple script that we use to check for files in git
|
# This is a simple script that we use to check for files in git
|
||||||
# and not in the distribution. It was previously written in shell
|
# and not in the distribution. It was previously written in shell
|
||||||
@ -16,10 +16,10 @@ os.chdir(srcdir)
|
|||||||
|
|
||||||
status=0
|
status=0
|
||||||
for f in subprocess.Popen(["git", "ls-files"], stdout=subprocess.PIPE).stdout:
|
for f in subprocess.Popen(["git", "ls-files"], stdout=subprocess.PIPE).stdout:
|
||||||
f = f.strip()
|
f = f.decode('utf-8').strip()
|
||||||
if (not os.path.exists(os.path.join(distdir, f)) and
|
if (not os.path.exists(os.path.join(distdir, f)) and
|
||||||
not any((fnmatch.fnmatch(f, p) for p in excludes))):
|
not any((fnmatch.fnmatch(f, p) for p in excludes))):
|
||||||
print "File missing from distribution:", f
|
print("File missing from distribution:", f)
|
||||||
status=1
|
status=1
|
||||||
|
|
||||||
sys.exit(status)
|
sys.exit(status)
|
||||||
|
Loading…
Reference in New Issue
Block a user