[33fdb3]: / codesys-ide / scripts / gen-package-manifest.py  Maximize  Restore  History

Download this file

171 lines (148 with data), 4.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import sys, os, glob
import uuid
import helper

ManifestSkeleton="""<?xml version="1.0" encoding="ISO-8859-1"?>
<Package>
  <Strings>
    <String Id="GeneralName">
      <Neutral>%s</Neutral>
    </String>
    <String Id="GeneralVendor">
      <Neutral>%s</Neutral>
    </String>
    <String Id="GeneralCopyright">
      <Neutral>%s</Neutral>
    </String>
    <String Id="GeneralDescription">
      <Neutral>%s</Neutral>
    </String>    
    <String Id="license">
      <Neutral>%s</Neutral>
    </String>        
    <String Id="TargetDir">
      <Neutral>Target directory</Neutral>
    </String>
    <String Id="TargetDirDescription">
      <Neutral>The target directory where the projects are saved.</Neutral>
    </String>
  </Strings>
  <General>
    <Id>{%s}</Id>
    <Version>1.0.0.0</Version>
    <Name>$GeneralName</Name>
    <Vendor>$GeneralVendor</Vendor>
    <Copyright>$GeneralCopyright</Copyright>
    <Description>$GeneralDescription</Description>    
    <LicenseAgreement>$license</LicenseAgreement>        
    <RequiredInstallerVersion>3.5.10.0</RequiredInstallerVersion>
  </General>
  <TargetDirectoryDefinitions>  
    <TargetDirectoryDefinition>
      <Id>1</Id>
      <Name>$TargetDir</Name>
      <Description>$TargetDirDescription</Description>
      <PromptUser>True</PromptUser>
      <DefaultValue>%%USERPROFILE%%\CODESYS Projects\</DefaultValue>
    </TargetDirectoryDefinition>
  </TargetDirectoryDefinitions>
  <Components>                
    <Component>
      <General>
    <Id>1</Id>
    <Name>Default</Name>
    <Description>Default Package</Description>
    <Selectable>false</Selectable>
    <SelectedByDefault>true</SelectedByDefault>
      </General>
      <Dependencies>            
      </Dependencies>
      <Items>
%s
      </Items>            
    </Component>     
  </Components>
</Package>
"""

ManifestItemLibrary = """
        <Library>
          <Path>%s</Path>
        </Library>
"""

ManifestItemDevDesc = """
        <DeviceDescription>
          <Path>%s</Path>
        </DeviceDescription>
"""

ManifestItemProject = """
        <File>
          <Path>%s</Path>
          <IgnoreArchiveFolder>True</IgnoreArchiveFolder>
          <TargetFolder>$1</TargetFolder>
          <Overwrite>
            <Option>Yes</Option>
          </Overwrite>
        </File>
"""


class SearchBuildDo(helper.SearchBuild):
    basepath=''
    packageItems=''
    license=''

    # define basepath of the package
    def setbasepath(self, path):
       self.basepath=path

    # Build rules for:
    # - package.manifest
    # search for all files that we want to pack
    def doit(self, filename):
        artifacts = list()

        archname=filename[len(self.basepath)+1:]
        if filename.endswith(".project"):
            self.packageItems += ManifestItemProject % (archname)
        if filename.endswith(".devdesc.xml"):
            self.packageItems += ManifestItemDevDesc % (archname)
        if filename.endswith(".library"):
            self.packageItems += ManifestItemLibrary % (archname)
        if filename == "license.txt":
            self.license = archname;

        return artifacts

    def write(self, name, vendor, copyright, description):
        # add an empty license file if none was found
        if self.license == '':
            file = open(os.path.join(self.basepath, "license.txt"), "w")
            if file:
                file.write("No license file found.")
                file.close();
            self.license = "license.txt"

        guid = uuid.uuid1();
        packageManifest = ManifestSkeleton % (name, vendor, copyright, description, self.license, guid, self.packageItems)

        filename = os.path.join(self.basepath, 'package.manifest')
        if not os.path.isfile(filename):
            file = open(filename, "w")
            if file:
                file.write(packageManifest)
                file.close();
            self.artifacts.append(filename)


packageFolders = list()
# add trunk / master
if os.path.isdir('trunk'):
    packageFolders.append('trunk')
else:
    packageFolders.append('.')

# add all branches
if os.path.isdir('branches'):
    for filename in glob.iglob('branches/**'):
        if os.path.isdir(filename):
            packageFolders.append(filename)



for folder in packageFolders:
    print ("creating manifest for folder %s." % folder)
    sb = SearchBuildDo()
    sb.setbasepath(folder)
    sb.search(".library", ".")
    sb.search(".project", ".")
    sb.search(".devdesc.xml", ".")
    sb.search("license.txt", ".")

    name = folder
    if name == ".":
        name = "master"
    sb.write(name, "unknown vendor", "unknown copyright", "no description")

    sb.save(".", ".drone-artifacts")