2
# Copyright (C) 2011 Canonical
7
# This program is free software; you can redistribute it and/or modify it under
8
# the terms of the GNU General Public License as published by the Free Software
9
# Foundation; version 3.
11
# This program is distributed in the hope that it will be useful, but WITHOUT
12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16
# You should have received a copy of the GNU General Public License along with
17
# this program; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
from gi.repository import GObject
28
# useful for debugging
29
if "SOFTWARE_CENTER_DEBUG_HTTP" in os.environ:
31
httplib2.debuglevel = 1
33
import piston_mini_client.auth
35
from softwarecenter.paths import SOFTWARE_CENTER_CACHE_DIR
36
from softwarecenter.backend.piston.ubuntusso_pristine import (
38
from piston_get_scagent_available_apps import SSOLoginHelper
40
# patch default_service_root to the one we use
41
from softwarecenter.enums import SSO_LOGIN_HOST
42
UbuntuSsoAPI.default_service_root = SSO_LOGIN_HOST+"/api/1.0"
44
from gettext import gettext as _
46
LOG = logging.getLogger(__name__)
48
if __name__ == "__main__":
52
parser = argparse.ArgumentParser(description="Helper for recommender-api")
53
parser.add_argument("--debug", action="store_true", default=False,
54
help="enable debug output")
55
parser.add_argument("--ignore-cache", action="store_true", default=False,
56
help="force ignore cache")
57
parser.add_argument("--parent-xid", default=0,
58
help="xid of the parent window")
60
subparser = parser.add_subparsers(title="Commands")
62
command = subparser.add_parser("whoami")
63
command.set_defaults(command="whoami")
65
args = parser.parse_args()
68
LOG.setLevel(logging.DEBUG)
73
cachedir = os.path.join(SOFTWARE_CENTER_CACHE_DIR, "uraclient")
75
# all calls are authenticated
76
helper = SSOLoginHelper(args.parent_xid)
77
token = helper.get_oauth_token_sync()
79
auth = piston_mini_client.auth.OAuthAuthorizer(token["token"],
80
token["token_secret"],
81
token["consumer_key"],
82
token["consumer_secret"])
83
urclient = UbuntuSsoAPI(cachedir=cachedir, auth=auth)
87
f = getattr(urclient, args.command)
91
LOG.exception("urclient_apps")
94
# print to stdout where its consumed by the parent
95
if piston_reply is not None:
97
print pickle.dumps(piston_reply)
99
# this can happen if the parent gets killed, no need to trigger