MythTV master
getLink.py
Go to the documentation of this file.
1# -*- coding: utf-8 -*-
2
3
4
5# smolt - Fedora hardware profiler
6#
7# Copyright (C) 2008 Yaakov M. Nemoy <loupgaroublond@gmail.com>
8# Copyright (C) 2008 Chris Lamb <chris@chris-lamb.co.uk>
9#
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation; either version 2 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, write to the Free Software
22# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
23
24import sys
25from optparse import OptionParser
26import requests
27import json
28
29sys.path.append('/usr/share/smolt/client')
30
31from i18n import _
32import smolt
33from smolt import debug
34from smolt import error
35from scan import scan
36
37parser = OptionParser(version = smolt.smoltProtocol)
38
39parser.add_option('-d', '--debug',
40 dest = 'DEBUG',
41 default = False,
42 action = 'store_true',
43 help = _('enable debug information'))
44parser.add_option('-s', '--server',
45 dest = 'smoonURL',
46 default = smolt.smoonURL,
47 metavar = 'smoonURL',
48 help = _('specify the URL of the server (default "%default")'))
49parser.add_option('-u', '--useragent', '--user_agent',
50 dest = 'user_agent',
51 default = smolt.user_agent,
52 metavar = 'USERAGENT',
53 help = _('specify HTTP user agent (default "%default")'))
54parser.add_option('-t', '--timeout',
55 dest = 'timeout',
56 type = 'float',
57 default = smolt.timeout,
58 help = _('specify HTTP timeout in seconds (default %default seconds)'))
59parser.add_option('--uuidFile',
60 dest = 'uuidFile',
61 default = smolt.hw_uuid_file,
62 help = _('specify which uuid to use, useful for debugging and testing mostly.'))
63
64(opts, args) = parser.parse_args()
65
66def main():
67 from gate import create_default_gate
68 profile = smolt.create_profile(create_default_gate(), smolt.read_uuid())
69 session = requests.Session()
70 session.headers.update({'USER-AGENT': opts.user_agent})
71
72 o = session.post(opts.smoonURL + '', timeout=opts.timeout)
73
74 exceptions = (requests.exceptions.HTTPError,
75 requests.exceptions.URLRequired,
76 requests.exceptions.Timeout,
77 requests.exceptions.ConnectionError,
78 requests.exceptions.InvalidURL)
79
80 #first find out the server desired protocol
81 try:
82 #fli is a file like item
83 pub_uuid_fli = opts.smoonURL + 'client/pub_uuid?uuid=%s' % profile.host.UUID
84 pub_uuid_fli = session.get(pub_uuid_fli, timeout=opts.timeout)
85 except exceptions as e:
86 error(_('Error contacting Server: %s') % e)
87 return 1
88 try:
89 pub_uuid_obj = pub_uuid_fli.json()
90 try:
91 print(_('To view your profile visit: %s') % smolt.get_profile_link(opts.smoonURL, pub_uuid_obj["pub_uuid"]))
92 except ValueError as e:
93 error(_('Something went wrong fetching the public UUID'))
94 finally:
95 session.close()
96
97if __name__ == '__main__':
98 main()
def create_default_gate()
Definition: gate.py:83
def error(message)
Definition: smolt.py:409
static void print(const QList< uint > &raw_minimas, const QList< uint > &raw_maximas, const QList< float > &minimas, const QList< float > &maximas)