18
|
1 |
#
|
|
2 |
# Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
# All rights reserved.
|
|
4 |
# This component and the accompanying materials are made available
|
|
5 |
# under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
# which accompanies this distribution, and is available
|
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
#
|
|
9 |
# Initial Contributors:
|
|
10 |
# Nokia Corporation - initial contribution.
|
|
11 |
#
|
|
12 |
# Contributors:
|
|
13 |
#
|
|
14 |
# Description:
|
|
15 |
# Filter class for copying files in serial in python. This
|
|
16 |
# is important in cluster builds where file copying is
|
|
17 |
# very inefficient.
|
|
18 |
# The one-to-many <finalcopy> tag is searched for and copy
|
|
19 |
# instructions are built up in a hash table.
|
|
20 |
# <finalcopy source='sourcefilename'>destfilename1 destfilename2 . . . .destfilenameN</copy>
|
|
21 |
# destinations must be full filenames not directories.
|
|
22 |
#
|
|
23 |
# This filter monitors build progress
|
|
24 |
# via the <progress> tags and flushes copies as build
|
|
25 |
# stages end (e.g. after resource so resources are ready for the next stage)
|
|
26 |
#
|
|
27 |
|
|
28 |
import os
|
|
29 |
import sys
|
|
30 |
import tempfile
|
|
31 |
import filter_interface
|
|
32 |
import shutil
|
|
33 |
import generic_path
|
|
34 |
import stat
|
|
35 |
from raptor_utilities import copyfile
|
|
36 |
|
|
37 |
class FilterCopyFile(filter_interface.Filter):
|
|
38 |
|
|
39 |
def open(self, params):
|
|
40 |
"initialise"
|
|
41 |
|
|
42 |
self.ok = True
|
|
43 |
|
|
44 |
self.files = {}
|
|
45 |
|
|
46 |
return self.ok
|
|
47 |
|
|
48 |
|
|
49 |
def write(self, text):
|
|
50 |
"process some log text"
|
|
51 |
|
|
52 |
for line in text.splitlines():
|
|
53 |
if line.startswith("<finalcopy"):
|
|
54 |
source_start = line.find("source='")
|
|
55 |
source = line[source_start+8:line.find("'", source_start+8)]
|
|
56 |
destinations = line[line.find(">",source_start)+1:line.find("</finalcopy>")].split(" ")
|
|
57 |
|
|
58 |
if source in self.files:
|
|
59 |
self.files[source].update(destinations)
|
|
60 |
else:
|
|
61 |
self.files[source] = set(destinations)
|
|
62 |
elif line.startswith("<progress:end object_type='makefile' task='build'"):
|
|
63 |
self.flushcopies() # perform copies at end of each invocation of the make engine
|
|
64 |
# to ensure dependencies are in place for the next one.
|
|
65 |
|
|
66 |
return self.ok
|
|
67 |
|
|
68 |
|
|
69 |
def summary(self):
|
|
70 |
"finish off"
|
|
71 |
self.flushcopies()
|
|
72 |
return self.ok
|
|
73 |
|
|
74 |
def flushcopies(self):
|
|
75 |
for source in self.files.keys():
|
|
76 |
for dest in self.files[source]:
|
|
77 |
try:
|
|
78 |
copyfile(source, dest)
|
|
79 |
except IOError, e:
|
|
80 |
print "<error>%s</error>" % str(e)
|
|
81 |
self.files = {}
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
def close(self):
|
|
86 |
"nop"
|
|
87 |
|
|
88 |
|
|
89 |
return self.ok
|
|
90 |
|
|
91 |
# the end
|
|
92 |
|