Skip to content

Refactored exporter features #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 16, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions workspace_tools/export/exporters.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -35,23 +37,41 @@ def __scan_and_copy(self, src_path, trg_path):
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:
build_url = open(bld).read().strip()
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')
Expand All @@ -64,7 +84,7 @@ def scan_and_copy_resources(self, prj_path, trg_path):
# 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()
Expand Down