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 
24 from __future__ import print_function
25 import sys
26 from optparse import OptionParser
27 import requests
28 import json
29 
30 sys.path.append('/usr/share/smolt/client')
31 
32 from i18n import _
33 import smolt
34 from smolt import debug
35 from smolt import error
36 from scan import scan
37 
38 parser = OptionParser(version = smolt.smoltProtocol)
39 
40 parser.add_option('-d', '--debug',
41  dest = 'DEBUG',
42  default = False,
43  action = 'store_true',
44  help = _('enable debug information'))
45 parser.add_option('-s', '--server',
46  dest = 'smoonURL',
47  default = smolt.smoonURL,
48  metavar = 'smoonURL',
49  help = _('specify the URL of the server (default "%default")'))
50 parser.add_option('-u', '--useragent', '--user_agent',
51  dest = 'user_agent',
52  default = smolt.user_agent,
53  metavar = 'USERAGENT',
54  help = _('specify HTTP user agent (default "%default")'))
55 parser.add_option('-t', '--timeout',
56  dest = 'timeout',
57  type = 'float',
58  default = smolt.timeout,
59  help = _('specify HTTP timeout in seconds (default %default seconds)'))
60 parser.add_option('--uuidFile',
61  dest = 'uuidFile',
62  default = smolt.hw_uuid_file,
63  help = _('specify which uuid to use, useful for debugging and testing mostly.'))
64 
65 (opts, args) = parser.parse_args()
66 
67 def main():
68  from gate import create_default_gate
69  profile = smolt.create_profile(create_default_gate(), smolt.read_uuid())
70  session = requests.Session()
71  session.headers.update({'USER-AGENT': opts.user_agent})
72 
73  o = session.post(opts.smoonURL + '', timeout=opts.timeout)
74 
75  exceptions = (requests.exceptions.HTTPError,
76  requests.exceptions.URLRequired,
77  requests.exceptions.Timeout,
78  requests.exceptions.ConnectionError,
79  requests.exceptions.InvalidURL)
80 
81  #first find out the server desired protocol
82  try:
83  #fli is a file like item
84  pub_uuid_fli = opts.smoonURL + 'client/pub_uuid?uuid=%s' % profile.host.UUID
85  pub_uuid_fli = session.get(pub_uuid_fli, timeout=opts.timeout)
86  except exceptions as e:
87  error(_('Error contacting Server: %s') % e)
88  return 1
89  try:
90  pub_uuid_obj = pub_uuid_fli.json()
91  try:
92  print(_('To view your profile visit: %s') % smolt.get_profile_link(opts.smoonURL, pub_uuid_obj["pub_uuid"]))
93  except ValueError as e:
94  error(_('Something went wrong fetching the public UUID'))
95  finally:
96  session.close()
97 
98 if __name__ == '__main__':
99  main()
def create_default_gate()
Definition: gate.py:83
static void print(const QList< uint > &raw_minimas, const QList< uint > &raw_maximas, const QList< float > &minimas, const QList< float > &maximas)
static void error(const char *str,...)
Definition: vbi.c:42