Bug 5917 / Bug 6085 : Fixing not being able to change language
[koha.git] / koha-tt / opac-tmpl / prog / en / lib / greybox / GreyBox_v5_5 / combiner.py
1 #!/usr/bin/env python
2 """
3 Used to combine the different parts of GreyBox.
4 - Python 2.4 required
5 - Java 1.4+ required
6 - Dojo's JavaScript compressor (http://dojotoolkit.org/docs/compressor_system.html). Place it under compression_lib/custom_rhino.jar
7 """
8 import os, sys, shutil
9 from compression_lib import AJS_minify
10
11
12 if __name__ == '__main__':
13     args = sys.argv
14
15     if len(args) < 2:
16         print """
17 Usage is:
18     python combiner.py [full|gallery|window]
19 Example usage:
20     python combiner.py full
21 The files will be store in greybox_dist/* depending on the dist. type
22 """
23         sys.exit(0)
24
25     type = args[1]
26     output_dir = 'greybox'
27
28     ##
29     # Config file list
30     #
31     js = []
32     css = []
33     static = []
34
35     append = lambda l, x: l.append('greybox_source/%s' % x)
36
37     def appendBase():
38         append(js, 'base/base.js')
39         append(js, 'auto_deco.js')
40         append(css, 'base/base.css')
41         append(static, 'base/indicator.gif')
42         append(static, 'base/loader_frame.html')
43
44     def appendSet():
45         append(js, 'set/set.js')
46         append(css, 'set/set.css')
47         append(static, 'set/next.gif')
48         append(static, 'set/prev.gif')
49
50     def appendGallery():
51         append(js, 'gallery/gallery.js')
52         append(css, 'gallery/gallery.css')
53         append(static, 'gallery/g_close.gif')
54
55     def appendWindow():
56         append(js, 'window/window.js')
57         append(css, 'window/window.css')
58         append(static, 'window/header_bg.gif')
59         append(static, 'window/w_close.gif')
60
61     appendBase()
62
63     if type == 'full':
64         appendGallery()
65         appendSet()
66         appendWindow()
67     elif type == 'gallery':
68         appendGallery()
69         appendSet()
70     elif type == 'window':
71         appendWindow()
72     else:
73         sys.exit('Uknown type')
74
75     print 'Follwoing styles are used:'
76     for style in css:
77         print '   %s' % style
78
79     print 'Follwoing JavaScript is used:'
80     for script in js:
81         print '   %s' % script
82
83     ##
84     # Copy the files
85     #
86     try:
87         shutil.rmtree(output_dir)
88     except:
89         pass
90     os.mkdir(output_dir)
91
92     def concatFiles(f_list):
93         data = []
94         for f in f_list:
95             data.append(open(f, 'r').read())
96         return '\n\n'.join(data)
97
98     def copyFiles(f_list):
99         for f in f_list:
100             shutil.copy(f, output_dir)
101
102     copyFiles(static)
103     fp = open('%s/%s' % (output_dir, 'gb_styles.css'), 'w')
104     fp.write(concatFiles(css))
105     fp.close()
106     print 'Compressed styles in %s' % ('greybox/gb_styles.css')
107
108     ##
109     # Concat js
110     #
111     fp = open('%s/%s' % (output_dir, 'gb_scripts_tmp.js'), 'w')
112     fp.write(concatFiles(js))
113     fp.close()
114
115     AJS_minify.AJS_SRC = 'greybox_source/base/AJS.js'
116     AJS_minify.AJS_MINI_SRC = 'greybox/AJS_tmp.js'
117     files = ['greybox/gb_scripts_tmp.js', 'greybox_source/base/AJS_fx.js', 'static_files/help.js']
118     code_analyzer = AJS_minify.ExternalCodeAnalyzer(files)
119     composer = AJS_minify.AjsComposer(code_analyzer.findFunctions())
120     composer.writeToOutput()
121
122     os.popen('java -jar compression_lib/custom_rhino.jar -c greybox/AJS_tmp.js > greybox/AJS.js')
123     os.remove('greybox/AJS_tmp.js')
124     os.popen('java -jar compression_lib/custom_rhino.jar -c greybox_source/base/AJS_fx.js > greybox/AJS_fx.js')
125     print 'Compressed AJS.js and AJS.js into greybox/'
126
127     os.popen('java -jar compression_lib/custom_rhino.jar -c greybox/gb_scripts_tmp.js > greybox/gb_scripts.js')
128     os.remove('greybox/gb_scripts_tmp.js')
129     print 'Compressed JavaScript in %s' % ('greybox/gb_scripts.css')
130
131     #Append script_loaded
132     open('greybox/AJS.js', 'a').write('\nscript_loaded=true;')
133     open('greybox/AJS_fx.js', 'a').write('\nscript_loaded=true;')
134     open('greybox/gb_scripts.js', 'a').write('\nscript_loaded=true;')