3 # Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
15 searchfile = '*_api.js'
16 startwith = "//= require('"
21 def get_require(self, s):
23 start = s.index(self.startwith) + len(self.startwith)
24 end = s.index(self.endwith, start)
25 filename = s[start:end]
26 self.reqfiles.append(filename)
31 def find_require(self):
32 p = os.path.join('./', self.searchfile)
33 filenames = glob.glob(self.searchfile)
34 for fname in filenames:
35 with open(fname, 'r') as myfile:
37 self.get_require(line)
40 def print_lines(self, filename):
41 with open(filename, 'r') as file:
46 def merge_js_files(self, path):
48 if len(self.reqfiles) == 0:
49 s = os.path.join('./', self.searchfile)
52 self.print_lines(fname)
55 p = os.path.join(path, js)
56 filenames = glob.glob(p)
57 for fname in self.reqfiles:
58 fname = path + '/' + fname
59 if fname in filenames:
60 self.print_lines(fname)
66 opts, args = getopt.getopt(argv,"hf:p:",["file=", "path="])
67 except getopt.GetoptError:
68 print __file__ + ' -h'
75 print __file__ + '-f <file> -p <path>'
77 print '<opt> \t <opt> \t\t <description>'
78 print '-f \t --file \t Name of the file where script searching for require files:'
79 print '\t \t \t ' + self.startwith + 'file_name.js' + self.endwith
80 print '-p \t --path \t Path to "' + path + '" directory'
83 elif opt in ("-f", "--file"):
85 elif opt in ("-p", "--path"):
87 self.merge_js_files(path)
90 if Utils.__module__ == "__main__":
91 Utils.main(sys.argv[1:])