~ubuntu-branches/ubuntu/raring/hplip/raring

« back to all changes in this revision

Viewing changes to uninstall.py

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2012-10-06 15:03:44 UTC
  • mfrom: (1.6.1) (20.1.16 quantal)
  • Revision ID: package-import@ubuntu.com-20121006150344-2p3xz26br0t3hu2q
Tags: 3.12.10-1
* New upstream release
  - Fixes "Network scanning fails (Closes: #683033)
* quilt refresh hplip-syslog-fix-debug-messages-to-error.dpatch
* Fix "error in clean build env" updated debian/rules (Closes: #687129)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
# -*- coding: utf-8 -*-
 
3
#
 
4
# (c) Copyright 2011-2014 Hewlett-Packard Development Company, L.P.
 
5
#
 
6
# This program is free software; you can redistribute it and/or modify
 
7
# it under the terms of the GNU General Public License as published by
 
8
# the Free Software Foundation; either version 2 of the License, or
 
9
# (at your option) any later version.
 
10
#
 
11
# This program is distributed in the hope that it will be useful,
 
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
# GNU General Public License for more details.
 
15
#
 
16
# You should have received a copy of the GNU General Public License
 
17
# along with this program; if not, write to the Free Software
 
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 
19
#
 
20
# Author: Amarnath Chitumalla
 
21
#
 
22
 
 
23
__version__ = '1.0'
 
24
__title__ = 'HPLIP Uninstaller'
 
25
__mod__ = 'hp-uninstall'
 
26
__doc__ = "Uninstaller for HPLIP ."
 
27
 
 
28
# Std Lib
 
29
import getopt, os, sys, re, time
 
30
 
 
31
# Local
 
32
from base.g import *
 
33
from base import utils, tui
 
34
from installer.core_install import *
 
35
 
 
36
 
 
37
USAGE = [(__doc__, "", "name", True),
 
38
         ("Usage: %s [OPTIONS]" % __mod__, "", "summary", True),
 
39
         utils.USAGE_SPACE,
 
40
         utils.USAGE_OPTIONS,
 
41
         utils.USAGE_LOGGING1, utils.USAGE_LOGGING2, utils.USAGE_LOGGING3,
 
42
         ("Non-interactive mode:", "-n (without asking for permission)","option",False),
 
43
         utils.USAGE_HELP,
 
44
        ]
 
45
 
 
46
 
 
47
def usage(typ='text'):
 
48
    if typ == 'text':
 
49
        utils.log_title(__title__, __version__)
 
50
 
 
51
    utils.format_text(USAGE, typ, __title__, __mod__, __version__)
 
52
    sys.exit(0)
 
53
 
 
54
mode = INTERACTIVE_MODE
 
55
auto = False
 
56
log_level = None
 
57
 
 
58
 
 
59
 
 
60
log.set_module(__mod__)
 
61
 
 
62
 
 
63
try:
 
64
    opts, args = getopt.getopt(sys.argv[1:], 'hl:gn',
 
65
        ['help', 'help-rest', 'help-man', 'help-desc', 'gui', 'lang=','logging=', 'debug'])
 
66
 
 
67
except getopt.GetoptError, e:
 
68
    log.error(e.msg)
 
69
    usage()
 
70
    sys.exit(1)
 
71
 
 
72
if os.getenv("HPLIP_DEBUG"):
 
73
    log.set_level('debug')
 
74
 
 
75
for o, a in opts:
 
76
    if o in ('-h', '--help'):
 
77
        usage()
 
78
 
 
79
    elif o == '--help-rest':
 
80
        usage('rest')
 
81
 
 
82
    elif o == '--help-man':
 
83
        usage('man')
 
84
 
 
85
    elif o in ('-q', '--lang'):
 
86
        language = a.lower()
 
87
 
 
88
    elif o == '--help-desc':
 
89
        print __doc__,
 
90
        sys.exit(0)
 
91
 
 
92
    elif o in ('-l', '--logging'):
 
93
        log_level = a.lower().strip()
 
94
#        if not log.set_level(log_level):
 
95
#            usage()
 
96
 
 
97
    elif o in ('-g', '--debug'):
 
98
        log_level = 'debug'
 
99
#        log.set_level('debug')
 
100
 
 
101
    elif o == '-n':
 
102
        mode = NON_INTERACTIVE_MODE
 
103
 
 
104
 
 
105
if log_level is not None:
 
106
    if not log.set_level(log_level):
 
107
        usage()
 
108
        
 
109
log_file = os.path.normpath('/var/log/hp/hplip-uninstall.log')
 
110
if os.getuid() != 0:
 
111
    log.error("To run 'hp-uninstall' utility, you must have root privileges.(Try using 'sudo' or 'su -c')")
 
112
    sys.exit(1)
 
113
 
 
114
if os.path.exists(log_file):
 
115
    os.remove(log_file)
 
116
 
 
117
log.set_logfile(log_file)
 
118
log.set_where(log.LOG_TO_CONSOLE_AND_FILE)
 
119
 
 
120
log.debug("Log file=%s" % log_file)
 
121
log.debug("euid = %d" % os.geteuid())
 
122
 
 
123
utils.log_title(__title__, __version__, True)
 
124
 
 
125
log.info("Uninstaller log saved in: %s" % log.bold(log_file))
 
126
log.info("")
 
127
 
 
128
core =  CoreInstall(MODE_CHECK, INTERACTIVE_MODE)
 
129
core.init()
 
130
 
 
131
core.uninstall(mode)
 
132