forked from seblavoie/sublime-extendscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtendScript.py
99 lines (73 loc) · 2.77 KB
/
ExtendScript.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
97
98
99
import os
import sys
import fileinput
import re
import shutil
import subprocess
import sublime
import sublime_plugin
class ExtendScriptCommand(sublime_plugin.TextCommand):
def init(self):
self.currentFile = self.view.file_name()
self.currentPath = os.path.dirname(self.currentFile)
self.settings = sublime.load_settings("ExtendScript.sublime-settings")
def copyToSoftwareFolder(self, softwarePath):
# Changing the extension
scriptFolderPath = self.settings.get(softwarePath + '_path')
file_name = re.sub(r'.*/(.*)\..*$', r'\1.jsx', self.currentFile)
self.destination_file = scriptFolderPath + file_name
# Copying the file to desination
shutil.copyfile(self.currentFile, self.destination_file)
def compileEsFile(self):
file_handle = open(self.destination_file, 'r')
file_string = file_handle.read()
file_handle.close()
file_output = ""
for line in file_string.splitlines():
file_output = file_output + '\n' + self.makeReplacements(line)
file_handle = open(self.destination_file, 'w')
file_handle.write(file_output)
file_handle.close()
def makeReplacements(self, line):
output = line
if self.settings.get('compile_includes'):
if re.match(r'.*#include', line):
output = self.replaceIncludes(line)
if self.settings.get('set_debug_false'):
if re.match(r'.*debug = .*', line):
output = self.replaceDebug(line)
return output
def replaceIncludes(self, line):
path = re.sub(r'.*#include \"(.*)\";?', r'\1', line)
path = self.currentPath + "/" + path
with open(os.path.abspath(path)) as f:
fileContent = f.read()
return fileContent
def replaceDebug(self, line):
return re.sub(r'debug = true', r'debug = false', line)
class BuildForIndesign(ExtendScriptCommand):
def run(self, edit):
self.init()
self.copyToSoftwareFolder('id')
self.compileEsFile()
class BuildForIllustrator(ExtendScriptCommand):
def run(self, edit):
self.init()
self.copyToSoftwareFolder('ai')
self.compileEsFile()
class BuildForPhotoshop(ExtendScriptCommand):
def run(self, edit):
self.init()
self.copyToSoftwareFolder('ps')
self.compileEsFile()
class BuildForAfterEffects(ExtendScriptCommand):
def run(self, edit):
self.init()
self.copyToSoftwareFolder('ae')
self.compileEsFile()
class OpenEstk(ExtendScriptCommand):
def run(self, edit):
self.init()
subprocess.call(
'open -a "ExtendScript Toolkit" '+self.currentFile,
shell=True)