|
1 | | -import errno |
2 | 1 | import json |
3 | 2 | import os |
4 | 3 | import shutil |
5 | 4 | import time |
6 | | -from os.path import dirname, abspath, isfile |
| 5 | +from os.path import dirname, abspath, isfile, isdir |
| 6 | +import fnmatch |
7 | 7 | import argparse |
8 | 8 |
|
9 | 9 | from git import Repo |
|
12 | 12 | parser.add_argument('coin', type=str, help="Coin to parse from the .json file in the config folder") |
13 | 13 | args = parser.parse_args() |
14 | 14 |
|
| 15 | +# https://stackoverflow.com/questions/52071642/python-copying-the-files-with-include-pattern |
| 16 | +def include_patterns(*patterns): |
| 17 | + def _ignore_patterns(path, names): |
| 18 | + keep = set(name for pattern in patterns |
| 19 | + for name in fnmatch.filter(names, pattern)) |
| 20 | + ignore = set(name for name in names |
| 21 | + if name not in keep and not isdir(os.path.join(path, name))) |
| 22 | + return ignore |
| 23 | + |
| 24 | + return _ignore_patterns |
15 | 25 | # Get current directory |
16 | 26 | d = dirname(abspath(__file__)) |
17 | 27 |
|
|
38 | 48 | root_dir = 'src/cosmospy_protobuf' |
39 | 49 | root_abs_path = os.path.join(d, root_dir) |
40 | 50 | for filename in os.listdir(root_abs_path): |
| 51 | + if filename == ".gitignore": |
| 52 | + continue |
| 53 | + |
41 | 54 | file_path = os.path.join(root_abs_path, filename) |
42 | 55 | try: |
43 | 56 | if os.path.isfile(file_path) or os.path.islink(file_path): |
|
63 | 76 | proto_dir = os.path.join(repo_dir, proto_folder) |
64 | 77 | category_name = proto_folder.split('/')[-1] |
65 | 78 | try: |
66 | | - shutil.copytree(proto_dir, root_abs_path + "/" + category_name, dirs_exist_ok=True, ignore=shutil.ignore_patterns("*.go")) |
| 79 | + shutil.copytree(proto_dir, root_abs_path + "/" + category_name, dirs_exist_ok=True, ignore=include_patterns("*.proto")) |
67 | 80 | print(f"Copied {category_name}") |
68 | | - except OSError as exc: # python >2.5 |
| 81 | + except OSError as exc: |
69 | 82 | try: |
70 | 83 | shutil.copy(proto_dir, root_abs_path) |
71 | 84 | print(f"File {proto_dir} copied successfully") |
|
0 commit comments