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
22from builtins import str
23import sys
24import requests
25from optparse import OptionParser
26
27
28def 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 uuid = smolt.read_uuid()
82 delHostString = 'uuid=%s' % uuid
83
84 session = requests.Session()
85 session.headers.update({'USER-AGENT': opts.user_agent})
86 session.headers.update({'Content-type': 'application/x-www-form-urlencoded'})
87 session.headers.update({'Content-length': '%i' % len(delHostString)})
88
89 # Try retrieving current pub_uuid (from cache or remotely if necessary)
90 pub_uuid = None
91 try:
92 pub_uuid = smolt.read_pub_uuid(create_default_uuiddb(), uuid, silent=True)
93 except PubUUIDError:
94 pass
95
96 exceptions = (requests.exceptions.HTTPError,
97 requests.exceptions.URLRequired,
98 requests.exceptions.Timeout,
99 requests.exceptions.ConnectionError,
100 requests.exceptions.InvalidURL)
101
102 try:
103 o = session.post(opts.smoonURL + 'client/delete', data=delHostString,
104 timeout=opts.timeout)
105 except exceptions as e:
106 sys.stderr.write(_('Error contacting Server:'))
107 sys.stderr.write(str(e))
108 sys.stderr.write('\n')
109 sys.exit(1)
110 else:
111 serverMessage(o.text)
112 session.close()
113
114 if pub_uuid is None:
115 profile_url = opts.smoonURL + 'client/show?%s' % delHostString
116 else:
117 profile_url = get_profile_link(opts.smoonURL, pub_uuid)
118 print((_('Profile removed, please verify at'), profile_url))
119
120
121if __name__ == '__main__':
122 main()
def get_profile_link(smoonURL, pub_uuid)
This is another.
Definition: smolt.py:1306
def error(message)
Definition: smolt.py:409
def serverMessage(page)
Definition: smolt.py:399
def create_default_uuiddb()
Definition: uuiddb.py:67
static void print(const QList< uint > &raw_minimas, const QList< uint > &raw_maximas, const QList< float > &minimas, const QList< float > &maximas)