-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathNppExec_npp_files_compare.py
96 lines (77 loc) · 3.03 KB
/
NppExec_npp_files_compare.py
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
import os
import shutil
import subprocess
import tempfile
from datetime import datetime
WINMERGE_EXE = "C:/Progs/Progs/WinMerge64/WinMergeU.exe"
RELATIVE_NPP_FILES_PATH = "NppExec/src/npp_files"
RELATIVE_NPP_PATH = ["../notepad-plus-plus-git/master.notepad-plus-plus", "../notepad-plus-plus"]
NPP_FILES = [
"PowerEditor/src/WinControls/DockingWnd/Docking.h",
"PowerEditor/src/menuCmdID.h",
"PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h",
"PowerEditor/src/MISC/PluginsManager/PluginInterface.h",
"scintilla/include/Sci_Position.h",
"scintilla/include/Scintilla.h",
"scintilla/include/BoostRegexSearch.h"
]
def run():
winmergeExe = os.path.normpath(WINMERGE_EXE)
if not os.path.isfile(winmergeExe):
showWarning("WinMerge.exe does not exist: {0}".format(winmergeExe))
return
nppFilesDir = os.path.normpath(os.path.join(getPyFileDir(), RELATIVE_NPP_FILES_PATH))
if not os.path.isdir(nppFilesDir):
showWarning("Directory does not exist: {0}".format(nppFilesDir))
return
tempDir = copyNppFilesToTempDir()
if tempDir:
try:
showMessage("Working directory: {0}".format(tempDir))
showMessage("Running WinMerge")
runWinMerge(winmergeExe, tempDir, nppFilesDir)
finally:
showMessage("Clean-up")
cleanup(tempDir)
def copyNppFilesToTempDir() -> str:
isNppDirExist = False
for relativePath in RELATIVE_NPP_PATH:
nppDir = os.path.normpath(os.path.join(getPyFileDir(), relativePath))
if os.path.isdir(nppDir):
isNppDirExist = True
break
if not isNppDirExist:
showWarning("Directory does not exist: {0}".format(nppDir))
return ""
tempDir = ""
nppFilePaths = []
for nppFile in NPP_FILES:
nppFilePath = os.path.normpath(os.path.join(nppDir, nppFile))
if os.path.isfile(nppFilePath):
nppFilePaths.append(nppFilePath)
else:
showWarning("File does not exist: {0}".format(nppFilePath))
if len(nppFilePaths) == len(NPP_FILES):
tempDir = getTempDirForNppFiles()
os.makedirs(tempDir)
for nppFilePath in nppFilePaths:
tempFilePath = os.path.join(tempDir, os.path.basename(nppFilePath))
shutil.copyfile(nppFilePath, tempFilePath)
return tempDir
def cleanup(tempDir: str):
shutil.rmtree(tempDir)
def runWinMerge(winmergeExe: str, srcDir: str, dstDir: str):
subprocess.run([winmergeExe, "/r", srcDir, dstDir])
def getTempDirForNppFiles() -> str:
now = datetime.now()
date_time = now.strftime("%Y%m%d_%H%M%S")
tempDir = tempfile.gettempdir()
return os.path.join(tempDir, "npp_files", date_time)
def getPyFileDir() -> str:
py_file_path = os.path.realpath(__file__)
return os.path.dirname(py_file_path)
def showMessage(message: str):
print(message)
def showWarning(message: str):
print("Warning: {0}".format(message))
run()