1
1
"""Just a template for subclassing"""
2
2
import uuid , shutil , os , logging , fnmatch
3
+ from os import walk , remove
3
4
from os .path import join , dirname , isdir , split
5
+ from copy import copy
4
6
from jinja2 import Template
5
7
from contextlib import closing
6
8
from zipfile import ZipFile , ZIP_DEFLATED
@@ -35,23 +37,41 @@ def __scan_and_copy(self, src_path, trg_path):
35
37
if r :
36
38
self .toolchain .copy_files (r , trg_path , rel_path = src_path )
37
39
return resources
40
+
41
+ def __scan_all (self , path ):
42
+ resources = []
43
+
44
+ for root , dirs , files in walk (path ):
45
+ for d in copy (dirs ):
46
+ if d == '.' or d == '..' :
47
+ dirs .remove (d )
48
+
49
+ for file in files :
50
+ file_path = join (root , file )
51
+ resources .append (file_path )
52
+
53
+ return resources
38
54
39
55
def scan_and_copy_resources (self , prj_path , trg_path ):
40
56
# Copy only the file for the required target and toolchain
41
57
lib_builds = []
42
- repo_dirs = []
43
58
for src in ['lib' , 'src' ]:
44
59
resources = self .__scan_and_copy (join (prj_path , src ), trg_path )
45
60
lib_builds .extend (resources .lib_builds )
46
- repo_dirs .extend (resources .repo_dirs )
61
+
62
+ # The repository files
63
+ for repo_dir in resources .repo_dirs :
64
+ repo_files = self .__scan_all (repo_dir )
65
+ self .toolchain .copy_files (repo_files , trg_path , rel_path = join (prj_path , src ))
47
66
48
67
# The libraries builds
49
68
for bld in lib_builds :
50
69
build_url = open (bld ).read ().strip ()
51
70
lib_data = self .build_url_resolver (build_url )
52
71
lib_path = lib_data ['path' ].rstrip ('\\ /' )
53
72
self .__scan_and_copy (lib_path , join (trg_path , lib_data ['name' ]))
54
- # create .hg dir in build dir so it's ignored when versioning
73
+
74
+ # Create .hg dir in mbed build dir so it's ignored when versioning
55
75
hgdir = join (trg_path , lib_data ['name' ], '.hg' )
56
76
mkdir (hgdir )
57
77
fhandle = file (join (hgdir , 'keep.me' ), 'a' )
@@ -64,7 +84,7 @@ def scan_and_copy_resources(self, prj_path, trg_path):
64
84
# This prevents exporting the mbed libraries from source
65
85
# if not self.toolchain.mbed_libs:
66
86
# raise OldLibrariesException()
67
-
87
+
68
88
def gen_file (self , template_file , data , target_file ):
69
89
template_path = join (Exporter .TEMPLATE_DIR , template_file )
70
90
template_text = open (template_path ).read ()
0 commit comments