File: setup_kit_files.py

package info (click to toggle)
pysvn 1.9.22-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,212 kB
  • sloc: cpp: 20,327; python: 5,485; sh: 869; javascript: 57; makefile: 56; ansic: 52
file content (181 lines) | stat: -rw-r--r-- 7,181 bytes parent folder | download
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
171
172
173
174
175
176
177
178
179
180
181
import sys
import time
import os
import datetime

def main( argv ):
    print( 'Info: setup_kit_files.py' )
    inno = InnoSetup( argv )
    return inno.createInnoInstall()

class InnoSetup:
    def __init__( self, argv ):

        self.arch = sys.argv[1]
        self.vc_ver = sys.argv[2]

        # Must not use relative parh to sources becuase DLLs will not be loaded
        # by python 3.8 because of the Windows trusted DLL folders feature.
        sys.path.insert( 0, os.path.abspath( r'..\..\Source' ) )
        import pysvn

        self.py_maj = sys.version_info[0]
        self.py_min = sys.version_info[1]

        self.python_version_string = '%d.%d.%d' % (self.py_maj, self.py_min, sys.version_info[2])
        self.pysvn_version_string = '%d.%d.%d-%d' % (pysvn.version[0], pysvn.version[1], pysvn.version[2], pysvn.version[3])
        self.svn_version_package_string = '%d%d%d' % (pysvn.svn_version[0], pysvn.svn_version[1], pysvn.svn_version[2])
        self.svn_version_string = '%d.%d.%d' % (pysvn.svn_version[0], pysvn.svn_version[1], pysvn.svn_version[2])

        self.build_time  = time.time()
        self.build_time_str = time.strftime( '%d-%b-%Y %H:%M', time.localtime( self.build_time ) )

        self.year = datetime.datetime.now().year

        self.all_code_items = []
        self.all_setup_items = []
        self.all_file_items = []
        self.all_icon_items = []
        self.all_run_items = []

    def createInnoInstall( self ):
        self.setupInnoItems()
        self.generateInnoFile()

    def setupInnoItems( self ):
        print( 'Info: Create info_before.txt' )

        f = open( r'tmp\info_before.txt', 'w' )
        f.write(
'''PySVN %s for %s Python %s and Subversion %s

    Barry Scott

    %s

''' % (self.pysvn_version_string, self.arch, self.python_version_string, self.svn_version_string, self.build_time_str) )
        f.close()

        print( 'Info: Create setup_copy.cmd' )
        f = open( r'tmp\setup_copy.cmd', 'w' )
        f.write( r'copy tmp\Output\mysetup.exe tmp\Output\py%d%d-pysvn-svn%s-%s-%s.exe' '\n' %
                    (self.py_maj, self.py_min, self.svn_version_package_string, self.pysvn_version_string, self.arch) )
        f.close()

        self.all_setup_items.extend( [
                r'AppName=Python %(py_maj)d.%(py_min)d PySVN for %(arch)s' % self.__dict__,
                r'AppVerName=Python %(py_maj)d.%(py_min)d PySVN %(pysvn_version_string)s on %(arch)s' % self.__dict__,
                r'AppCopyright=Copyright (C) 2003-%(year)s Barry A. Scott' % self.__dict__,
                r'DefaultDirName={code:pythondir}\lib\site-packages\pysvn',
                r'DefaultGroupName=PySVN for Python %(py_maj)d.%(py_min)d on %(arch)s' % self.__dict__,
                r'DisableStartupPrompt=yes',
                r'InfoBeforeFile=info_before.txt',
                r'Compression=bzip/9',
                ] )

        self.all_icon_items.extend( [
                r'Name: "{group}\PySVN Documentation"; Filename: "{app}\pysvn.html";',
                r'Name: "{group}\PySVN License"; Filename: "{app}\pysvn_LICENSE.txt";',
                r'Name: "{group}\PySVN Web Site"; Filename: "https://pysvn.sourceforge.io";',
                ] )

        self.all_file_items.extend( [
                r'Source: "..\..\..\Source\pysvn\__init__.py"; DestDir: "{app}";',
                r'Source: "..\..\..\Source\pysvn\_pysvn_%(py_maj)d_%(py_min)d.pyd"; DestDir: "{app}"; Flags: ignoreversion;' % self.__dict__,
                r'Source: "..\..\..\Docs\pysvn.html"; DestDir: "{app}";',
                r'Source: "..\..\..\Docs\pysvn_prog_guide.html"; DestDir: "{app}";',
                r'Source: "..\..\..\Docs\pysvn_prog_ref.html"; DestDir: "{app}";',
                r'Source: "..\..\..\Docs\pysvn_prog_ref.js"; DestDir: "{app}";',
                r'Source: "LICENSE.txt"; DestDir: "{app}";',
                r'',
                r'Source: "..\..\..\Examples\Client\svn_cmd.py"; DestDir: "{app}\Examples\Client";',
                r'Source: "..\..\..\Examples\Client\parse_datetime.py"; DestDir: "{app}\Examples\Client";',
                ] )

        for dll_name in [dll for dll in os.listdir( os.path.abspath( r'..\..\Source\pysvn' ) ) if dll.lower().endswith( '.dll' )]:
            dll = os.path.abspath( os.path.join( r'..\..\Source\pysvn', dll_name ) )
            self.all_file_items.append( 'Source: "%s"; DestDir: "{app}"; Flags: ignoreversion' % (dll,) )

        if self.vc_ver == '9.0':
            redist_year = '2008'

        elif self.vc_ver == '10.0':
            redist_year = '2010'

        elif self.vc_ver == '14.0':
            redist_year = '2015'

        elif self.vc_ver == '14.1':
            redist_year = '2015'

        elif self.vc_ver == '14.2':
            redist_year = '2015'

        else:
            print( 'Error: Unsupported VC_VER of %s' % (self.vc_ver,) )
            return 1

        if self.arch == 'Win32':
            redist_arch = 'x86'
            code_file = 'pysvn_win32_code.iss'

        elif self.arch == 'Win64':
            redist_arch = 'x64'
            code_file = 'pysvn_win64_code.iss'
            self.all_setup_items.append( 'ArchitecturesAllowed=x64' )
            self.all_setup_items.append( 'ArchitecturesInstallIn64BitMode=x64' )

        else:
            print( 'Error: Unsupported ARCH of %s' % (self.arch,) )
            return 1

        f = open( code_file, 'r' )
        self.all_code_items.append( f.read() % self.__dict__ )
        f.close()

        redist_file = 'vcredist_%s_%s.exe' % (redist_arch, redist_year)

        os.system( r'copy k:\subversion\%s tmp' % (redist_file,) )

        self.all_file_items.append( 'Source: "%s"; DestDir: {tmp}; Flags: deleteafterinstall' %
                                    (redist_file,) )
        self.all_run_items.append( r'Filename: {tmp}\%s; Parameters: "/q"; StatusMsg: Installing VC++ %s %s Redistributables...' %
                                    (redist_file, redist_year, self.arch) )

    def generateInnoFile( self ):
        inno_file = r'tmp\pysvn.iss'
        print( 'Info: Generating %s' % (inno_file,) )
        f = open( inno_file, 'w' )

        f.write( '[Code]\n' )
        for item in self.all_code_items:
            f.write( item )
            f.write( '\n' )

        f.write( '[Setup]\n' )
        for item in self.all_setup_items:
            f.write( item )
            f.write( '\n' )

        f.write( '[Files]\n' )
        for item in self.all_file_items:
            f.write( item )
            f.write( '\n' )

        f.write( '[Icons]\n' )
        for item in self.all_icon_items:
            f.write( item )
            f.write( '\n' )

        f.write( '[Run]\n' )
        for item in self.all_run_items:
            f.write( item )
            f.write( '\n' )

        f.write( r'[UninstallDelete]' '\n' )
        f.write( r'Type: filesandordirs; Name: "{app}\__pycache__"' '\n' )

        f.close()

if __name__ == '__main__':
    sys.exit( main( sys.argv ) )