|
a |
|
b/codesys-ide/scripts/gen-package-manifest.py |
|
|
1 |
import sys, os, glob |
|
|
2 |
import uuid |
|
|
3 |
import helper |
|
|
4 |
|
|
|
5 |
ManifestSkeleton="""<?xml version="1.0" encoding="ISO-8859-1"?> |
|
|
6 |
<Package> |
|
|
7 |
<Strings> |
|
|
8 |
<String Id="GeneralName"> |
|
|
9 |
<Neutral>%s</Neutral> |
|
|
10 |
</String> |
|
|
11 |
<String Id="GeneralVendor"> |
|
|
12 |
<Neutral>%s</Neutral> |
|
|
13 |
</String> |
|
|
14 |
<String Id="GeneralCopyright"> |
|
|
15 |
<Neutral>%s</Neutral> |
|
|
16 |
</String> |
|
|
17 |
<String Id="GeneralDescription"> |
|
|
18 |
<Neutral>%s</Neutral> |
|
|
19 |
</String> |
|
|
20 |
<String Id="license"> |
|
|
21 |
<Neutral>%s</Neutral> |
|
|
22 |
</String> |
|
|
23 |
<String Id="TargetDir"> |
|
|
24 |
<Neutral>Target directory</Neutral> |
|
|
25 |
</String> |
|
|
26 |
<String Id="TargetDirDescription"> |
|
|
27 |
<Neutral>The target directory where the projects are saved.</Neutral> |
|
|
28 |
</String> |
|
|
29 |
</Strings> |
|
|
30 |
<General> |
|
|
31 |
<Id>{%s}</Id> |
|
|
32 |
<Version>1.0.0.0</Version> |
|
|
33 |
<Name>$GeneralName</Name> |
|
|
34 |
<Vendor>$GeneralVendor</Vendor> |
|
|
35 |
<Copyright>$GeneralCopyright</Copyright> |
|
|
36 |
<Description>$GeneralDescription</Description> |
|
|
37 |
<LicenseAgreement>$license</LicenseAgreement> |
|
|
38 |
<RequiredInstallerVersion>3.5.10.0</RequiredInstallerVersion> |
|
|
39 |
</General> |
|
|
40 |
<TargetDirectoryDefinitions> |
|
|
41 |
<TargetDirectoryDefinition> |
|
|
42 |
<Id>1</Id> |
|
|
43 |
<Name>$TargetDir</Name> |
|
|
44 |
<Description>$TargetDirDescription</Description> |
|
|
45 |
<PromptUser>True</PromptUser> |
|
|
46 |
<DefaultValue>%%USERPROFILE%%\CODESYS Projects\</DefaultValue> |
|
|
47 |
</TargetDirectoryDefinition> |
|
|
48 |
</TargetDirectoryDefinitions> |
|
|
49 |
<Components> |
|
|
50 |
<Component> |
|
|
51 |
<General> |
|
|
52 |
<Id>1</Id> |
|
|
53 |
<Name>Default</Name> |
|
|
54 |
<Description>Default Package</Description> |
|
|
55 |
<Selectable>false</Selectable> |
|
|
56 |
<SelectedByDefault>true</SelectedByDefault> |
|
|
57 |
</General> |
|
|
58 |
<Dependencies> |
|
|
59 |
</Dependencies> |
|
|
60 |
<Items> |
|
|
61 |
%s |
|
|
62 |
</Items> |
|
|
63 |
</Component> |
|
|
64 |
</Components> |
|
|
65 |
</Package> |
|
|
66 |
""" |
|
|
67 |
|
|
|
68 |
ManifestItemLibrary = """ |
|
|
69 |
<Library> |
|
|
70 |
<Path>%s</Path> |
|
|
71 |
</Library> |
|
|
72 |
""" |
|
|
73 |
|
|
|
74 |
ManifestItemDevDesc = """ |
|
|
75 |
<DeviceDescription> |
|
|
76 |
<Path>%s</Path> |
|
|
77 |
</DeviceDescription> |
|
|
78 |
""" |
|
|
79 |
|
|
|
80 |
ManifestItemProject = """ |
|
|
81 |
<File> |
|
|
82 |
<Path>%s</Path> |
|
|
83 |
<IgnoreArchiveFolder>True</IgnoreArchiveFolder> |
|
|
84 |
<TargetFolder>$1</TargetFolder> |
|
|
85 |
<Overwrite> |
|
|
86 |
<Option>Yes</Option> |
|
|
87 |
</Overwrite> |
|
|
88 |
</File> |
|
|
89 |
""" |
|
|
90 |
|
|
|
91 |
|
|
|
92 |
class SearchBuildDo(helper.SearchBuild): |
|
|
93 |
basepath='' |
|
|
94 |
packageItems='' |
|
|
95 |
license='' |
|
|
96 |
|
|
|
97 |
# define basepath of the package |
|
|
98 |
def setbasepath(self, path): |
|
|
99 |
self.basepath=path |
|
|
100 |
|
|
|
101 |
# Build rules for: |
|
|
102 |
# - package.manifest |
|
|
103 |
# search for all files that we want to pack |
|
|
104 |
def doit(self, filename): |
|
|
105 |
artifacts = list() |
|
|
106 |
|
|
|
107 |
archname=filename[len(self.basepath)+1:] |
|
|
108 |
if filename.endswith(".project"): |
|
|
109 |
self.packageItems += ManifestItemProject % (archname) |
|
|
110 |
if filename.endswith(".devdesc.xml"): |
|
|
111 |
self.packageItems += ManifestItemDevDesc % (archname) |
|
|
112 |
if filename.endswith(".library"): |
|
|
113 |
self.packageItems += ManifestItemLibrary % (archname) |
|
|
114 |
if filename == "license.txt": |
|
|
115 |
self.license = archname; |
|
|
116 |
|
|
|
117 |
return artifacts |
|
|
118 |
|
|
|
119 |
def write(self, name, vendor, copyright, description): |
|
|
120 |
# add an empty license file if none was found |
|
|
121 |
if self.license == '': |
|
|
122 |
file = open(os.path.join(self.basepath, "license.txt"), "w") |
|
|
123 |
if file: |
|
|
124 |
file.write("No license file found.") |
|
|
125 |
file.close(); |
|
|
126 |
self.license = "license.txt" |
|
|
127 |
|
|
|
128 |
guid = uuid.uuid1(); |
|
|
129 |
packageManifest = ManifestSkeleton % (name, vendor, copyright, description, self.license, guid, self.packageItems) |
|
|
130 |
|
|
|
131 |
filename = os.path.join(self.basepath, 'package.manifest') |
|
|
132 |
file = open(filename, "w") |
|
|
133 |
if file: |
|
|
134 |
file.write(packageManifest) |
|
|
135 |
file.close(); |
|
|
136 |
self.artifacts.append(filename) |
|
|
137 |
|
|
|
138 |
|
|
|
139 |
packageFolders = list() |
|
|
140 |
# add trunk / master |
|
|
141 |
if os.path.isdir('trunk'): |
|
|
142 |
packageFolders.append('trunk') |
|
|
143 |
else: |
|
|
144 |
packageFolders.append('.') |
|
|
145 |
|
|
|
146 |
# add all branches |
|
|
147 |
if os.path.isdir('branches'): |
|
|
148 |
for filename in glob.iglob('branches/**'): |
|
|
149 |
if os.path.isdir(filename): |
|
|
150 |
packageFolders.append(filename) |
|
|
151 |
|
|
|
152 |
|
|
|
153 |
|
|
|
154 |
for folder in packageFolders: |
|
|
155 |
print ("creating manifest for folder %s." % folder) |
|
|
156 |
sb = SearchBuildDo() |
|
|
157 |
sb.setbasepath(folder) |
|
|
158 |
sb.search(".library", ".") |
|
|
159 |
sb.search(".project", ".") |
|
|
160 |
sb.search(".devdesc.xml", ".") |
|
|
161 |
sb.search("license.txt", ".") |
|
|
162 |
|
|
|
163 |
name = folder |
|
|
164 |
if name == ".": |
|
|
165 |
name = "master" |
|
|
166 |
sb.write(name, "unknown vendor", "unknown copyright", "no description") |
|
|
167 |
|
|
|
168 |
sb.save(".", ".drone-artifacts") |
|
|
169 |
|