(operations)
| 192 | |
| 193 | |
| 194 | def perform_copy_operations(operations): |
| 195 | assert len(operations) % 2 == 0 |
| 196 | count_ops = int(len(operations) / 2) |
| 197 | for op_i in range(count_ops): |
| 198 | # Refer to values by index |
| 199 | pattern = operations[op_i*2] |
| 200 | dst_dir = operations[op_i*2+1] |
| 201 | # Convert tuples to lists |
| 202 | pattern = list(pattern) |
| 203 | dst_dir = list(dst_dir) |
| 204 | # Join paths |
| 205 | pattern = os.path.join(*pattern) |
| 206 | dst_dir = os.path.join(*dst_dir) |
| 207 | dst_dir = os.path.abspath(dst_dir) |
| 208 | # Normalize unix slashes on Windows |
| 209 | pattern = pattern.replace("/", os.path.sep) |
| 210 | # dst_dir must be a directory |
| 211 | if not os.path.isdir(dst_dir): |
| 212 | raise Exception("Not a directory: {dst_dir}" |
| 213 | .format(dst_dir=dst_dir)) |
| 214 | # Is pattern a file or a directory |
| 215 | if os.path.isfile(pattern): |
| 216 | if is_ignored_path(pattern): |
| 217 | raise Exception("Copy operation pattern is in ignore list:" |
| 218 | " {pattern}".format(pattern=pattern)) |
| 219 | print("[make_installer.py] Copy: {file} ==> {dir}" |
| 220 | .format(file=short_src_path(pattern), |
| 221 | dir=short_dst_path(dst_dir))) |
| 222 | # Destination file must not exist |
| 223 | assert not os.path.exists(os.path.join(dst_dir, |
| 224 | os.path.basename(pattern))) |
| 225 | shutil.copy(pattern, dst_dir) |
| 226 | else: |
| 227 | # pattern is a glob pattern |
| 228 | base_dir = os.path.dirname(pattern) |
| 229 | assert base_dir |
| 230 | assert base_dir == os.path.abspath(base_dir) |
| 231 | paths = glob.glob(pattern) |
| 232 | if not len(paths): |
| 233 | raise Exception("No paths found in: {pattern}" |
| 234 | .format(pattern=pattern)) |
| 235 | for path in paths: |
| 236 | # "path" variable contains absolute path |
| 237 | assert path == os.path.abspath(path) |
| 238 | if os.path.isfile(path): |
| 239 | if is_ignored_path(path): |
| 240 | continue |
| 241 | print("[make_installer.py] Copy: {file} ==> {dir}" |
| 242 | .format(file=short_src_path(path), |
| 243 | dir=short_dst_path(dst_dir))) |
| 244 | # Destination file must not exist |
| 245 | assert not os.path.exists( |
| 246 | os.path.join(dst_dir, os.path.basename(path))) |
| 247 | shutil.copy(path, dst_dir) |
| 248 | elif os.path.isdir(path): |
| 249 | if is_ignored_path(path): |
| 250 | continue |
| 251 | relative_dir = path.replace(base_dir, "") |
no test coverage detected