From f168089a91e9e63b0168e2e1dfa2ab76e475e12f Mon Sep 17 00:00:00 2001 From: root Date: Fri, 15 Nov 2013 18:59:19 +0000 Subject: [PATCH] Drop deep repository scanning from scan_resources() so it doesn't affect compile Implement repository scanning through __scan_all() for exporter --- workspace_tools/export/exporters.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/workspace_tools/export/exporters.py b/workspace_tools/export/exporters.py index 3debb6ccdf..5fb5b91251 100644 --- a/workspace_tools/export/exporters.py +++ b/workspace_tools/export/exporters.py @@ -1,6 +1,8 @@ """Just a template for subclassing""" import uuid, shutil, os, logging, fnmatch +from os import walk, remove from os.path import join, dirname, isdir, split +from copy import copy from jinja2 import Template from contextlib import closing from zipfile import ZipFile, ZIP_DEFLATED @@ -35,15 +37,32 @@ class Exporter(): if r: self.toolchain.copy_files(r, trg_path, rel_path=src_path) return resources + + def __scan_all(self, path): + resources = [] + + for root, dirs, files in walk(path): + for d in copy(dirs): + if d == '.' or d == '..': + dirs.remove(d) + + for file in files: + file_path = join(root, file) + resources.append(file_path) + + return resources def scan_and_copy_resources(self, prj_path, trg_path): # Copy only the file for the required target and toolchain lib_builds = [] - repo_dirs = [] for src in ['lib', 'src']: resources = self.__scan_and_copy(join(prj_path, src), trg_path) lib_builds.extend(resources.lib_builds) - repo_dirs.extend(resources.repo_dirs) + + # The repository files + for repo_dir in resources.repo_dirs: + repo_files = self.__scan_all(repo_dir) + self.toolchain.copy_files(repo_files, trg_path, rel_path=join(prj_path, src)) # The libraries builds for bld in lib_builds: @@ -51,7 +70,8 @@ class Exporter(): lib_data = self.build_url_resolver(build_url) lib_path = lib_data['path'].rstrip('\\/') self.__scan_and_copy(lib_path, join(trg_path, lib_data['name'])) - # create .hg dir in build dir so it's ignored when versioning + + # Create .hg dir in mbed build dir so it's ignored when versioning hgdir = join(trg_path, lib_data['name'], '.hg') mkdir(hgdir) fhandle = file(join(hgdir, 'keep.me'), 'a') @@ -64,7 +84,7 @@ class Exporter(): # This prevents exporting the mbed libraries from source # if not self.toolchain.mbed_libs: # raise OldLibrariesException() - + def gen_file(self, template_file, data, target_file): template_path = join(Exporter.TEMPLATE_DIR, template_file) template_text = open(template_path).read()