[gnome-shell] gnome-shell.in: Move extension creation to gnome-shell-extension-tool



commit 3916b5973d5c08b9c7ac22f4e11845b0c9561eb5
Author: Colin Walters <walters verbum org>
Date:   Thu Feb 17 14:43:48 2011 -0500

    gnome-shell.in: Move extension creation to gnome-shell-extension-tool
    
    https://bugzilla.gnome.org/show_bug.cgi?id=642084

 src/Makefile.am                   |   21 +++++--
 src/gnome-shell-extension-tool.in |  112 +++++++++++++++++++++++++++++++++++++
 src/gnome-shell.in                |   91 ------------------------------
 3 files changed, 126 insertions(+), 98 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 71cb018..170913b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -8,20 +8,27 @@ noinst_PROGRAMS =
 
 .AUTOPARALLEL:
 
-bin_SCRIPTS = gnome-shell
+generated_bin_scripts = gnome-shell gnome-shell-extension-tool
 
-gnome-shell: gnome-shell.in
-	$(AM_V_GEN) sed -e "s|@MUTTER_BIN_DIR[ ]|$(MUTTER_BIN_DIR)|" \
+bin_SCRIPTS = $(generated_bin_scripts)
+
+generated_script_substitutions = -e "s|@MUTTER_BIN_DIR[ ]|$(MUTTER_BIN_DIR)|" \
 	    -e "s|@datadir[ ]|$(datadir)|" \
 	    -e "s|@libexecdir[ ]|$(libexecdir)|" \
 	    -e "s|@libdir[ ]|$(libdir)|" \
 	    -e "s|@pkgdatadir[ ]|$(pkgdatadir)|" \
 	    -e "s|@PYTHON[ ]|$(PYTHON)|" \
 	    -e "s|@VERSION[ ]|$(VERSION)|" \
-	    -e "s|@sysconfdir[ ]|$(sysconfdir)|" \
-	    $< > $@ && chmod a+x $@
-CLEANFILES += gnome-shell
-EXTRA_DIST += gnome-shell.in
+	    -e "s|@sysconfdir[ ]|$(sysconfdir)|"
+
+gnome-shell: gnome-shell.in
+	$(AM_V_GEN) sed $(generated_script_substitutions) $< > $  tmp && mv $  tmp $@ && chmod a+x $@
+
+gnome-shell-extension-tool: gnome-shell-extension-tool.in
+	$(AM_V_GEN) sed $(generated_script_substitutions) $< > $  tmp && mv $  tmp $@ && chmod a+x $@
+
+CLEANFILES += $(generated_bin_scripts)
+EXTRA_DIST += $(generated_bin_scripts:=.in)
 
 include Makefile-gdmuser.am
 include Makefile-st.am
diff --git a/src/gnome-shell-extension-tool.in b/src/gnome-shell-extension-tool.in
new file mode 100644
index 0000000..578fe2d
--- /dev/null
+++ b/src/gnome-shell-extension-tool.in
@@ -0,0 +1,112 @@
+#! PYTHON@
+# -*- mode: Python; indent-tabs-mode: nil; -*-
+
+import os
+import re
+import subprocess
+import sys
+import optparse
+import tempfile
+try:
+    import json
+except ImportError:
+    try:
+        import simplejson as json
+    except ImportError:
+        print 'The Python simplejson module is required'
+        sys.exit(1)
+
+parser = optparse.OptionParser()
+parser.add_option("", "--create-extension", action="store_true",
+                  help="Create a new GNOME Shell extension")
+
+options, args = parser.parse_args()
+
+if args:
+    parser.print_usage()
+    sys.exit(1)
+
+if options.create_extension:
+    print
+    print '''Name should be a very short (ideally descriptive) string.
+Examples are: "Click To Focus",  "Adblock", "Shell Window Shrinker".
+'''
+    name = raw_input('Name: ').strip()
+    print
+    print '''Description is a single-sentence explanation of what your extension does.
+Examples are: "Make windows visible on click", "Block advertisement popups"
+              "Animate windows shrinking on minimize"
+'''
+    description = raw_input('Description: ').strip()
+    underifier = re.compile('[^A-Za-z]')
+    sample_uuid = underifier.sub('_', name)
+    # TODO use evolution data server
+    hostname = subprocess.Popen(['hostname'], stdout=subprocess.PIPE).communicate()[0].strip()
+    sample_uuid = sample_uuid + '@' + hostname
+
+    print
+    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
+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
+use an extension title clicktofocus janedoe example com '''
+    uuid = raw_input('Uuid [%s]: ' % (sample_uuid, )).strip()
+    if uuid == '':
+        uuid = sample_uuid
+
+    extension_path = os.path.join(os.path.expanduser('~/.local'), 'share', 'gnome-shell', 'extensions', uuid)
+    if os.path.exists(extension_path):
+        print "Extension path %r already exists" % (extension_path, )
+        sys.exit(0)
+    os.makedirs(extension_path)
+    meta = { 'name': name,
+             'description': description,
+             'uuid': uuid,
+             'shell-version': ['@VERSION@'] }
+    f = open(os.path.join(extension_path, 'metadata.json'), 'w')
+    try:
+        json.dump(meta, f)
+    except AttributeError:
+        # For Python versions older than 2.6, try using the json-py module
+        f.write(json.write(meta) + '\n')
+    f.close()
+
+    extensionjs_path = os.path.join(extension_path, 'extension.js')
+    f = open(extensionjs_path, 'w')
+    f.write('''// Sample extension code, makes clicking on the panel show a message
+const St = imports.gi.St;
+const Mainloop = imports.mainloop;
+
+const Main = imports.ui.main;
+
+function _showHello() {
+    let text = new St.Label({ style_class: 'helloworld-label', text: "Hello, world!" });
+    let monitor = global.get_primary_monitor();
+    global.stage.add_actor(text);
+    text.set_position(Math.floor (monitor.width / 2 - text.width / 2), Math.floor(monitor.height / 2 - text.height / 2));
+    Mainloop.timeout_add(3000, function () { text.destroy(); });
+}
+
+// Put your extension initialization code here
+function main() {
+    Main.panel.actor.reactive = true;
+    Main.panel.actor.connect('button-release-event', _showHello);
+}
+''')
+    f.close()
+
+    f = open(os.path.join(extension_path, 'stylesheet.css'), 'w')
+    f.write('''/* Example stylesheet */
+.helloworld-label {
+    font-size: 36px;
+    font-weight: bold;
+    color: #ffffff;
+    background-color: rgba(10,10,10,0.7);
+    border-radius: 5px;
+}
+''')
+    f.close()
+
+    print "Created extension in %r" % (extension_path, )
+    subprocess.Popen(['gnome-open', extensionjs_path])
+    sys.exit(0)
diff --git a/src/gnome-shell.in b/src/gnome-shell.in
index e748ac6..a187588 100755
--- a/src/gnome-shell.in
+++ b/src/gnome-shell.in
@@ -563,8 +563,6 @@ parser.add_option("", "--perf-upload", action="store_true",
 		  help="Upload performance report to server")
 parser.add_option("", "--eval-file", metavar="EVAL_FILE",
                   help="Evaluate the contents of the given JavaScript file")
-parser.add_option("", "--create-extension", action="store_true",
-                  help="Create a new GNOME Shell extension")
 parser.add_option("", "--version", action="callback", callback=show_version,
                   help="Display version and exit")
 
@@ -574,99 +572,10 @@ if args:
     parser.print_usage()
     sys.exit(1)
 
-if options.create_extension and json is None:
-    print 'The Python simplejson module is required to create a new GNOME Shell extension'
-    sys.exit(1)
-
 if options.perf and json is None:
     print 'The Python simplejson module is required for performance tests'
     sys.exit(1)
 
-if options.create_extension:
-    print
-    print '''Name should be a very short (ideally descriptive) string.
-Examples are: "Click To Focus",  "Adblock", "Shell Window Shrinker".
-'''
-    name = raw_input('Name: ').strip()
-    print
-    print '''Description is a single-sentence explanation of what your extension does.
-Examples are: "Make windows visible on click", "Block advertisement popups"
-              "Animate windows shrinking on minimize"
-'''
-    description = raw_input('Description: ').strip()
-    underifier = re.compile('[^A-Za-z]')
-    sample_uuid = underifier.sub('_', name)
-    # TODO use evolution data server
-    hostname = subprocess.Popen(['hostname'], stdout=subprocess.PIPE).communicate()[0].strip()
-    sample_uuid = sample_uuid + '@' + hostname
-
-    print
-    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
-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
-use an extension title clicktofocus janedoe example com '''
-    uuid = raw_input('Uuid [%s]: ' % (sample_uuid, )).strip()
-    if uuid == '':
-        uuid = sample_uuid
-
-    extension_path = os.path.join(os.path.expanduser('~/.local'), 'share', 'gnome-shell', 'extensions', uuid)
-    if os.path.exists(extension_path):
-        print "Extension path %r already exists" % (extension_path, )
-        sys.exit(0)
-    os.makedirs(extension_path)
-    meta = { 'name': name,
-             'description': description,
-             'uuid': uuid,
-             'shell-version': ['@VERSION@'] }
-    f = open(os.path.join(extension_path, 'metadata.json'), 'w')
-    try:
-        json.dump(meta, f)
-    except AttributeError:
-        # For Python versions older than 2.6, try using the json-py module
-        f.write(json.write(meta) + '\n')
-    f.close()
-
-    extensionjs_path = os.path.join(extension_path, 'extension.js')
-    f = open(extensionjs_path, 'w')
-    f.write('''// Sample extension code, makes clicking on the panel show a message
-const St = imports.gi.St;
-const Mainloop = imports.mainloop;
-
-const Main = imports.ui.main;
-
-function _showHello() {
-    let text = new St.Label({ style_class: 'helloworld-label', text: "Hello, world!" });
-    let monitor = global.get_primary_monitor();
-    global.stage.add_actor(text);
-    text.set_position(Math.floor (monitor.width / 2 - text.width / 2), Math.floor(monitor.height / 2 - text.height / 2));
-    Mainloop.timeout_add(3000, function () { text.destroy(); });
-}
-
-// Put your extension initialization code here
-function main() {
-    Main.panel.actor.reactive = true;
-    Main.panel.actor.connect('button-release-event', _showHello);
-}
-''')
-    f.close()
-
-    f = open(os.path.join(extension_path, 'stylesheet.css'), 'w')
-    f.write('''/* Example stylesheet */
-.helloworld-label {
-    font-size: 36px;
-    font-weight: bold;
-    color: #ffffff;
-    background-color: rgba(10,10,10,0.7);
-    border-radius: 5px;
-}
-''')
-    f.close()
-
-    print "Created extension in %r" % (extension_path, )
-    subprocess.Popen(['gnome-open', extensionjs_path])
-    sys.exit(0)
-
 # Handle ssh logins
 if 'DISPLAY' not in os.environ:
     running_env = get_running_session_environs()



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]