Commit MetaInfo

修订版db9ba1f5919e0a20d53b9e2a188ccc3e14a88d42 (tree)
时间2019-10-21 02:01:54
作者Benjamin Berkels <torr.samaho@quan...>
CommiterBenjamin Berkels

Log Message

autopep8

更改概述

差异

diff -r 5e2a748f11bf -r db9ba1f5919e zaninstaller.py
--- a/zaninstaller.py Mon Jul 03 01:23:54 2017 +0300
+++ b/zaninstaller.py Sun Oct 20 19:01:54 2019 +0200
@@ -7,15 +7,18 @@
77
88 INSTRUCTIONS_FILE = ".instructions.txt"
99
10+
1011 class InstallerGenError (Exception):
1112 pass
1213
14+
1315 def quote(string):
1416 if '"' in string:
1517 return "'" + string + "'"
1618 else:
1719 return '"' + string + '"'
1820
21+
1922 def getInstallFilePaths(base):
2023 '''Returns a dictionary of files to install. The function is supplied the base path to walk
2124 through. The dictionary has two elements:
@@ -36,38 +39,45 @@
3639
3740 # We should have at least one file.
3841 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?")
4044
4145 return filedict
4246 finally:
4347 os.chdir(oldpath)
4448
49+
4550 def readFragment(filename, args):
4651 '''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)
4853
4954 try:
50- with open (fragmentPath, 'r') as fp:
55+ with open(fragmentPath, 'r') as fp:
5156 return fp.read()
5257 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)
5460
55-def getFileinfoPaths (fileinfo):
61+
62+def getFileinfoPaths(fileinfo):
5663 '''Gets the directory names from the fileinfo. Paths aree sorted case-insensitively.'''
5764 return sorted(fileinfo['files'].keys(), key=str.lower)
5865
59-def generateInstaller (fileinfo):
66+
67+def generateInstaller(fileinfo):
6068 '''Generates the installer NSIS script'''
6169 outlines = []
62- for installpath in getFileinfoPaths (fileinfo):
70+ for installpath in getFileinfoPaths(fileinfo):
6371 outlines.append(" SetOutPath " + quote("$INSTDIR\\" + installpath))
6472 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))
6675 return '\n'.join(outlines)
6776
68-def generateUninstaller (fileinfo):
77+
78+def generateUninstaller(fileinfo):
6979 '''Generates the uninstaller NSIS script'''
70- paths = getFileinfoPaths (fileinfo)
80+ paths = getFileinfoPaths(fileinfo)
7181 outlines = []
7282 for installpath in paths:
7383 outlines.append(" SetOutPath " + quote("$INSTDIR\\" + installpath))
@@ -75,22 +85,26 @@
7585 outlines.append(" Delete /REBOOTOK " + quote(filepath))
7686 outlines.append(" SetOutPath $TEMP")
7787 for installpath in paths[::-1]:
78- outlines.append(" RmDir /REBOOTOK " + quote("$INSTDIR\\" + installpath))
88+ outlines.append(" RmDir /REBOOTOK " +
89+ quote("$INSTDIR\\" + installpath))
7990 return '\n'.join(outlines)
8091
92+
8193 def main():
8294 '''The main installer routine'''
8395 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')
89102 args = parser.parse_args()
90103
91104 # No spaces should be in the version number.
92105 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).")
94108
95109 filePaths = getInstallFilePaths(args.files_path)
96110
@@ -117,14 +131,15 @@
117131 textoutput += generateUninstaller(filePaths)
118132
119133 # 7) Append the footer.
120- textoutput += readFragment ('footer.txt', args=args)
134+ textoutput += readFragment('footer.txt', args=args)
121135
122136 # Write it to the installer file.
123137 with open(args.output, "w") as f:
124138 f.write(textoutput)
125139 print(args.output, "written")
126140 except InstallerGenError as e:
127- print ('Error:', e, file=sys.stderr)
141+ print('Error:', e, file=sys.stderr)
142+
128143
129144 if __name__ == '__main__':
130145 main()
Show on old repository browser