Merge pull request #108 from ScreamerBG/master

Refactored exporter features
pull/109/head mbed_lib_rev69
Bogdan Marinescu 2013-11-16 03:56:39 -08:00
commit a3cae89a98
1 changed files with 24 additions and 4 deletions

View File

@ -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()