| 
									
										
										
										
											2012-09-26 12:04:46 +02:00
										 |  |  | #!/usr/bin/env python | 
					
						
							| 
									
										
										
										
											2016-01-15 14:52:30 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | ############################################################################ | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Copyright (C) 2016 The Qt Company Ltd. | 
					
						
							|  |  |  | # Contact: https://www.qt.io/licensing/ | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # This file is part of Qt Creator. | 
					
						
							| 
									
										
										
										
											2012-09-26 12:04:46 +02:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2016-01-15 14:52:30 +01:00
										 |  |  | # Commercial License Usage | 
					
						
							|  |  |  | # Licensees holding valid commercial Qt licenses may use this file in | 
					
						
							|  |  |  | # accordance with the commercial license agreement provided with the | 
					
						
							|  |  |  | # Software or, alternatively, in accordance with the terms contained in | 
					
						
							|  |  |  | # a written agreement between you and The Qt Company. For licensing terms | 
					
						
							|  |  |  | # and conditions see https://www.qt.io/terms-conditions. For further | 
					
						
							|  |  |  | # information use the contact form at https://www.qt.io/contact-us. | 
					
						
							| 
									
										
										
										
											2012-09-26 12:04:46 +02:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2016-01-15 14:52:30 +01:00
										 |  |  | # GNU General Public License Usage | 
					
						
							|  |  |  | # Alternatively, this file may be used under the terms of the GNU | 
					
						
							|  |  |  | # General Public License version 3 as published by the Free Software | 
					
						
							|  |  |  | # Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT | 
					
						
							|  |  |  | # included in the packaging of this file. Please review the following | 
					
						
							|  |  |  | # information to ensure the GNU General Public License requirements will | 
					
						
							|  |  |  | # be met: https://www.gnu.org/licenses/gpl-3.0.html. | 
					
						
							| 
									
										
										
										
											2012-09-26 12:04:46 +02:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2016-01-15 14:52:30 +01:00
										 |  |  | ############################################################################ | 
					
						
							| 
									
										
										
										
											2012-09-26 12:04:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | import os | 
					
						
							|  |  |  | import sys | 
					
						
							|  |  |  | import datetime | 
					
						
							|  |  |  | import getopt | 
					
						
							|  |  |  | import subprocess | 
					
						
							|  |  |  | import fnmatch | 
					
						
							|  |  |  | import tempfile | 
					
						
							|  |  |  | import shutil | 
					
						
							|  |  |  | import inspect | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def usage(): | 
					
						
							| 
									
										
										
										
											2015-10-09 11:46:14 +02:00
										 |  |  |     print('Usage: %s [-v|--version-string=versionstring] [-i|--installer-path=/path/to/installerfw] [-a|--archive=archive.7z] [-d|--debug] <outputname>' %  os.path.basename(sys.argv[0])) | 
					
						
							| 
									
										
										
										
											2012-09-26 12:04:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | def substitute_file(infile, outfile, substitutions): | 
					
						
							|  |  |  |     with open(infile, 'r') as f: | 
					
						
							|  |  |  |       template = f.read() | 
					
						
							|  |  |  |     with open(outfile, 'w') as f: | 
					
						
							|  |  |  |       f.write(template.format(**substitutions)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def ifw_template_dir(): | 
					
						
							|  |  |  |     script_dir = os.path.dirname(inspect.getfile(inspect.currentframe())) | 
					
						
							|  |  |  |     source_dir = os.path.normpath(os.path.join(script_dir, '..')); | 
					
						
							|  |  |  |     return os.path.normpath(os.path.join(source_dir, 'dist', 'installer', 'ifw')) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def main(): | 
					
						
							|  |  |  |     try: | 
					
						
							| 
									
										
										
										
											2015-10-09 11:46:14 +02:00
										 |  |  |         opts, args = getopt.gnu_getopt(sys.argv[1:], 'hv:i:a:d', ['help', 'version-string=', 'installer-path=', 'archive', 'debug']) | 
					
						
							| 
									
										
										
										
											2012-09-26 12:04:46 +02:00
										 |  |  |     except: | 
					
						
							|  |  |  |         usage() | 
					
						
							|  |  |  |         sys.exit(2) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if len(args) < 1: | 
					
						
							|  |  |  |         usage() | 
					
						
							|  |  |  |         sys.exit(2) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     version = '' | 
					
						
							|  |  |  |     ifw_location = '' | 
					
						
							| 
									
										
										
										
											2015-10-09 11:46:14 +02:00
										 |  |  |     archives = [] | 
					
						
							|  |  |  |     debug = False | 
					
						
							| 
									
										
										
										
											2012-09-26 12:04:46 +02:00
										 |  |  |     for o, a in opts: | 
					
						
							|  |  |  |         if o in ('-h', '--help'): | 
					
						
							|  |  |  |             usage() | 
					
						
							|  |  |  |             sys.exit(0) | 
					
						
							|  |  |  |         if o in ('-v', '--version-string'): | 
					
						
							|  |  |  |             version = a | 
					
						
							|  |  |  |         if o in ('-i', '--installer-path'): | 
					
						
							|  |  |  |             ifw_location = a | 
					
						
							|  |  |  |         if o in ('-a', '--archive'): | 
					
						
							| 
									
										
										
										
											2015-10-09 11:46:14 +02:00
										 |  |  |             archives.append(a) | 
					
						
							|  |  |  |         if o in ('-d', '--debug'): | 
					
						
							|  |  |  |             debug = True | 
					
						
							| 
									
										
										
										
											2012-09-26 12:04:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (version == ''): | 
					
						
							|  |  |  |       raise Exception('Version not specified (--version-string)!') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (ifw_location == ''): | 
					
						
							|  |  |  |       raise Exception('Installer framework location not specified (--installer-path)!') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-09 11:46:14 +02:00
										 |  |  |     if not archives: | 
					
						
							|  |  |  |       raise ValueError('No archive(s) specified (--archive)!') | 
					
						
							| 
									
										
										
										
											2012-09-26 12:04:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     installer_name = args[0] | 
					
						
							| 
									
										
										
										
											2012-10-09 15:48:00 +02:00
										 |  |  |     config_postfix = '' | 
					
						
							| 
									
										
										
										
											2012-09-26 12:04:46 +02:00
										 |  |  |     if sys.platform == 'darwin': | 
					
						
							| 
									
										
										
										
											2013-06-19 18:39:29 +02:00
										 |  |  |         config_postfix = '-mac' | 
					
						
							| 
									
										
										
										
											2012-10-09 15:48:00 +02:00
										 |  |  |     if sys.platform.startswith('win'): | 
					
						
							|  |  |  |         config_postfix = '-windows' | 
					
						
							|  |  |  |     if sys.platform.startswith('linux'): | 
					
						
							|  |  |  |         config_postfix = '-linux' | 
					
						
							| 
									
										
										
										
											2013-03-25 09:59:29 +01:00
										 |  |  |         installer_name = installer_name + '.run' | 
					
						
							| 
									
										
										
										
											2012-10-09 15:48:00 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     config_name = 'config' + config_postfix + '.xml' | 
					
						
							| 
									
										
										
										
											2012-09-26 12:04:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     try: | 
					
						
							|  |  |  |         temp_dir = tempfile.mkdtemp() | 
					
						
							|  |  |  |     except: | 
					
						
							| 
									
										
										
										
											2015-10-09 11:46:14 +02:00
										 |  |  |         raise IOError('Failed to create a temporary directory!') | 
					
						
							| 
									
										
										
										
											2012-09-26 12:04:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-09 11:46:14 +02:00
										 |  |  |     if debug: | 
					
						
							|  |  |  |         print('Working directory: {0}'.format(temp_dir)) | 
					
						
							| 
									
										
										
										
											2012-09-26 12:04:46 +02:00
										 |  |  |     try: | 
					
						
							|  |  |  |         substs = {} | 
					
						
							|  |  |  |         substs['version'] = version | 
					
						
							|  |  |  |         substs['date'] = datetime.date.today().isoformat() | 
					
						
							| 
									
										
										
										
											2015-10-09 11:46:14 +02:00
										 |  |  |         substs['archives'] = ','.join(archives) | 
					
						
							| 
									
										
										
										
											2012-09-26 12:04:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         template_dir = ifw_template_dir() | 
					
						
							|  |  |  |         out_config_dir = os.path.join(temp_dir,'config') | 
					
						
							|  |  |  |         out_packages_dir = os.path.join(temp_dir, 'packages') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         shutil.copytree(os.path.join(template_dir, 'packages'), os.path.join(temp_dir, 'packages')) | 
					
						
							|  |  |  |         shutil.copytree(os.path.join(template_dir, 'config'), os.path.join(temp_dir, 'config')) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for root, dirnames, filenames in os.walk(out_packages_dir): | 
					
						
							|  |  |  |             for template in fnmatch.filter(filenames, '*.in'): | 
					
						
							|  |  |  |                 substitute_file(os.path.join(root, template), os.path.join(root, template[:-3]), substs) | 
					
						
							|  |  |  |                 os.remove(os.path.join(root, template)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for root, dirnames, filenames in os.walk(out_config_dir): | 
					
						
							|  |  |  |             for template in fnmatch.filter(filenames, '*.in'): | 
					
						
							|  |  |  |                 substitute_file(os.path.join(root, template), os.path.join(root, template[:-3]), substs) | 
					
						
							|  |  |  |                 os.remove(os.path.join(root, template)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         data_path = os.path.join(out_packages_dir, 'org.qtproject.qtcreator.application', 'data') | 
					
						
							|  |  |  |         if not os.path.exists(data_path): | 
					
						
							|  |  |  |             os.makedirs(data_path) | 
					
						
							| 
									
										
										
										
											2015-10-09 11:46:14 +02:00
										 |  |  |         for archive in archives: | 
					
						
							|  |  |  |             shutil.copy(archive, data_path) | 
					
						
							| 
									
										
										
										
											2012-09-26 12:04:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-09 15:48:00 +02:00
										 |  |  |         ifw_call = [os.path.join(ifw_location, 'bin', 'binarycreator'), '-c', os.path.join(out_config_dir, config_name), '-p', out_packages_dir, installer_name, '--offline-only' ] | 
					
						
							| 
									
										
										
										
											2015-10-09 11:46:14 +02:00
										 |  |  |         if debug: | 
					
						
							|  |  |  |             ifw_call.append('-v') | 
					
						
							| 
									
										
										
										
											2012-09-26 12:04:46 +02:00
										 |  |  |         subprocess.check_call(ifw_call, stderr=subprocess.STDOUT) | 
					
						
							|  |  |  |     finally: | 
					
						
							| 
									
										
										
										
											2015-10-09 11:46:14 +02:00
										 |  |  |         if not debug: | 
					
						
							|  |  |  |             print('Cleaning up...') | 
					
						
							|  |  |  |             shutil.rmtree(temp_dir) | 
					
						
							| 
									
										
										
										
											2015-08-25 09:52:23 +03:00
										 |  |  |         print('Done.') | 
					
						
							| 
									
										
										
										
											2012-09-26 12:04:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | if __name__ == '__main__': | 
					
						
							|  |  |  |     main() |