Skip to content

Commit a3cae89

Browse files
committed
Merge pull request #108 from ScreamerBG/master
Refactored exporter features
2 parents 7e42a9f + f168089 commit a3cae89

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

workspace_tools/export/exporters.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""Just a template for subclassing"""
22
import uuid, shutil, os, logging, fnmatch
3+
from os import walk, remove
34
from os.path import join, dirname, isdir, split
5+
from copy import copy
46
from jinja2 import Template
57
from contextlib import closing
68
from zipfile import ZipFile, ZIP_DEFLATED
@@ -35,23 +37,41 @@ def __scan_and_copy(self, src_path, trg_path):
3537
if r:
3638
self.toolchain.copy_files(r, trg_path, rel_path=src_path)
3739
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
3854

3955
def scan_and_copy_resources(self, prj_path, trg_path):
4056
# Copy only the file for the required target and toolchain
4157
lib_builds = []
42-
repo_dirs = []
4358
for src in ['lib', 'src']:
4459
resources = self.__scan_and_copy(join(prj_path, src), trg_path)
4560
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))
4766

4867
# The libraries builds
4968
for bld in lib_builds:
5069
build_url = open(bld).read().strip()
5170
lib_data = self.build_url_resolver(build_url)
5271
lib_path = lib_data['path'].rstrip('\\/')
5372
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
5575
hgdir = join(trg_path, lib_data['name'], '.hg')
5676
mkdir(hgdir)
5777
fhandle = file(join(hgdir, 'keep.me'), 'a')
@@ -64,7 +84,7 @@ def scan_and_copy_resources(self, prj_path, trg_path):
6484
# This prevents exporting the mbed libraries from source
6585
# if not self.toolchain.mbed_libs:
6686
# raise OldLibrariesException()
67-
87+
6888
def gen_file(self, template_file, data, target_file):
6989
template_path = join(Exporter.TEMPLATE_DIR, template_file)
7090
template_text = open(template_path).read()

0 commit comments

Comments
 (0)