[gnome-builder: 120/139] rustup: port to libide-gui



commit be816900852d5954ba91074dda4fb2a50025b32d
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jan 9 17:37:37 2019 -0800

    rustup: port to libide-gui

 src/plugins/rustup/meson.build          |  4 +--
 src/plugins/rustup/rustup.gresource.xml |  2 +-
 src/plugins/rustup/rustup.plugin        | 12 +++++----
 src/plugins/rustup/rustup.sh            | 39 ++++++++++++++++++++++-----
 src/plugins/rustup/rustup_plugin.py     | 48 ++++++++++++++-------------------
 5 files changed, 62 insertions(+), 43 deletions(-)
---
diff --git a/src/plugins/rustup/meson.build b/src/plugins/rustup/meson.build
index bb4e754de..904296102 100644
--- a/src/plugins/rustup/meson.build
+++ b/src/plugins/rustup/meson.build
@@ -1,4 +1,4 @@
-if get_option('with_rustup')
+if get_option('plugin_rustup')
 
 rustup_resources = gnome.compile_resources(
   'rustup_plugin',
@@ -13,7 +13,7 @@ install_data('rustup_plugin.py', install_dir: plugindir)
 configure_file(
           input: 'rustup.plugin',
          output: 'rustup.plugin',
-           copy: true,
+  configuration: config_h,
         install: true,
     install_dir: plugindir,
 )
diff --git a/src/plugins/rustup/rustup.gresource.xml b/src/plugins/rustup/rustup.gresource.xml
index cf7bc4003..e3940b5f3 100644
--- a/src/plugins/rustup/rustup.gresource.xml
+++ b/src/plugins/rustup/rustup.gresource.xml
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <gresources>
-  <gresource prefix="/org/gnome/builder/plugins/rustup_plugin">
+  <gresource prefix="/plugins/rustup_plugin">
     <file>rustup.sh</file>
   </gresource>
 </gresources>
diff --git a/src/plugins/rustup/rustup.plugin b/src/plugins/rustup/rustup.plugin
index 82758e43e..c9d94ef59 100644
--- a/src/plugins/rustup/rustup.plugin
+++ b/src/plugins/rustup/rustup.plugin
@@ -1,8 +1,10 @@
 [Plugin]
-Module=rustup_plugin
-Name=RustUp
-Loader=python3
-Description=Helps keep your rust installation up to date!
 Authors=Christian Hergert <christian hergert me>, Georg Vienna <georg vienna himbarsoft com>
-Copyright=Copyright © 2017 Christian Hergert, Georg Vienna <georg vienna himbarsoft com>
 Builtin=true
+Copyright=Copyright © 2017 Christian Hergert, Georg Vienna <georg vienna himbarsoft com>
+Description=Helps keep your rust installation up to date!
+Loader=python3
+Module=rustup_plugin
+Name=RustUp
+X-Builder-ABI=@PACKAGE_ABI@
+X-Has-Resources=true
diff --git a/src/plugins/rustup/rustup.sh b/src/plugins/rustup/rustup.sh
index 7e089a1fb..7df218a9f 100755
--- a/src/plugins/rustup/rustup.sh
+++ b/src/plugins/rustup/rustup.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 # Copyright 2016 The Rust Project Developers. See the COPYRIGHT
 # file at the top-level directory of this distribution and at
 # http://rust-lang.org/COPYRIGHT.
@@ -9,8 +9,8 @@
 # option. This file may not be copied, modified, or distributed
 # except according to those terms.
 
-# This is just a little script that can be curled from the internet to
-# install rustup. It just does platform detection, curls the installer
+# This is just a little script that can be downloaded from the internet to
+# install rustup. It just does platform detection, downloads the installer
 # and runs it.
 
 set -u
@@ -41,8 +41,8 @@ EOF
 }
 
 main() {
+    downloader --check
     need_cmd uname
-    need_cmd curl
     need_cmd mktemp
     need_cmd chmod
     need_cmd mkdir
@@ -100,7 +100,7 @@ main() {
     fi
 
     ensure mkdir -p "$_dir"
-    ensure curl -sSfL "$_url" -o "$_file"
+    ensure downloader "$_url" "$_file"
     ensure chmod u+x "$_file"
     if [ ! -x "$_file" ]; then
         printf '%s\n' "Cannot execute $_file (likely because of mounting /tmp as noexec)." 1>&2
@@ -308,7 +308,7 @@ get_architecture() {
 
     # Detect armv7 but without the CPU features Rust needs in that build,
     # and fall back to arm.
-    # See https://github.com/rust-lang-nursery/rustup.rs/issues/587.
+    # See https://github.com/rust-lang/rustup.rs/issues/587.
     if [ $_ostype = "unknown-linux-gnueabihf" -a $_cputype = armv7 ]; then
         if ensure grep '^Features' /proc/cpuinfo | grep -q -v neon; then
             # At least one processor does not have NEON.
@@ -331,11 +331,16 @@ err() {
 }
 
 need_cmd() {
-    if ! command -v "$1" > /dev/null 2>&1
+    if ! check_cmd "$1"
     then err "need '$1' (command not found)"
     fi
 }
 
+check_cmd() {
+    command -v "$1" > /dev/null 2>&1
+    return $?
+}
+
 need_ok() {
     if [ $? != 0 ]; then err "$1"; fi
 }
@@ -359,4 +364,24 @@ ignore() {
     "$@"
 }
 
+# This wraps curl or wget. Try curl first, if not installed,
+# use wget instead.
+downloader() {
+    if check_cmd curl
+    then _dld=curl
+    elif check_cmd wget
+    then _dld=wget
+    else _dld='curl or wget' # to be used in error message of need_cmd
+    fi
+
+    if [ "$1" = --check ]
+    then need_cmd "$_dld"
+    elif [ "$_dld" = curl ]
+    then curl -sSfL "$1" -o "$2"
+    elif [ "$_dld" = wget ]
+    then wget "$1" -O "$2"
+    else err "Unknown downloader"   # should not reach here
+    fi
+}
+
 main "$@" || exit 1
diff --git a/src/plugins/rustup/rustup_plugin.py b/src/plugins/rustup/rustup_plugin.py
index c4c1d04fb..8b3157ac6 100644
--- a/src/plugins/rustup/rustup_plugin.py
+++ b/src/plugins/rustup/rustup_plugin.py
@@ -3,7 +3,7 @@
 #
 # __init__.py
 #
-# Copyright 2016-2019 Christian Hergert <chergert redhat com>
+# Copyright 2016 Christian Hergert <chergert redhat com>
 # Copyright 2017 Georg Vienna <georg vienna himbarsoft com>
 #
 # This program is free software: you can redistribute it and/or modify
@@ -20,16 +20,11 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
-import gi
 import os
 import re
 import pty
 import stat
 
-gi.require_version('Dazzle', '1.0')
-gi.require_version('Ide', '1.0')
-gi.require_version('Gtk', '3.0')
-
 from gi.repository import Dazzle
 from gi.repository import GLib
 from gi.repository import GObject
@@ -41,7 +36,7 @@ from gi.repository import Peas
 _ = Ide.gettext
 
 def get_resource(path):
-    full_path = os.path.join('/org/gnome/builder/plugins/rustup_plugin', path)
+    full_path = os.path.join('/plugins/rustup_plugin', path)
     return Gio.resources_lookup_data(full_path, 0).get_data()
 
 def get_module_data_path(name):
@@ -73,18 +68,14 @@ def looks_like_channel(channel):
 
 class RustUpWorkbenchAddin(GObject.Object, Ide.WorkbenchAddin):
     """
-    The RustUpWorkbenchAddin is a helper to handle open workbenches.
-    It manages the set of open workbenches stored in the application addin.
+    The RustUpWorkbenchAddin is a helper to handle open workspaces.
+    It manages the set of open workspaces stored in the application addin.
     """
-    def do_load(self, workbench):
-        RustupApplicationAddin.instance.add_workbench(workbench)
-        def unload(workbench, context):
-            RustupApplicationAddin.instance.workbenches.discard(workbench)
-        workbench.connect('unload', unload)
+    def do_workspace_added(self, workspace):
+        RustupApplicationAddin.instance.add_workspace(workspace)
 
-    def do_unload(self, workbench):
-        if RustupApplicationAddin.instance:
-            RustupApplicationAddin.instance.workbenches.discard(workbench)
+    def do_workspace_removed(self, workspace):
+        RustupApplicationAddin.instance.workspaces.discard(workspace)
 
 _NO_RUSTUP = _('Rustup not installed')
 
@@ -112,7 +103,7 @@ class RustupApplicationAddin(GObject.Object, Ide.ApplicationAddin):
 
     def do_load(self, application):
         RustupApplicationAddin.instance = self
-        self.workbenches = set()
+        self.workspaces = set()
         self.active_transfer = None
         self.has_rustup = False
         self.rustup_version = _NO_RUSTUP
@@ -210,27 +201,27 @@ class RustupApplicationAddin(GObject.Object, Ide.ApplicationAddin):
             pass
         self.emit('rustup_changed')
 
-    def add_workbench(self, workbench):
+    def add_workspace(self, workspace):
         # recheck if rustup was installed outside of gnome-builder
-        def is_active(workbench, active):
-            if workbench.is_active ():
+        def is_active(workspace, active):
+            if workspace.is_active ():
                 if self.active_transfer is None:
                     RustupApplicationAddin.instance.check_rustup()
-        workbench.connect('notify::is-active', is_active)
+        workspace.connect('notify::is-active', is_active)
         # call us if a transfer completes (could be the active_transfer)
-        transfer_manager = Gio.Application.get_default().get_transfer_manager()
+        transfer_manager = Ide.TransferManager.get_default()
         transfer_manager.connect('transfer-completed', self.transfer_completed)
         transfer_manager.connect('transfer-failed', self.transfer_failed)
-        self.workbenches.add(workbench)
+        self.workspaces.add(workspace)
 
     def transfer_completed(self, transfer_manager, transfer):
-        # reset the active transfer on completion, ensures that new workbenches dont get an old transfer
+        # reset the active transfer on completion, ensures that new workspaces dont get an old transfer
         if self.active_transfer == transfer:
             self.active_transfer = None
             self.notify('busy')
 
     def transfer_failed(self, transfer_manager, transfer, error):
-        # reset the active transfer on error, ensures that new workbenches dont get an old transfer
+        # reset the active transfer on error, ensures that new workspaces dont get an old transfer
         if self.active_transfer == transfer:
             self.active_transfer = None
             self.notify('busy')
@@ -238,7 +229,7 @@ class RustupApplicationAddin(GObject.Object, Ide.ApplicationAddin):
     def run_transfer(self, transfer):
         self.active_transfer = transfer
         self.notify('busy')
-        transfer_manager = Gio.Application.get_default().get_transfer_manager()
+        transfer_manager = Ide.TransferManager.get_default()
         transfer_manager.execute_async(transfer)
 
     def install(self):
@@ -390,7 +381,8 @@ class RustupInstaller(Ide.Transfer):
                         try:
                             self.props.progress = float(percent)/100
                         except Exception as te:
-                            print('_read_line_cb', self.state, line, te)
+                            if type(te) is not ValueError:
+                                print('_read_line_cb', self.state, line, te)
                 elif self.state == _STATE_DOWN_COMP or self.state == _STATE_SYNC_UPDATE or self.state == 
_STATE_CHECK_UPDATE_SELF  or self.state == _STATE_DOWN_UPDATE_SELF:
                     # the first progress can be empty, skip it
                     if length > 0:


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