Skip to content

Commit 358c33c

Browse files
authored
修正了虚拟环境bug (#7)
1 parent dcf7d04 commit 358c33c

2,368 files changed

Lines changed: 71677 additions & 26 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Convert.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
var scriptFilePath = $.fileName; // .js位置
22
var scriptFolder = new File(scriptFilePath).parent.fsName; // .js文件夹
3-
var pythonPath = scriptFolder + "\\py3.9\\Scripts\\python.exe";
4-
var scriptPath = scriptFolder + "\\OpenCC_script.py";
3+
//var pythonPath = scriptFolder + "\\py3.9\\Scripts\\python.exe";
4+
//var scriptPath = scriptFolder + "\\OpenCC_script.py";
5+
var scriptPath = scriptFolder + "\\OpenCC_script.exe"
56
// get psd files
67
var inputFolder = Folder.selectDialog("选择包含PSD文件的文件夹");
78
var fileList = inputFolder.getFiles("*.psd");
@@ -51,9 +52,7 @@ function processLayers(layers) {
5152

5253
// 繁转简
5354
var convertedText = convertText(originalText);
54-
// textItem.contents = convertedText.replace(/\n/g, '\r'); // 需要修改换行符,否则乱码
5555
// var visibleText = convertedText.replace(/\n/g, '\\n'); // 检查换行符
56-
// logFile.writeln(visibleText)
5756

5857
// 设置字符属性
5958
// 更新文本图层的ActionDescriptor对象
@@ -88,10 +87,13 @@ function convertText(text) {
8887
inputFile.close();
8988

9089
// 运行 Python 脚本
91-
var command = pythonPath + ' "' + scriptPath + '" "' + inputFilePath + '" "' + outputFilePath + '" "' + logFilePath + '"';
90+
//var command = pythonPath + ' "' + scriptPath + '" "' + inputFilePath + '" "' + outputFilePath + '" "' + logFilePath + '"';
91+
var command = scriptPath + ' "' + inputFilePath + '" "' + outputFilePath + '" "' + logFilePath + '"';
9292
logFile.writeln("Running command: " + command);
9393
// logFile.writeln(Folder.current.fsName);
94-
app.system(command);
94+
var callback = system(command);
95+
if (callback != 0)
96+
logFile.writeln("Faild to run python command, callback: " + callback);
9597

9698
// 读取输出文件
9799
var outputFile = new File(outputFilePath);

OpenCC_script.exe

6.34 MB
Binary file not shown.

OpenCC_script.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@
1111
try:
1212
with open(log_file_path, 'a', encoding='utf-8') as f:
1313
f.write("Input: "+ input_file_path)
14-
# 读取输入文件
14+
# 读取输入文件
1515
with open(input_file_path, 'r', encoding = "utf-8") as f:
1616
text = f.read()
1717
f.close()
1818

19-
# 转换文本内容
19+
# 转换文本内容
2020
converted_text = cc.convert(text)
2121

22-
# 将转换后的文本内容写入输出文件
22+
# 将转换后的文本内容写入输出文件
2323
with open(output_file_path, 'w', encoding = "utf-8") as f:
2424
f.write(converted_text)
2525
f.close()
2626
except Exception as e:
27-
# 将错误信息写入日志文件
27+
# 将错误信息写入日志文件
2828
with open(log_file_path, 'a', encoding='utf-8') as f:
2929
f.write("Error while running Python script: " + str(e) + "\n")

OpenCC_script.spec

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# -*- mode: python ; coding: utf-8 -*-
2+
3+
4+
block_cipher = None
5+
6+
7+
a = Analysis(
8+
['OpenCC_script.py'],
9+
pathex=[],
10+
binaries=[],
11+
datas=[],
12+
hiddenimports=[],
13+
hookspath=[],
14+
hooksconfig={},
15+
runtime_hooks=[],
16+
excludes=[],
17+
win_no_prefer_redirects=False,
18+
win_private_assemblies=False,
19+
cipher=block_cipher,
20+
noarchive=False,
21+
)
22+
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
23+
24+
exe = EXE(
25+
pyz,
26+
a.scripts,
27+
a.binaries,
28+
a.zipfiles,
29+
a.datas,
30+
[],
31+
name='OpenCC_script',
32+
debug=False,
33+
bootloader_ignore_signals=False,
34+
strip=False,
35+
upx=True,
36+
upx_exclude=[],
37+
runtime_tmpdir=None,
38+
console=True,
39+
disable_windowed_traceback=False,
40+
argv_emulation=False,
41+
target_arch=None,
42+
codesign_identity=None,
43+
entitlements_file=None,
44+
)

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,12 @@
3232

3333
这个问题是因为换行符是`\r`,而不是`\n`,因此需要用.replace()`改过来。
3434

35+
36+
37+
# 2023/9/16 Fixed
38+
39+
1. 在其他主机上不能调用py脚本,推测是虚拟环境问题
40+
41+
修的比较赶,暂时先改用可执行文件的形式。
42+
43+
> 感谢@银河猫喵喵帮忙debug\^_\^

0 commit comments

Comments
 (0)