Fixed build error by changing buildrequires from pkgconfig(turbo-jpeg) to libjpeg...
[platform/upstream/hplip.git] / install.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # (c) Copyright 2003-2009 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: Don Welch
21 #
22
23 __version__ = '5.1'
24 __title__ = 'HPLIP Installer'
25 __mod__ = 'hplip-install'
26 __doc__ = "Installer for HPLIP tarball (called automatically after invoking the .run file)."
27
28
29 # Std Lib
30 import getopt
31 import os
32 import os.path
33 import sys
34 import time
35 import re
36
37 # Local
38 from base.g import *
39 from base import utils
40
41
42 USAGE = [(__doc__, "", "name", True),
43          ("Usage: sh %s [OPTIONS]" % __mod__, "", "summary", True),
44          utils.USAGE_SPACE,
45          utils.USAGE_SPACE,
46          utils.USAGE_OPTIONS,
47          ("Automatic mode (chooses the most common options):", "-a or --auto", "option", False),
48          ("Dependency package installation retries:", "-r <retries> or --retries=<retries> (default is 3)", "option", False),
49          ("Assume network connection present:", "-n or --network", "option", False),
50          utils.USAGE_LOGGING1, utils.USAGE_LOGGING2, utils.USAGE_LOGGING3,
51          utils.USAGE_HELP,
52          utils.USAGE_SPACE,
53          utils.USAGE_SPACE,
54          ("[OPTIONS] (FOR TESTING ONLY/ADVANCED)", "", "header", False),
55          ("Force install of all dependencies:", "-x", "option", False),
56          ("Force unknown distro mode:", "-d", "option", False),
57          ("Force installation of Qt4 support:", "--qt4 (same as --enable=qt4)", "option", False),
58          ("Force disable Qt4 support:", "--no-qt4 (same as --disable=qt4", "option", False),
59          #("Force installation of Qt3 support:", "--qt3 (same as --enable=qt3)", "option", False),
60          #("Force disable Qt3 support:", "--no-qt3 (same as --disable=qt3", "option", False),
61          ("Force installation of PolicyKit support:", "--policykit (same as --enable=policykit)", "option", False),
62          ("Force disable PolicyKit support:", "--no-policykit (same as --disable=policykit)", "option", False),
63          ("Force configure enable/disable flag:", "--enable=<flag> or --disable=<flag>, where <flag> is 'fax-build', 'qt4', 'pp-build', etc. See ./configure --help for more info.", "option", False),
64         ]
65
66 def usage(typ='text'):
67     if typ == 'text':
68         utils.log_title(__title__, __version__)
69
70     utils.format_text(USAGE, typ, __title__, __mod__, __version__)
71     sys.exit(0)
72
73
74 log.set_module(__mod__)
75
76 log.debug("euid = %d" % os.geteuid())
77 mode = INTERACTIVE_MODE
78 auto = False
79 test_depends = False
80 test_unknown = False
81 language = None
82 assume_network = False
83 max_retries = 3
84 restricted_override = False
85 enable = []
86 disable = []
87
88 if((re.search(' ',os.getcwd()))!= None):
89         log.info("Current hplip source directory path has space character in it. Please update path by removing space characters. Example: Change %s.run to %s.run" % (os.getcwd(),(os.getcwd()).replace(' ','')))
90         os.system("rm -r ../%s"%(os.getcwd()).rsplit('/').pop())
91         sys.exit(0)             
92                 
93 try:
94     opts, args = getopt.getopt(sys.argv[1:], 'hl:giatxdq:nr:b',
95         ['help', 'help-rest', 'help-man', 'help-desc', 'gui', 'lang=',
96         'logging=', 'interactive', 'auto', 'text', 'qt4',
97         'network', 'retries=', 'enable=', 'disable=',
98         'no-qt4', 'policykit', 'no-policykit', 'debug'])
99
100 except getopt.GetoptError, e:
101     log.error(e.msg)
102     usage()
103     sys.exit(1)
104
105 if os.getenv("HPLIP_DEBUG"):
106     log.set_level('debug')
107
108 for o, a in opts:
109     if o in ('-h', '--help'):
110         usage()
111
112     elif o == '--help-rest':
113         usage('rest')
114
115     elif o == '--help-man':
116         usage('man')
117
118     elif o in ('-q', '--lang'):
119         language = a.lower()
120
121     elif o == '--help-desc':
122         print __doc__,
123         sys.exit(0)
124
125     elif o in ('-l', '--logging'):
126         log_level = a.lower().strip()
127         if not log.set_level(log_level):
128             usage()
129
130     elif o in ('-g', '--debug'):
131         log.set_level('debug')
132
133     elif o in ('-i', '--interactive', '--text', '-t'):
134         mode = INTERACTIVE_MODE
135
136     elif o in ('-a', '--auto'):
137         auto = True
138
139     elif o == '-x':
140         log.warn("Install all depends (-x) is for TESTING ONLY")
141         test_depends = True
142
143     elif o == '-d':
144         log.warn("Unknown distro (-d) is for TESTING ONLY")
145         test_unknown = True
146
147     elif o in ('-n', '--network'):
148         assume_network = True
149
150     elif o in ('-r', '--retries'):
151         try:
152             max_retries = int(a)
153         except ValueError:
154             log.error("Invalid value for retries. Set to default of 3.")
155             max_retries = 3
156
157     elif o == '-b':
158         restricted_override = True
159
160     elif o == '--qt4':
161         if 'qt4' not in enable and 'qt4' not in disable:
162             enable.append('qt4')
163         else:
164             log.error("Duplicate configuration flag: %s" % a)
165             sys.exit(1)
166
167     elif o == '--no-qt4':
168         if 'qt4' not in disable and 'qt4' not in enable:
169             disable.append('qt4')
170         else:
171             log.error("Duplicate configuration flag: %s" % a)
172             sys.exit(1)
173
174     elif o == '--policykit':
175         if 'policykit' not in enable and 'policykit' not in disable:
176             enable.append('policykit')
177         else:
178             log.error("Duplicate configuration flag: %s" % a)
179             sys.exit(1)
180
181     elif o == '--no-policykit':
182         if 'policykit' not in disable and 'policykit' not in enable:
183             disable.append('policykit')
184         else:
185             log.error("Duplicate configuration flag: %s" % a)
186             sys.exit(1)
187
188     elif o == '--enable':
189         if a not in enable and a not in disable:
190             enable.append(a)
191         else:
192             log.error("Duplicate configuration flag: %s" % a)
193             sys.exit(1)
194
195     elif o == '--disable':
196         if a not in enable and a not in disable:
197             disable.append(a)
198         else:
199             log.error("Duplicate configuration flag: %s" % a)
200             sys.exit(1)
201
202
203
204 if os.getuid() == 0:
205     log.warn("hplip-install should not be run as root.")
206
207 log_file = os.path.normpath('./hplip-install_%s.log' % time.strftime("%a-%d-%b-%Y_%H:%M:%S"))
208
209 if os.path.exists(log_file):
210     os.remove(log_file)
211
212 log.set_logfile(log_file)
213 log.set_where(log.LOG_TO_CONSOLE_AND_FILE)
214
215 log.debug("Log file=%s" % log_file)
216
217 ac_init_pat = re.compile(r"""AC_INIT\(\[(.*?)\], *\[(.*?)\], *\[(.*?)\], *\[(.*?)\] *\)""", re.IGNORECASE)
218 try:
219     config_in = open('./configure.in', 'r')
220 except IOError:
221     prop.version = 'x.x.x'
222 else:
223     for c in config_in:
224         if c.startswith("AC_INIT"):
225             match_obj = ac_init_pat.search(c)
226             prop.version = match_obj.group(2)
227             break
228
229     config_in.close()
230
231 utils.log_title(__title__, __version__, True)
232
233 log.info("Installer log saved in: %s" % log.bold(log_file))
234 log.info("")
235
236
237 try:
238     from installer import text_install
239     log.debug("Starting text installer...")
240     text_install.start(language, auto, test_depends, test_unknown, assume_network, max_retries, enable, disable)
241 except KeyboardInterrupt:
242     log.error("User exit")
243