-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjs_compactor.py
More file actions
98 lines (76 loc) · 3.01 KB
/
Copy pathjs_compactor.py
File metadata and controls
98 lines (76 loc) · 3.01 KB
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
############################################################
#
# Copyright (c) 2009, Southpaw Technology
# All Rights Reserved
#
# PROPRIETARY INFORMATION. This software is proprietary to
# Southpaw Technology, and is not to be reproduced, transmitted,
# or disclosed in any way without written permission.
#
#
import os
import tacticenv
from pyasm.common import Environment
import tactic.ui.app.js_includes as js_includes
# This function gathers all javascript files listed in js_includes (as defined by js_includes.all_lists)
# and puts them all in on single javascript file.
#
# The compacting process also removes block comments and lines that begin with the line comment marker ("//").
# Also removed are any leading spaces on any line written out to the single javascript file.
#
# The generated output file is placed into tactic/src/context/spt_js and the file is named with:
#
# _compact_spt_all_r<release_number>.js
#
# ... where <release_number> is the TACTIC install's release version number with dots changed to underscores.
#
def compact_javascript_files():
print " "
print "Processing javascript files to compact into single '_compact_spt_all.js' file ..."
print " "
context_path = "%s/src/context" % Environment.get_install_dir()
all_js_path = js_includes.get_compact_js_filepath()
out_fp = open( all_js_path, "w" )
for (dir, includes_list) in js_includes.all_lists:
for include in includes_list:
js_path = "%s/%s/%s" % (context_path, dir, include)
print " >> processing '%s' ..." % js_path
out_fp.write( "// %s\n\n" % js_path )
in_fp = open( js_path, "r" )
done = False
comment_flag = False
while not done:
line = in_fp.readline()
if not line:
done = True
continue
line = line.strip()
if line.startswith("//"):
continue
start_comment_idx = line.find( "/*" )
if start_comment_idx != -1:
comment_flag = True
tmp_line = line[ : start_comment_idx ].strip()
if tmp_line:
out_fp.write( "%s\n" % tmp_line )
if line.find( "*/" ) != -1:
comment_flag = False
tmp_line = line[ line.find("*/") + 2 : ].strip()
if tmp_line:
out_fp.write( "%s\n" % tmp_line )
continue
if comment_flag:
continue
line = line.strip()
if line:
out_fp.write( "%s\n" % line )
in_fp.close()
out_fp.write( "\n\n" )
out_fp.close()
print " "
print "Generated compact '%s' file." % all_js_path
print " "
print "DONE compacting javascript files into single file."
print " "
if __name__ == "__main__":
compact_javascript_files()