Please notice that forums and news and documentation have moved elsewhere.

source: nscp/build/python/postbuild.py @ 35254d1

0.4.00.4.10.4.2
Last change on this file since 35254d1 was 35254d1, checked in by Michael Medin <michael@…>, 3 years ago
  • Fixed installer "back" issues
  • Fixed payload truncation for NRPe and NSCA
  • Improved the installer target tagging functions in the python installer
  • Property mode set to 100644
File size: 3.2 KB
Line 
1import sys
2import os
3import zipfile
4import fnmatch
5import shutil
6
7
8execfile("config.py")
9
10sys.path.append(BUILD_PYTHON_FOLDER)
11from VersionHandler import VersionHandler
12
13version = VersionHandler(VERSION_TXT)
14version.read()
15datestr = version.datestr()
16vstring = version.version()
17
18targets = None
19
20def build_targets(str):
21        targets = {}
22        for itm in str.split(';'):
23                tmp = itm.split('=')
24                if len(tmp) == 0:
25                        continue
26                elif len(tmp) == 1:
27                        targets['nscp'] = tmp[0]
28                else:
29                        targets[tmp[0]] = tmp[1]
30        return targets
31                       
32       
33               
34def find_target(key=None):
35        global targets
36        if not targets:
37                targets = build_targets(TARGET_SITE)
38        if not key:
39                key = 'nscp'
40        if not key in targets:
41                return None
42        return targets[key]
43
44
45def scp_file(file):
46        tfile = os.path.basename(file)
47        (name, version, arch) = tfile.split('-')
48        target = None
49        if '_' in name:
50                (name, tag) = name.split('_')
51                target = find_target(tag)
52                if target:
53                        print 'Found tagged installer %s for %s'%(tfile, tag)
54                else:
55                        print 'Ignoring unconfigured tagged installer: %s (define TARGET_SITE_%s to a destination)'%(tag,tag)
56        else:
57                print 'Found normal installer %s'%tfile
58                target = find_target()
59        if target:
60                print 'Uploading name: %s to %s'%(tfile, target)
61                os.system("%s %s %s"%(SCP_BINARY, file, target))
62
63def rename_and_move(file, target):
64        tfile = '%s/%s'%(target, os.path.basename(file))
65        tfile = tfile.replace('win64', 'x64')
66        print "Copying %s to %s"%(file, tfile)
67        shutil.copy(file, tfile)
68
69def find_by_pattern(path, pattern):
70        matches = []
71        for root, dirnames, filenames in os.walk(path):
72                if '_CPack_Packages' not in root:
73                        for filename in fnmatch.filter(filenames, pattern):
74                                matches.append(os.path.join(root, filename))
75        return matches
76       
77target_name = 'NSCP-%s-%s_symbols.zip'%(vstring, VERSION_ARCH)
78
79if BREAKPAD_FOUND == "TRUE":
80        print "Gathering symbols into %s"%target_name
81        matches = find_by_pattern(BUILD_TARGET_EXE_PATH, '*.pdb')
82        zip = zipfile.ZipFile(target_name, 'w', zipfile.ZIP_DEFLATED)
83        for f in matches:
84                print "Processing: %s"%f
85                out = f.replace('.pdb', '.sym')
86                os.system("%s %s > %s"%(BREAKPAD_DUMPSYMS_EXE, f, out))
87                if out.startswith(BUILD_TARGET_EXE_PATH):
88                        name = out[len(BUILD_TARGET_EXE_PATH)+1:]
89                else:
90                        name = out
91                zip.write(out, name)
92        zip.close()
93
94if ARCHIVE_FOLDER != "":
95        print "Archiving files..."
96        target_installer = "%s/%s"%(ARCHIVE_FOLDER,"installers")
97        target_archives = "%s/%s"%(ARCHIVE_FOLDER,"archive")
98        if not os.path.isdir(ARCHIVE_FOLDER):
99                os.mkdir(ARCHIVE_FOLDER)
100        if not os.path.isdir(target_installer):
101                os.mkdir(target_installer)
102        if not os.path.isdir(target_archives):
103                os.mkdir(target_archives)
104
105        for f in find_by_pattern(BUILD_TARGET_EXE_PATH, '*%s*.msi'%vstring):
106                rename_and_move(f, target_installer)
107        for f in find_by_pattern(BUILD_TARGET_EXE_PATH, '*%s*.zip'%vstring):
108                rename_and_move(f, target_archives)
109
110try:
111        if TARGET_SITE != '' and SCP_BINARY != '':
112                print "Distributing files to site..."
113
114                for f in find_by_pattern(BUILD_TARGET_EXE_PATH, '*%s*.msi'%vstring):
115                        scp_file(f)
116                for f in find_by_pattern(BUILD_TARGET_EXE_PATH, '*%s*.zip'%vstring):
117                        scp_file(f)
118except NameError:
119        print 'TARGET_SITE not defined so we wont upload anything...'
Note: See TracBrowser for help on using the repository browser.