+ 1#============================================================================
+ 2#Name : builders.py
+ 3#Part of : Helium
+ 4
+ 5#Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+ 6#All rights reserved.
+ 7#This component and the accompanying materials are made available
+ 8#under the terms of the License "Eclipse Public License v1.0"
+ 9#which accompanies this distribution, and is available
+ 10#at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ 11#
+ 12#Initial Contributors:
+ 13#Nokia Corporation - initial contribution.
+ 14#
+ 15#Contributors:
+ 16#
+ 17#Description:
+ 18#===============================================================================
+ 19
+ 20"""
+ 21This modules contains the archive builders.
+ 22An archive builder is a class that is able to use data from a configuration
+ 23and generate a set of shell commands.
+ 24"""
+ 25importarchive.tools
+ 26importarchive.selectors
+ 27importarchive.mappers
+ 28importarchive.scanners
+ 29importlogging
+ 30importpathaddition
+ 31importbuildtools
+ 32importos
+ 33importcodecs
+ 34
+ 35_logger=logging.getLogger('archive')
+ 36_logger.setLevel(logging.INFO)
+ 37
+
48""" Generate a manifest file from the a configuration. """
+ 49_logger.info('Processing archive config: '+config['name'])
+ 50_scanners=archive.scanners.get_scanners(config.get_list('scanners',['default']),config)
+ 51
+ 52content_list={}
+ 53
+ 54ifnotos.path.exists(config['temp.build.dir']):
+ 55os.makedirs(config['temp.build.dir'])
+ 56manifest_file_path=os.path.abspath(os.path.join(config['temp.build.dir'],config['name']+'_includefile.txt'))
+ 57out=codecs.open(manifest_file_path,'w+','utf-8')
+ 58
+ 59# zip.root.dir can be set to root.dir so that when zipping from another dir,
+ 60# the manifest is relative to that dir
+ 61(drive,root_dir)=os.path.splitdrive(os.path.normpath(config.get('zip.root.dir',config['root.dir'])))
+ 62_logger.info(" * Scanning")
+ 63forscannerin_scanners:
+ 64_logger.debug("Scanner %s"%scanner)
+ 65forsubpathinscanner.scan():
+ 66(drive,subpath)=os.path.splitdrive(subpath)
+ 67ifpathaddition.relative.abs2rel(subpath,root_dir):
+ 68_logger.debug(subpath)
+ 69subpath=subpath[len(root_dir):]
+ 70ifsubpath.startswith(os.sep):
+ 71subpath=subpath[1:]
+ 72# normpath is to remove any occurances of "..\.." before checking for duplicates
+ 73subpath=os.path.normpath(subpath)
+ 74ifsubpathnotincontent_list:
+ 75out.write(u"".join([subpath,u'\n']))
+ 76content_list[subpath]=True
+ 77
+ 78out.close()
+ 79returnmanifest_file_path
+
117"""Creates a build tool configuration file that executes archive build operations.
+118
+119 The input to each archive build operation is an includefile that lists
+120 all the files to be included in the archive. These text files are
+121 generated before the build file by scanning the filesystem.
+122 """
+123stages=buildtools.CommandList()
+124
+125commands=[]
+126ifself.index>len(self.configs):
+127raiseException("index not found in configuration")
+128config=self.configs[self.index]
+129stages=self.manifest_to_commands(config,self.build_manifest(config))
+130
+131# merging the commands
+132whilelen(commands)<len(stages):
+133commands.append([])
+134foriinrange(len(stages)):
+135commands[i].extend(stages[i])
+136
+137writer=buildtools.get_writer(self.writerType,outputname)
+138writer.write(self.create_command_list(commands))
+