Esempio n. 1
0
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())
Esempio n. 2
0
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())
Esempio n. 3
0
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())
Esempio n. 4
0
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())
Esempio n. 5
0
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())
Esempio n. 6
0
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())