Drop deep repository scanning from scan_resources() so it doesn't affect compile

Implement repository scanning through __scan_all() for exporter
pull/108/head
root 2013-11-15 18:59:19 +00:00
parent 9a080d65ee
commit f168089a91
1 changed files with 24 additions and 4 deletions

View File

@ -1,6 +1,8 @@
"""Just a template for subclassing""" """Just a template for subclassing"""
import uuid, shutil, os, logging, fnmatch import uuid, shutil, os, logging, fnmatch
from os import walk, remove
from os.path import join, dirname, isdir, split from os.path import join, dirname, isdir, split
from copy import copy
from jinja2 import Template from jinja2 import Template
from contextlib import closing from contextlib import closing
from zipfile import ZipFile, ZIP_DEFLATED from zipfile import ZipFile, ZIP_DEFLATED
@ -36,14 +38,31 @@ class Exporter():
self.toolchain.copy_files(r, trg_path, rel_path=src_path) self.toolchain.copy_files(r, trg_path, rel_path=src_path)
return resources 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): def scan_and_copy_resources(self, prj_path, trg_path):
# Copy only the file for the required target and toolchain # Copy only the file for the required target and toolchain
lib_builds = [] lib_builds = []
repo_dirs = []
for src in ['lib', 'src']: for src in ['lib', 'src']:
resources = self.__scan_and_copy(join(prj_path, src), trg_path) resources = self.__scan_and_copy(join(prj_path, src), trg_path)
lib_builds.extend(resources.lib_builds) 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 # The libraries builds
for bld in lib_builds: for bld in lib_builds:
@ -51,7 +70,8 @@ class Exporter():
lib_data = self.build_url_resolver(build_url) lib_data = self.build_url_resolver(build_url)
lib_path = lib_data['path'].rstrip('\\/') lib_path = lib_data['path'].rstrip('\\/')
self.__scan_and_copy(lib_path, join(trg_path, lib_data['name'])) 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') hgdir = join(trg_path, lib_data['name'], '.hg')
mkdir(hgdir) mkdir(hgdir)
fhandle = file(join(hgdir, 'keep.me'), 'a') fhandle = file(join(hgdir, 'keep.me'), 'a')