Package archive :: Module builders
[hide private]
[frames] | no frames]

Source Code for Module archive.builders

  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  """ 
 21  This modules contains the archive builders. 
 22  An archive builder is a class that is able to use data from a configuration 
 23  and generate a set of shell commands. 
 24  """ 
 25  import archive.tools 
 26  import archive.selectors 
 27  import archive.mappers 
 28  import archive.scanners 
 29  import logging 
 30  import pathaddition 
 31  import buildtools 
 32  import os 
 33  import codecs 
 34   
 35  _logger = logging.getLogger('archive') 
 36  _logger.setLevel(logging.INFO) 
 37   
38 -class ArchivePreBuilder(buildtools.PreBuilder):
39 """ Processes an archive build specification. """
40 - def __init__(self, config_set, config_name, writerType='ant', index = None):
41 buildtools.PreBuilder.__init__(self, config_set) 42 self.configs = config_set.getConfigurations() 43 self.spec_name = config_name 44 self.index = index 45 self.writerType = writerType
46
47 - def build_manifest(self, config):
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 52 content_list = {} 53 54 if not os.path.exists(config['temp.build.dir']): 55 os.makedirs(config['temp.build.dir']) 56 manifest_file_path = os.path.abspath(os.path.join(config['temp.build.dir'], config['name'] + '_includefile.txt')) 57 out = 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") 63 for scanner in _scanners: 64 _logger.debug("Scanner %s" % scanner) 65 for subpath in scanner.scan(): 66 (drive, subpath) = os.path.splitdrive(subpath) 67 if pathaddition.relative.abs2rel(subpath, root_dir): 68 _logger.debug(subpath) 69 subpath = subpath[len(root_dir):] 70 if subpath.startswith(os.sep): 71 subpath = subpath[1:] 72 # normpath is to remove any occurances of "..\.." before checking for duplicates 73 subpath = os.path.normpath(subpath) 74 if subpath not in content_list: 75 out.write(u"".join([subpath, u'\n'])) 76 content_list[subpath] = True 77 78 out.close() 79 return manifest_file_path
80
81 - def manifest_to_commands(self, config, manifest):
82 """ Generate return a command list. Commands are stored in a two dimension array.""" 83 _logger.info(" * Generating commands") 84 tool = archive.tools.get_tool(config['archive.tool']) 85 mapper_name = 'default' 86 if config.has_key('mapper'): 87 mapper_name = config['mapper'] 88 mapper = archive.mappers.get_mapper(mapper_name, config, tool) 89 return mapper.create_commands(manifest)
90
91 - def create_command_list(self, commands):
92 """ Convert a two dimensions array of command to a CommandList object. """ 93 stages = buildtools.CommandList() 94 newstage = False 95 for cmds_stage in commands: 96 _logger.debug("Stage: %s" % cmds_stage) 97 for cmd in cmds_stage: 98 stages.addCommand(cmd, newstage) 99 newstage = False 100 newstage = True 101 return stages
102
103 - def writeTopLevel(self, build_file_path, output_path, xml_file):
104 """Creates a build tool config makefile that executes archieve build.""" 105 config_name_list = [] 106 for config in self.configs: 107 config_name_list.append(config['name']) 108 if not os.path.exists(config['archives.dir']): 109 os.makedirs(config['archives.dir']) 110 111 writer = buildtools.get_writer(self.writerType, build_file_path) 112 writer.writeTopLevel(config_name_list, self.spec_name, output_path, xml_file)
113 114 115
116 - def write(self, outputname):
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 """ 123 stages = buildtools.CommandList() 124 125 commands = [] 126 if self.index > len(self.configs): 127 raise Exception("index not found in configuration") 128 config = self.configs[self.index] 129 stages = self.manifest_to_commands(config, self.build_manifest(config)) 130 131 # merging the commands 132 while len(commands) < len(stages): 133 commands.append([]) 134 for i in range(len(stages)): 135 commands[i].extend(stages[i]) 136 137 writer = buildtools.get_writer(self.writerType, outputname) 138 writer.write(self.create_command_list(commands))
139