Changeset 8230acb in rtems-central


Ignore:
Timestamp:
Apr 17, 2020, 12:29:00 PM (9 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
a4e08c5
Parents:
4733ad3
Message:

util: Add copy_files()

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • rtems_spec_to_x.py

    r4733ad3 r8230acb  
    2727
    2828import os
    29 import shutil
    3029import string
    3130import subprocess
     
    5756    source_dir = config["source-directory"]
    5857    workspace_dir = config["workspace-directory"]
    59     for a_file in files:
    60         src = os.path.join(source_dir, a_file)
    61         dst = os.path.join(workspace_dir, a_file)
    62         os.makedirs(os.path.dirname(dst), exist_ok=True)
    63         shutil.copy2(src, dst)
     58    rtemsqual.util.copy_files(source_dir, workspace_dir, files)
    6459    with open(os.path.join(workspace_dir, "config.ini"), "w") as config_ini:
    6560        content = string.Template(config["config-ini"]).substitute(config)
  • rtemsqual/tests/test_util.py

    r4733ad3 r8230acb  
    2727import os
    2828
    29 from rtemsqual.util import load_config
     29from rtemsqual.util import copy_files, load_config
     30
     31
     32def test_copy_files(tmpdir):
     33    src_dir = os.path.dirname(__file__)
     34    copy_files(src_dir, tmpdir, [])
     35    filename = "config/c/d.yml"
     36    assert not os.path.exists(os.path.join(tmpdir, filename))
     37    copy_files(src_dir, tmpdir, [filename])
     38    assert os.path.exists(os.path.join(tmpdir, filename))
    3039
    3140
  • rtemsqual/util.py

    r4733ad3 r8230acb  
    2626
    2727import os
    28 from typing import Any
     28import shutil
     29from typing import Any, List
    2930import yaml
     31
     32
     33def copy_files(src_dir: str, dst_dir: str, files: List[str]) -> None:
     34    """
     35    Copies a list of files in the source directory to the destination
     36    directory preserving the directory of the files relative to the source
     37    directory.
     38    """
     39    for a_file in files:
     40        src = os.path.join(src_dir, a_file)
     41        dst = os.path.join(dst_dir, a_file)
     42        os.makedirs(os.path.dirname(dst), exist_ok=True)
     43        shutil.copy2(src, dst)
    3044
    3145
Note: See TracChangeset for help on using the changeset viewer.