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