diff options
author | Neil <nyamatongwe@gmail.com> | 2020-05-19 12:39:23 +1000 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2020-05-19 12:39:23 +1000 |
commit | ef98916585104cb893bdd7dd8f4bf91313639baf (patch) | |
tree | c2ad417ec36019c56d9cfb51d90e8f665623f807 /scripts | |
parent | 868780c1a7b664d0453c3921baed3ddfa5a2e4c3 (diff) | |
download | scintilla-mirror-ef98916585104cb893bdd7dd8f4bf91313639baf.tar.gz |
Use pathlib in generator scripts.
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/HFacer.py | 13 | ||||
-rw-r--r-- | scripts/LexGen.py | 39 | ||||
-rw-r--r-- | scripts/ScintillaData.py | 35 |
3 files changed, 42 insertions, 45 deletions
diff --git a/scripts/HFacer.py b/scripts/HFacer.py index 1e93d688a..d32054ec9 100755 --- a/scripts/HFacer.py +++ b/scripts/HFacer.py @@ -2,10 +2,9 @@ # HFacer.py - regenerate the Scintilla.h and SciLexer.h files from the Scintilla.iface interface # definition file. # Implemented 2000 by Neil Hodgson neilh@scintilla.org -# Requires Python 2.7 or later +# Requires Python 3.6 or later -import sys -import os +import pathlib import Face from FileGenerator import UpdateFile, Generate, Regenerate, UpdateLineInFile, lineEnd @@ -45,9 +44,9 @@ def printHFile(f): def RegenerateAll(root, showMaxID): f = Face.Face() - f.ReadFromFile(root + "include/Scintilla.iface") - Regenerate(root + "include/Scintilla.h", "/* ", printHFile(f)) - Regenerate(root + "include/SciLexer.h", "/* ", printLexHFile(f)) + f.ReadFromFile(root / "include/Scintilla.iface") + Regenerate(root / "include/Scintilla.h", "/* ", printHFile(f)) + Regenerate(root / "include/SciLexer.h", "/* ", printLexHFile(f)) if showMaxID: valueSet = set(int(x) for x in f.values if int(x) < 3000) maximumID = max(valueSet) @@ -58,4 +57,4 @@ def RegenerateAll(root, showMaxID): #~ print(v) if __name__ == "__main__": - RegenerateAll("../", True) + RegenerateAll(pathlib.Path(__file__).resolve().parent.parent, True) diff --git a/scripts/LexGen.py b/scripts/LexGen.py index f804feb70..0aaabbc9f 100644 --- a/scripts/LexGen.py +++ b/scripts/LexGen.py @@ -14,6 +14,7 @@ from FileGenerator import Regenerate, UpdateLineInFile, \ import ScintillaData import HFacer import os +import pathlib import uuid import sys @@ -24,34 +25,34 @@ import win32.DepGen import gtk.DepGen def UpdateVersionNumbers(sci, root): - UpdateLineInFile(root + "win32/ScintRes.rc", "#define VERSION_SCINTILLA", + UpdateLineInFile(root / "win32/ScintRes.rc", "#define VERSION_SCINTILLA", "#define VERSION_SCINTILLA \"" + sci.versionDotted + "\"") - UpdateLineInFile(root + "win32/ScintRes.rc", "#define VERSION_WORDS", + UpdateLineInFile(root / "win32/ScintRes.rc", "#define VERSION_WORDS", "#define VERSION_WORDS " + sci.versionCommad) - UpdateLineInFile(root + "qt/ScintillaEditBase/ScintillaEditBase.pro", + UpdateLineInFile(root / "qt/ScintillaEditBase/ScintillaEditBase.pro", "VERSION =", "VERSION = " + sci.versionDotted) - UpdateLineInFile(root + "qt/ScintillaEdit/ScintillaEdit.pro", + UpdateLineInFile(root / "qt/ScintillaEdit/ScintillaEdit.pro", "VERSION =", "VERSION = " + sci.versionDotted) - UpdateLineInFile(root + "doc/ScintillaDownload.html", " Release", + UpdateLineInFile(root / "doc/ScintillaDownload.html", " Release", " Release " + sci.versionDotted) - ReplaceREInFile(root + "doc/ScintillaDownload.html", + ReplaceREInFile(root / "doc/ScintillaDownload.html", r"/www.scintilla.org/([a-zA-Z]+)\d\d\d", r"/www.scintilla.org/\g<1>" + sci.version) - UpdateLineInFile(root + "doc/index.html", + UpdateLineInFile(root / "doc/index.html", ' <font color="#FFCC99" size="3"> Release version', ' <font color="#FFCC99" size="3"> Release version ' +\ sci.versionDotted + '<br />') - UpdateLineInFile(root + "doc/index.html", + UpdateLineInFile(root / "doc/index.html", ' Site last modified', ' Site last modified ' + sci.mdyModified + '</font>') - UpdateLineInFile(root + "doc/ScintillaHistory.html", + UpdateLineInFile(root / "doc/ScintillaHistory.html", ' Released ', ' Released ' + sci.dmyModified + '.') - UpdateLineInPlistFile(root + "cocoa/ScintillaFramework/Info.plist", + UpdateLineInPlistFile(root / "cocoa/ScintillaFramework/Info.plist", "CFBundleVersion", sci.versionDotted) - UpdateLineInPlistFile(root + "cocoa/ScintillaFramework/Info.plist", + UpdateLineInPlistFile(root / "cocoa/ScintillaFramework/Info.plist", "CFBundleShortVersionString", sci.versionDotted) # Last 24 digits of UUID, used for item IDs in Xcode @@ -116,14 +117,16 @@ def RegenerateXcodeProject(path, lexers, lexerReferences): UpdateFileFromLines(path, lines, "\n") -def RegenerateAll(root): +def RegenerateAll(rootDirectory): + + root = pathlib.Path(rootDirectory) - scintillaBase = os.path.abspath(root) + scintillaBase = root.resolve() - sci = ScintillaData.ScintillaData(root) + sci = ScintillaData.ScintillaData(scintillaBase) - Regenerate(root + "src/Catalogue.cxx", "//", sci.lexerModules) - Regenerate(root + "win32/scintilla.mak", "#", sci.lexFiles) + Regenerate(scintillaBase / "src/Catalogue.cxx", "//", sci.lexerModules) + Regenerate(scintillaBase / "win32/scintilla.mak", "#", sci.lexFiles) startDir = os.getcwd() os.chdir(os.path.join(scintillaBase, "win32")) @@ -132,7 +135,7 @@ def RegenerateAll(root): gtk.DepGen.Generate() os.chdir(startDir) - RegenerateXcodeProject(root + "cocoa/ScintillaFramework/ScintillaFramework.xcodeproj/project.pbxproj", + RegenerateXcodeProject(root / "cocoa/ScintillaFramework/ScintillaFramework.xcodeproj/project.pbxproj", sci.lexFiles, sci.lexersXcode) UpdateVersionNumbers(sci, root) @@ -140,4 +143,4 @@ def RegenerateAll(root): HFacer.RegenerateAll(root, False) if __name__=="__main__": - RegenerateAll("../") + RegenerateAll(pathlib.Path(__file__).resolve().parent.parent) diff --git a/scripts/ScintillaData.py b/scripts/ScintillaData.py index 5bb9fb1bc..1d9537d03 100644 --- a/scripts/ScintillaData.py +++ b/scripts/ScintillaData.py @@ -33,16 +33,14 @@ # This file can be run to see the data it provides. # Requires Python 3.6 or later -from __future__ import with_statement - -import codecs, datetime, glob, os, sys, textwrap +import datetime, pathlib, sys, textwrap import FileGenerator def FindModules(lexFile): modules = [] partLine = "" - with open(lexFile) as f: + with lexFile.open() as f: for l in f.readlines(): l = l.rstrip() if partLine or l.startswith("LexerModule"): @@ -116,7 +114,7 @@ def FindProperties(lexFile): def FindPropertyDocumentation(lexFile): documents = {} - with open(lexFile) as f: + with lexFile.open() as f: name = "" for l in f.readlines(): l = l.strip() @@ -158,7 +156,7 @@ def FindPropertyDocumentation(lexFile): def FindCredits(historyFile): credits = [] stage = 0 - with codecs.open(historyFile, "r", "utf-8") as f: + with historyFile.open(encoding="utf-8") as f: for l in f.readlines(): l = l.strip() if stage == 0 and l == "<table>": @@ -180,7 +178,7 @@ def FindCredits(historyFile): return credits def ciKey(a): - return a.lower() + return str(a).lower() def SortListInsensitive(l): l.sort(key=ciKey) @@ -188,13 +186,12 @@ def SortListInsensitive(l): class ScintillaData: def __init__(self, scintillaRoot): # Discover version information - with open(scintillaRoot + "version.txt") as f: - self.version = f.read().strip() + self.version = (scintillaRoot / "version.txt").read_text().strip() self.versionDotted = self.version[0] + '.' + self.version[1] + '.' + \ self.version[2] self.versionCommad = self.versionDotted.replace(".", ", ") + ', 0' - with open(scintillaRoot + "doc/index.html") as f: + with (scintillaRoot / "doc" / "index.html").open() as f: self.dateModified = [l for l in f.readlines() if "Date.Modified" in l]\ [0].split('\"')[3] # 20130602 @@ -212,9 +209,9 @@ class ScintillaData: self.myModified = monthModified + " " + self.yearModified # Find all the lexer source code files - lexFilePaths = glob.glob(scintillaRoot + "lexers/Lex*.cxx") + lexFilePaths = list((scintillaRoot / "lexers").glob("Lex*.cxx")) SortListInsensitive(lexFilePaths) - self.lexFiles = [os.path.basename(f)[:-4] for f in lexFilePaths] + self.lexFiles = [f.stem for f in lexFilePaths] self.lexerModules = [] lexerProperties = set() self.propertyDocuments = {} @@ -236,14 +233,15 @@ class ScintillaData: self.lexerProperties = list(lexerProperties) SortListInsensitive(self.lexerProperties) - self.lexersXcode = FindLexersInXcode(scintillaRoot + "cocoa/ScintillaFramework/ScintillaFramework.xcodeproj/project.pbxproj") - self.credits = FindCredits(scintillaRoot + "doc/ScintillaHistory.html") + self.lexersXcode = FindLexersInXcode(scintillaRoot / + "cocoa/ScintillaFramework/ScintillaFramework.xcodeproj/project.pbxproj") + self.credits = FindCredits(scintillaRoot / "doc" / "ScintillaHistory.html") def printWrapped(text): print(textwrap.fill(text, subsequent_indent=" ")) if __name__=="__main__": - sci = ScintillaData("../") + sci = ScintillaData(pathlib.Path(__file__).resolve().parent.parent) print("Version %s %s %s" % (sci.version, sci.versionDotted, sci.versionCommad)) print("Date last modified %s %s %s %s %s" % ( sci.dateModified, sci.yearModified, sci.mdyModified, sci.dmyModified, sci.myModified)) @@ -255,7 +253,7 @@ if __name__=="__main__": lexNames = sorted(sci.sclexFromName.keys()) for lexName in lexNames: sclex = sci.sclexFromName[lexName] - fileName = os.path.basename(sci.fileFromSclex[sclex]) + fileName = sci.fileFromSclex[sclex].name print(" " + lexName + " -> " + sclex + " in " + fileName) printWrapped("Lexer properties: " + ", ".join(sci.lexerProperties)) print("Lexer property documentation:") @@ -267,7 +265,4 @@ if __name__=="__main__": subsequent_indent=" ")) print("Credits:") for c in sci.credits: - if sys.version_info[0] == 2: - print(" " + c.encode("utf-8")) - else: - sys.stdout.buffer.write(b" " + c.encode("utf-8") + b"\n") + sys.stdout.buffer.write(b" " + c.encode("utf-8") + b"\n") |