/usr/lib/python3/dist-packages/softwarecenter_aptd_plugins/add_license_key_plugin.py is in software-center-aptdaemon-plugins 0.1.6build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Provides plugins for AptDaemon"""
# Copyright (C) 2011 Canonical Ltd.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
__author__ = "Sebastian Heinlein <devel@glatzor.de>"
import apt_pkg
import os
import subprocess
import time
from gi.repository import GLib
from aptdaemon.errors import TransactionFailed
from aptdaemon.enums import ERROR_LICENSE_KEY_DOWNLOAD_FAILED
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
|