Diffstat (limited to 'scripts/builder/frontendBuilder.py') (more/less context) (show whitespace changes)
-rw-r--r-- | scripts/builder/frontendBuilder.py | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/scripts/builder/frontendBuilder.py b/scripts/builder/frontendBuilder.py index 1f0f92f..fc603c4 100644 --- a/scripts/builder/frontendBuilder.py +++ b/scripts/builder/frontendBuilder.py | |||
@@ -2,44 +2,59 @@ | |||
2 | # -*- coding: UTF-8 -*- | 2 | # -*- coding: UTF-8 -*- |
3 | 3 | ||
4 | import sys, os, re | 4 | import sys, os, re |
5 | import cssmin | 5 | import cssmin |
6 | import jsmin | 6 | import jsmin |
7 | import codecs | 7 | import codecs |
8 | import shutil | 8 | import shutil |
9 | import StringIO | 9 | import StringIO |
10 | import urllib | 10 | import urllib |
11 | 11 | ||
12 | import main | 12 | import main |
13 | 13 | ||
14 | #=============================================================================== | ||
15 | |||
14 | class FrontendBuilder(object): | 16 | class FrontendBuilder(object): |
15 | 17 | ||
16 | def __init__ (self, frontend, settings, repositoryVersion): | 18 | def __init__ (self, frontend, settings, repositoryVersion): |
17 | if '.' in frontend: | 19 | if '.' in frontend: |
18 | moduleComponents = frontend.split('.') | 20 | moduleComponents = frontend.split('.') |
19 | self.module = moduleComponents[0] | 21 | self.module = moduleComponents[0] |
20 | self.submodule = moduleComponents[1] | 22 | self.submodule = moduleComponents[1] |
21 | else: | 23 | else: |
22 | self.module = frontend | 24 | self.module = frontend |
23 | self.submodule = frontend | 25 | self.submodule = frontend |
24 | 26 | ||
25 | self.settings = settings | 27 | self.settings = settings |
26 | self.projectDir = main.projectBaseDir() | 28 | self.projectDir = main.projectBaseDir() |
27 | # self.repository = repository.repositoryWithPath(self.projectDir) | 29 | # self.repository = repository.repositoryWithPath(self.projectDir) |
28 | self.repositoryVersion = repositoryVersion | 30 | self.repositoryVersion = repositoryVersion |
29 | self.processedFiles = {} | 31 | self.processedFiles = {} |
30 | 32 | ||
33 | #--------------------------------------------------------------------------- | ||
34 | |||
35 | def name (self): | ||
36 | raise NotImplementedError() | ||
37 | |||
38 | |||
39 | def copyStaticResources (self, targetFolder): | ||
40 | raise NotImplementedError() | ||
41 | |||
42 | #--------------------------------------------------------------------------- | ||
31 | 43 | ||
32 | def log (self, message): | 44 | def log (self, message): |
33 | print "frontend [" + self.module + "]: " + message | 45 | module = self.module |
46 | if (self.module != self.submodule): | ||
47 | module = module + "." + self.submodule | ||
48 | print "frontend [" + module + "]: " + message | ||
34 | 49 | ||
35 | 50 | ||
36 | def absolutePathForSources (self): | 51 | def absolutePathForSources (self): |
37 | return os.path.join(self.projectDir, 'frontend', self.module) | 52 | return os.path.join(self.projectDir, 'frontend', self.module) |
38 | 53 | ||
39 | 54 | ||
40 | def absolutePathForSourceFile (self, basePath, file): | 55 | def absolutePathForSourceFile (self, basePath, file): |
41 | return os.path.join(self.absolutePathForSources(), basePath, file) | 56 | return os.path.join(self.absolutePathForSources(), basePath, file) |
42 | 57 | ||
43 | 58 | ||
44 | def absolutePathForTargetFile (self, folder, basePath, file): | 59 | def absolutePathForTargetFile (self, folder, basePath, file): |
45 | return os.path.join(folder, self.module, basePath, file) | 60 | return os.path.join(folder, self.module, basePath, file) |
@@ -49,34 +64,48 @@ class FrontendBuilder(object): | |||
49 | result = [] | 64 | result = [] |
50 | 65 | ||
51 | for file in files: | 66 | for file in files: |
52 | if file.startswith('--'): | 67 | if file.startswith('--'): |
53 | pass | 68 | pass |
54 | else: | 69 | else: |
55 | result.append(file) | 70 | result.append(file) |
56 | 71 | ||
57 | return result | 72 | return result |
58 | 73 | ||
59 | 74 | ||
60 | def copyResources (self, sourceFolder, destinationFolder, fileType): | 75 | def copyResources (self, sourceFolder, destinationFolder, fileType): |
76 | if fileType in self.settings: | ||
61 | for file in self.filterFiles(self.settings[fileType]): | 77 | for file in self.filterFiles(self.settings[fileType]): |
62 | src = self.absolutePathForSourceFile(fileType, file) | 78 | src = self.absolutePathForSourceFile(fileType, file) |
63 | dst = self.absolutePathForTargetFile(destinationFolder, fileType, file) | 79 | dst = self.absolutePathForTargetFile(destinationFolder, fileType, file) |
64 | main.createFolder(os.path.dirname(dst)) | 80 | main.createFolder(os.path.dirname(dst)) |
65 | shutil.copy2(src, dst) | 81 | shutil.copy2(src, dst) |
82 | else: | ||
83 | srcFolder = os.path.join(self.absolutePathForSources(), fileType) | ||
84 | dstFolder = os.path.join(destinationFolder, self.module, fileType) | ||
85 | if not(os.path.exists(dstFolder)): | ||
86 | shutil.copytree(srcFolder, dstFolder) | ||
87 | |||
88 | # try: | ||
89 | # shutil.copytree(srcFolder, dstFolder) | ||
90 | # except: | ||
91 | # pass | ||
92 | |||
66 | 93 | ||
67 | 94 | ||
68 | def copyResourcesToFolder (self, targetFolder): | 95 | def copyResourcesToFolder (self, targetFolder): |
69 | self.copyResources(self.projectDir, targetFolder, 'css') | 96 | self.copyResources(self.projectDir, targetFolder, 'css') |
70 | self.copyResources(self.projectDir, targetFolder, 'js') | 97 | self.copyResources(self.projectDir, targetFolder, 'js') |
98 | self.copyResources(self.projectDir, targetFolder, 'images') | ||
99 | self.copyStaticResources(targetFolder) | ||
71 | 100 | ||
72 | 101 | ||
73 | def loadFilesContent (self, basePath, files): | 102 | def loadFilesContent (self, basePath, files): |
74 | result = "" | 103 | result = "" |
75 | 104 | ||
76 | for file in self.filterFiles(files): | 105 | for file in self.filterFiles(files): |
77 | try: | 106 | try: |
78 | fileHandler = codecs.open(self.absolutePathForSourceFile(basePath, file), 'r', 'utf-8') | 107 | fileHandler = codecs.open(self.absolutePathForSourceFile(basePath, file), 'r', 'utf-8') |
79 | except: | 108 | except: |
80 | print "FILE: " + file | 109 | print "FILE: " + file |
81 | 110 | ||
82 | result += fileHandler.read() + '\n' | 111 | result += fileHandler.read() + '\n' |
@@ -362,24 +391,25 @@ class FrontendBuilder(object): | |||
362 | js =self.scriptTagForContent(self.bookmarklet()) + \ | 391 | js =self.scriptTagForContent(self.bookmarklet()) + \ |
363 | '\n' + \ | 392 | '\n' + \ |
364 | self.scriptTagsForFiles('./js', self.filterFiles(self.settings['js'])) | 393 | self.scriptTagsForFiles('./js', self.filterFiles(self.settings['js'])) |
365 | jsLoadMode = 'LINKED' | 394 | jsLoadMode = 'LINKED' |
366 | 395 | ||
367 | elif assemblyMode == 'DEVELOPMENT': | 396 | elif assemblyMode == 'DEVELOPMENT': |
368 | copyright = "" | 397 | copyright = "" |
369 | css =self.cssTagsForFiles('file://' + str(os.path.join(self.absolutePathForSources(), 'css')), self.filterFiles(self.settings['css'])) | 398 | css =self.cssTagsForFiles('file://' + str(os.path.join(self.absolutePathForSources(), 'css')), self.filterFiles(self.settings['css'])) |
370 | js =self.scriptTagForContent(self.bookmarklet()) + \ | 399 | js =self.scriptTagForContent(self.bookmarklet()) + \ |
371 | '\n' + \ | 400 | '\n' + \ |
372 | self.scriptTagsForFiles('file://' + str(os.path.join(self.absolutePathForSources(), 'js')), self.filterFiles(self.settings['js'])) | 401 | self.scriptTagsForFiles('file://' + str(os.path.join(self.absolutePathForSources(), 'js')), self.filterFiles(self.settings['js'])) |
373 | jsLoadMode = 'LINKED' | 402 | jsLoadMode = 'LINKED' |
403 | versionType = 'development' | ||
374 | 404 | ||
375 | else: | 405 | else: |
376 | raise NotImplementedError() | 406 | raise NotImplementedError() |
377 | 407 | ||
378 | return self.assembleVersion( | 408 | return self.assembleVersion( |
379 | pageTitle = pageTitle, | 409 | pageTitle = pageTitle, |
380 | copyright = copyright, | 410 | copyright = copyright, |
381 | css = css, | 411 | css = css, |
382 | js = js, | 412 | js = js, |
383 | jsLoadMode = jsLoadMode, | 413 | jsLoadMode = jsLoadMode, |
384 | version = self.repositoryVersion, | 414 | version = self.repositoryVersion, |
385 | versionType = versionType | 415 | versionType = versionType |