コード例 #1
0
def get_license_key(uid, pkg_name, json_token, server_name):
    """Return the license key and the path for the given package."""
    rootdir = apt_pkg.config["Dir"]
    license_key_helper = os.path.join(
        rootdir, "usr/share/software-center/ubuntu-license-key-helper")
    cmd = [license_key_helper, "--server", server_name, "--pkgname", pkg_name]
    proc = subprocess.Popen(
        cmd,
        stdin=subprocess.PIPE,
        stderr=subprocess.PIPE,
        stdout=subprocess.PIPE,
        preexec_fn=lambda: os.setuid(uid),
        close_fds=True,
        # this will give us str in py3 instead of bytes
        universal_newlines=True)
    # send json token to the process
    proc.stdin.write(json_token + "\n")
    # wait until it finishes
    while proc.poll() is None:
        while GLib.main_context_default().pending():
            GLib.main_context_default().iteration()
            time.sleep(0.05)

    if proc.returncode != 0:
        stderr = proc.stderr.read()
        raise TransactionFailed(ERROR_LICENSE_KEY_DOWNLOAD_FAILED, stderr)

    # get data from stdout
    license_key_path = proc.stdout.readline().strip()
    license_key = proc.stdout.read()

    return license_key, license_key_path
コード例 #2
0
 def on_error(self, error):
     if isinstance(error, NotAuthorizedError):
         # Silently ignore auth failures
         return
     elif not isinstance(error, TransactionFailed):
         # Catch internal errors of the client
         error = TransactionFailed(ERROR_UNKNOWN, str(error))
     dia = AptErrorDialog(error)
     dia.run()
     dia.hide()
     self.apt_cache = apt.Cache()
コード例 #3
0
    def _error_handler(self, error):
        try:
            raise error
        except NotAuthorizedError:
            # Silently ignore auth failures
            sys.exit(11)
            return
        except TransactionFailed:
            pass
        except Exception as error:
            error = TransactionFailed(ERROR_UNKNOWN, str(error))

        dia = AptErrorDialog(error)
        dia.run()
        sys.exit(10)