1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
39 """ Processes an archive build specification. """
40 - def __init__(self, config_set, config_name, writerType='ant', index = None):
46
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
60
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
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
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
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
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