MythTV  master
deleteProfile.py
Go to the documentation of this file.
1 #!/usr/bin/python3
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 from __future__ import print_function
23 from builtins import str
24 import sys
25 import requests
26 from optparse import OptionParser
27 
28 
29 def main():
30  sys.path.append('/usr/share/smolt/client')
31 
32  from i18n import _
33  import smolt
34  from smolt import error, debug, get_profile_link, PubUUIDError
35  from uuiddb import create_default_uuiddb
36 
37  def serverMessage(page):
38  for line in page.split("\n"):
39  if 'ServerMessage:' in line:
40  error(_('Server Message: "%s"' % line.split('ServerMessage: ')[1]))
41  if 'Critical' in line:
42  sys.exit(3)
43 
44  parser = OptionParser(version = smolt.smoltProtocol)
45 
46  parser.add_option('-d', '--debug',
47  dest = 'DEBUG',
48  default = False,
49  action = 'store_true',
50  help = _('enable debug information'))
51  parser.add_option('-s', '--server',
52  dest = 'smoonURL',
53  default = smolt.smoonURL,
54  metavar = 'smoonURL',
55  help = _('specify the URL of the server (default "%default")'))
56  parser.add_option('-p', '--printOnly',
57  dest = 'printOnly',
58  default = False,
59  action = 'store_true',
60  help = _('print information only, do not send'))
61  parser.add_option('-u', '--useragent',
62  dest = 'user_agent',
63  default = smolt.user_agent,
64  metavar = 'USERAGENT',
65  help = _('specify HTTP user agent (default "%default")'))
66  parser.add_option('-t', '--timeout',
67  dest = 'timeout',
68  type = 'float',
69  default = smolt.timeout,
70  help = _('specify HTTP timeout in seconds (default %default seconds)'))
71  parser.add_option('--uuidFile',
72  dest = 'uuidFile',
73  default = smolt.hw_uuid_file,
74  help = _('specify which uuid to use, useful for debugging and testing mostly.'))
75 
76 
77  (opts, args) = parser.parse_args()
78 
79  smolt.DEBUG = opts.DEBUG
80  smolt.hw_uuid_file = opts.uuidFile
81 
82  uuid = smolt.read_uuid()
83  delHostString = 'uuid=%s' % uuid
84 
85  session = requests.Session()
86  session.headers.update({'USER-AGENT': opts.user_agent})
87  session.headers.update({'Content-type': 'application/x-www-form-urlencoded'})
88  session.headers.update({'Content-length': '%i' % len(delHostString)})
89 
90  # Try retrieving current pub_uuid (from cache or remotely if necessary)
91  pub_uuid = None
92  try:
93  pub_uuid = smolt.read_pub_uuid(create_default_uuiddb(), uuid, silent=True)
94  except PubUUIDError:
95  pass
96 
97  exceptions = (requests.exceptions.HTTPError,
98  requests.exceptions.URLRequired,
99  requests.exceptions.Timeout,
100  requests.exceptions.ConnectionError,
101  requests.exceptions.InvalidURL)
102 
103  try:
104  o = session.post(opts.smoonURL + 'client/delete', data=delHostString,
105  timeout=opts.timeout)
106  except exceptions as e:
107  sys.stderr.write(_('Error contacting Server:'))
108  sys.stderr.write(str(e))
109  sys.stderr.write('\n')
110  sys.exit(1)
111  else:
112  serverMessage(o.text)
113  session.close()
114 
115  if pub_uuid is None:
116  profile_url = opts.smoonURL + 'client/show?%s' % delHostString
117  else:
118  profile_url = get_profile_link(opts.smoonURL, pub_uuid)
119  print((_('Profile removed, please verify at'), profile_url))
120 
121 
122 if __name__ == '__main__':
123  main()
error
static void error(const char *str,...)
Definition: vbi.cpp:37
hardwareprofile.uuiddb.create_default_uuiddb
def create_default_uuiddb()
Definition: uuiddb.py:67
hardwareprofile.deleteProfile.main
def main()
Definition: deleteProfile.py:29
hardwareprofile.i18n._
_
Definition: i18n.py:44
print
static void print(const QList< uint > &raw_minimas, const QList< uint > &raw_maximas, const QList< float > &minimas, const QList< float > &maximas)
Definition: vbi608extractor.cpp:29
hardwareprofile.smolt.get_profile_link
def get_profile_link(smoonURL, pub_uuid)
This is another.
Definition: smolt.py:1307
hardwareprofile.smolt.serverMessage
def serverMessage(page)
Definition: smolt.py:400