MythTV  master
deleteProfile.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 
3 # smolt - Fedora hardware profiler
4 #
5 # Copyright (C) 2007 Mike McGrath
6 # Copyright (C) 2009 Sebastian Pipping <sebastian@pipping.org>
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 import urlgrabber.grabber
24 from optparse import OptionParser
25 from urlparse import urljoin
26 
27 
28 def main():
29  sys.path.append('/usr/share/smolt/client')
30 
31  from i18n import _
32  import smolt
33  from smolt import error, debug, get_profile_link, PubUUIDError
34  from uuiddb import create_default_uuiddb
35 
36  def serverMessage(page):
37  for line in page.split("\n"):
38  if 'ServerMessage:' in line:
39  error(_('Server Message: "%s"') % line.split('ServerMessage: ')[1])
40  if 'Critical' in line:
41  sys.exit(3)
42 
43  parser = OptionParser(version = smolt.smoltProtocol)
44 
45  parser.add_option('-d', '--debug',
46  dest = 'DEBUG',
47  default = False,
48  action = 'store_true',
49  help = _('enable debug information'))
50  parser.add_option('-s', '--server',
51  dest = 'smoonURL',
52  default = smolt.smoonURL,
53  metavar = 'smoonURL',
54  help = _('specify the URL of the server (default "%default")'))
55  parser.add_option('-p', '--printOnly',
56  dest = 'printOnly',
57  default = False,
58  action = 'store_true',
59  help = _('print information only, do not send'))
60  parser.add_option('-u', '--useragent',
61  dest = 'user_agent',
62  default = smolt.user_agent,
63  metavar = 'USERAGENT',
64  help = _('specify HTTP user agent (default "%default")'))
65  parser.add_option('-t', '--timeout',
66  dest = 'timeout',
67  type = 'float',
68  default = smolt.timeout,
69  help = _('specify HTTP timeout in seconds (default %default seconds)'))
70  parser.add_option('--uuidFile',
71  dest = 'uuidFile',
72  default = smolt.hw_uuid_file,
73  help = _('specify which uuid to use, useful for debugging and testing mostly.'))
74 
75 
76  (opts, args) = parser.parse_args()
77 
78  smolt.DEBUG = opts.DEBUG
79  smolt.hw_uuid_file = opts.uuidFile
80 
81  grabber = urlgrabber.grabber.URLGrabber(user_agent=opts.user_agent, timeout=opts.timeout)
82 
83  uuid = smolt.read_uuid()
84  delHostString = 'uuid=%s' % uuid
85 
86  # Try retrieving current pub_uuid (from cache or remotely if necessary)
87  pub_uuid = None
88  try:
89  pub_uuid = smolt.read_pub_uuid(create_default_uuiddb(), uuid, silent=True)
90  except PubUUIDError:
91  pass
92 
93 
94  try:
95  o=grabber.urlopen(urljoin(opts.smoonURL + '/', '/client/delete'), data=delHostString, http_headers=(
96  ('Content-length', '%i' % len(delHostString)),
97  ('Content-type', 'application/x-www-form-urlencoded')))
98  except urlgrabber.grabber.URLGrabError, e:
99  sys.stderr.write(_('Error contacting Server:'))
100  sys.stderr.write(str(e))
101  sys.stderr.write('\n')
102  sys.exit(1)
103  else:
104  serverMessage(o.read())
105  o.close()
106 
107  if pub_uuid is None:
108  profile_url = urljoin(opts.smoonURL + '/', '/client/show?%s' % delHostString)
109  else:
110  profile_url = get_profile_link(opts.smoonURL, pub_uuid)
111  print _('Profile removed, please verify at'), profile_url
112 
113 
114 if __name__ == '__main__':
115  main()
def serverMessage(page)
Definition: smolt.py:379
static void error(const char *str,...)
Definition: vbi.c:42
def create_default_uuiddb()
Definition: uuiddb.py:66
def get_profile_link(smoonURL, pub_uuid)
This is another.
Definition: smolt.py:1261