| 28 | |
| 29 | |
| 30 | class CheckOut: |
| 31 | def __init__(self, rtt_repo, rtt_branch): |
| 32 | self.root = os.getcwd() |
| 33 | self.rtt_repo = rtt_repo |
| 34 | self.rtt_branch = rtt_branch |
| 35 | |
| 36 | def __exclude_file(self, file_path): |
| 37 | dir_number = file_path.split('/') |
| 38 | ignore_path = file_path |
| 39 | |
| 40 | # gets the file path depth. |
| 41 | for i in dir_number: |
| 42 | # current directory. |
| 43 | dir_name = os.path.dirname(ignore_path) |
| 44 | ignore_path = dir_name |
| 45 | # judge the ignore file exists in the current directory. |
| 46 | ignore_file_path = os.path.join(dir_name, ".ignore_format.yml") |
| 47 | if not os.path.exists(ignore_file_path): |
| 48 | continue |
| 49 | try: |
| 50 | with open(ignore_file_path) as f: |
| 51 | ignore_config = yaml.safe_load(f.read()) |
| 52 | file_ignore = ignore_config.get("file_path", []) |
| 53 | dir_ignore = ignore_config.get("dir_path", []) |
| 54 | except Exception as e: |
| 55 | logging.error(e) |
| 56 | continue |
| 57 | logging.debug("ignore file path: {}".format(ignore_file_path)) |
| 58 | logging.debug("file_ignore: {}".format(file_ignore)) |
| 59 | logging.debug("dir_ignore: {}".format(dir_ignore)) |
| 60 | try: |
| 61 | # judge file_path in the ignore file. |
| 62 | for file in file_ignore: |
| 63 | if file is not None: |
| 64 | file_real_path = os.path.join(dir_name, file) |
| 65 | if file_real_path == file_path: |
| 66 | logging.info("ignore file path: {}".format(file_real_path)) |
| 67 | return 0 |
| 68 | |
| 69 | file_dir_path = os.path.dirname(file_path) |
| 70 | for _dir in dir_ignore: |
| 71 | if _dir is not None: |
| 72 | dir_real_path = os.path.join(dir_name, _dir) |
| 73 | if file_dir_path.startswith(dir_real_path): |
| 74 | logging.info("ignore dir path: {}".format(dir_real_path)) |
| 75 | return 0 |
| 76 | except Exception as e: |
| 77 | logging.error(e) |
| 78 | continue |
| 79 | |
| 80 | return 1 |
| 81 | |
| 82 | def get_new_file(self): |
| 83 | file_list = list() |
| 84 | try: |
| 85 | os.system('git remote add rtt_repo {}'.format(self.rtt_repo)) |
| 86 | os.system('git fetch rtt_repo') |
| 87 | os.system('git merge rtt_repo/{}'.format(self.rtt_branch)) |