Revision | db9ba1f5919e0a20d53b9e2a188ccc3e14a88d42 (tree) |
---|---|
Time | 2019-10-21 02:01:54 |
Author | Benjamin Berkels <torr.samaho@quan...> |
Commiter | Benjamin Berkels |
autopep8
@@ -7,15 +7,18 @@ | ||
7 | 7 | |
8 | 8 | INSTRUCTIONS_FILE = ".instructions.txt" |
9 | 9 | |
10 | + | |
10 | 11 | class InstallerGenError (Exception): |
11 | 12 | pass |
12 | 13 | |
14 | + | |
13 | 15 | def quote(string): |
14 | 16 | if '"' in string: |
15 | 17 | return "'" + string + "'" |
16 | 18 | else: |
17 | 19 | return '"' + string + '"' |
18 | 20 | |
21 | + | |
19 | 22 | def getInstallFilePaths(base): |
20 | 23 | '''Returns a dictionary of files to install. The function is supplied the base path to walk |
21 | 24 | through. The dictionary has two elements: |
@@ -36,38 +39,45 @@ | ||
36 | 39 | |
37 | 40 | # We should have at least one file. |
38 | 41 | if not filedict['files']: |
39 | - raise InstallerGenError("No files detected in the " + base + " folder, are you sure you set this up correctly?") | |
42 | + raise InstallerGenError("No files detected in the " + | |
43 | + base + " folder, are you sure you set this up correctly?") | |
40 | 44 | |
41 | 45 | return filedict |
42 | 46 | finally: |
43 | 47 | os.chdir(oldpath) |
44 | 48 | |
49 | + | |
45 | 50 | def readFragment(filename, args): |
46 | 51 | '''Reads a file from the fragmens directory''' |
47 | - fragmentPath = os.path.join (args.fragments_path, filename) | |
52 | + fragmentPath = os.path.join(args.fragments_path, filename) | |
48 | 53 | |
49 | 54 | try: |
50 | - with open (fragmentPath, 'r') as fp: | |
55 | + with open(fragmentPath, 'r') as fp: | |
51 | 56 | return fp.read() |
52 | 57 | except FileNotFoundError: |
53 | - raise InstallerGenError("You are missing a core NSIS text file:", fragmentPath) | |
58 | + raise InstallerGenError( | |
59 | + "You are missing a core NSIS text file:", fragmentPath) | |
54 | 60 | |
55 | -def getFileinfoPaths (fileinfo): | |
61 | + | |
62 | +def getFileinfoPaths(fileinfo): | |
56 | 63 | '''Gets the directory names from the fileinfo. Paths aree sorted case-insensitively.''' |
57 | 64 | return sorted(fileinfo['files'].keys(), key=str.lower) |
58 | 65 | |
59 | -def generateInstaller (fileinfo): | |
66 | + | |
67 | +def generateInstaller(fileinfo): | |
60 | 68 | '''Generates the installer NSIS script''' |
61 | 69 | outlines = [] |
62 | - for installpath in getFileinfoPaths (fileinfo): | |
70 | + for installpath in getFileinfoPaths(fileinfo): | |
63 | 71 | outlines.append(" SetOutPath " + quote("$INSTDIR\\" + installpath)) |
64 | 72 | for filepath in fileinfo['files'][installpath]: |
65 | - outlines.append(" File " + quote(fileinfo['basepath'] + installpath + filepath)) | |
73 | + outlines.append(" File " + | |
74 | + quote(fileinfo['basepath'] + installpath + filepath)) | |
66 | 75 | return '\n'.join(outlines) |
67 | 76 | |
68 | -def generateUninstaller (fileinfo): | |
77 | + | |
78 | +def generateUninstaller(fileinfo): | |
69 | 79 | '''Generates the uninstaller NSIS script''' |
70 | - paths = getFileinfoPaths (fileinfo) | |
80 | + paths = getFileinfoPaths(fileinfo) | |
71 | 81 | outlines = [] |
72 | 82 | for installpath in paths: |
73 | 83 | outlines.append(" SetOutPath " + quote("$INSTDIR\\" + installpath)) |
@@ -75,22 +85,26 @@ | ||
75 | 85 | outlines.append(" Delete /REBOOTOK " + quote(filepath)) |
76 | 86 | outlines.append(" SetOutPath $TEMP") |
77 | 87 | for installpath in paths[::-1]: |
78 | - outlines.append(" RmDir /REBOOTOK " + quote("$INSTDIR\\" + installpath)) | |
88 | + outlines.append(" RmDir /REBOOTOK " + | |
89 | + quote("$INSTDIR\\" + installpath)) | |
79 | 90 | return '\n'.join(outlines) |
80 | 91 | |
92 | + | |
81 | 93 | def main(): |
82 | 94 | '''The main installer routine''' |
83 | 95 | try: |
84 | - parser = argparse.ArgumentParser (description='Generates an NSIS installer script for Zandronum') | |
85 | - parser.add_argument ('version') | |
86 | - parser.add_argument ('-o', '--output', default='ZanInstaller.nsi') | |
87 | - parser.add_argument ('--fragments-path', default='fragments') | |
88 | - parser.add_argument ('--files-path', default='files') | |
96 | + parser = argparse.ArgumentParser( | |
97 | + description='Generates an NSIS installer script for Zandronum') | |
98 | + parser.add_argument('version') | |
99 | + parser.add_argument('-o', '--output', default='ZanInstaller.nsi') | |
100 | + parser.add_argument('--fragments-path', default='fragments') | |
101 | + parser.add_argument('--files-path', default='files') | |
89 | 102 | args = parser.parse_args() |
90 | 103 | |
91 | 104 | # No spaces should be in the version number. |
92 | 105 | if ' ' in args.version: |
93 | - raise InstallerGenError("You should not have spaces in the argument (try underscores or hyphens).") | |
106 | + raise InstallerGenError( | |
107 | + "You should not have spaces in the argument (try underscores or hyphens).") | |
94 | 108 | |
95 | 109 | filePaths = getInstallFilePaths(args.files_path) |
96 | 110 |
@@ -117,14 +131,15 @@ | ||
117 | 131 | textoutput += generateUninstaller(filePaths) |
118 | 132 | |
119 | 133 | # 7) Append the footer. |
120 | - textoutput += readFragment ('footer.txt', args=args) | |
134 | + textoutput += readFragment('footer.txt', args=args) | |
121 | 135 | |
122 | 136 | # Write it to the installer file. |
123 | 137 | with open(args.output, "w") as f: |
124 | 138 | f.write(textoutput) |
125 | 139 | print(args.output, "written") |
126 | 140 | except InstallerGenError as e: |
127 | - print ('Error:', e, file=sys.stderr) | |
141 | + print('Error:', e, file=sys.stderr) | |
142 | + | |
128 | 143 | |
129 | 144 | if __name__ == '__main__': |
130 | 145 | main() |