def create_source_files(project, base_dir): """ :param project: Project """ source_files = project.source_files.all() src_dir = os.path.join(base_dir, 'src') if project.project_type == 'pebblejs': src_dir = os.path.join(src_dir, 'js') worker_dir = None try: os.mkdir(src_dir) except OSError as e: if e.errno == 17: # file exists pass else: raise for f in source_files: target_dir = src_dir if f.target == 'worker' and project.project_type == 'native': if worker_dir is None: worker_dir = os.path.join(base_dir, 'worker_src') os.mkdir(worker_dir) target_dir = worker_dir abs_target = os.path.abspath(os.path.join(target_dir, f.file_name)) if not abs_target.startswith(target_dir): raise Exception("Suspicious filename: %s" % f.file_name) abs_target_dir = os.path.dirname(abs_target) if not os.path.exists(abs_target_dir): os.makedirs(abs_target_dir) f.copy_to_path(abs_target) # Make sure we don't duplicate downloading effort; just open the one we created. with open(abs_target) as fh: check_preprocessor_directives(abs_target_dir, abs_target, fh.read())
def create_source_files(source_files, src_dir): for f in source_files: abs_target = os.path.abspath(os.path.join(src_dir, f.file_name)) if not abs_target.startswith(src_dir): raise Exception("Suspicious filename: %s" % f.file_name) abs_target_dir = os.path.dirname(abs_target) if not os.path.exists(abs_target_dir): os.makedirs(abs_target_dir) f.copy_to_path(abs_target) # Make sure we don't duplicate downloading effort; just open the one we created. with open(abs_target) as f: check_preprocessor_directives(f.read())
def assemble_source_files(project, base_dir): """ Copy all the source files for a project into a project directory """ source_files = project.source_files.all() for f in source_files: target_dir = os.path.join(base_dir, f.project_dir) abs_target = os.path.abspath(os.path.join(target_dir, f.file_name)) if not abs_target.startswith(target_dir): raise Exception("Suspicious filename: %s" % f.file_name) abs_target_dir = os.path.dirname(abs_target) if not os.path.exists(abs_target_dir): os.makedirs(abs_target_dir) f.copy_to_path(abs_target) # Make sure we don't duplicate downloading effort; just open the one we created. with open(abs_target) as fh: check_preprocessor_directives(abs_target_dir, abs_target, fh.read())