(work_path, tgz, cpp_only=False, c_only=False, skip_files=None)
| 345 | |
| 346 | |
| 347 | def unpack_package(work_path, tgz, cpp_only=False, c_only=False, skip_files=None): |
| 348 | temp_path = os.path.join(work_path, 'temp') |
| 349 | __remove_tree(temp_path) |
| 350 | os.mkdir(temp_path) |
| 351 | |
| 352 | header_endings = ('.hpp', '.h++', '.hxx', '.hh', '.h') |
| 353 | cpp_source_endings = ('.cpp', '.c++', '.cxx', '.cc', '.tpp', '.txx', '.ipp', '.ixx', '.qml') |
| 354 | c_source_endings = ('.c',) |
| 355 | |
| 356 | if cpp_only: |
| 357 | source_endings = cpp_source_endings |
| 358 | elif c_only: |
| 359 | source_endings = c_source_endings |
| 360 | else: |
| 361 | source_endings = cpp_source_endings + c_source_endings |
| 362 | |
| 363 | source_found = False |
| 364 | if tarfile.is_tarfile(tgz): |
| 365 | print('Unpacking..') |
| 366 | with tarfile.open(tgz) as tf: |
| 367 | total = 0 |
| 368 | extracted = 0 |
| 369 | skipped = 0 |
| 370 | for member in tf: |
| 371 | total += 1 |
| 372 | if member.name.startswith(('/', '..')): |
| 373 | # Skip dangerous file names |
| 374 | # print('skipping dangerous file: ' + member.name) |
| 375 | skipped += 1 |
| 376 | continue |
| 377 | |
| 378 | is_source = member.name.lower().endswith(source_endings) |
| 379 | if is_source or member.name.lower().endswith(header_endings): |
| 380 | if skip_files is not None: |
| 381 | skip = False |
| 382 | for skip_file in skip_files: |
| 383 | if member.name.endswith('/' + skip_file): |
| 384 | # print('found file to skip: ' + member.name) |
| 385 | skip = True |
| 386 | break |
| 387 | if skip: |
| 388 | skipped += 1 |
| 389 | continue |
| 390 | try: |
| 391 | tf.extract(member.name, temp_path) |
| 392 | if is_source: |
| 393 | source_found = True |
| 394 | extracted += 1 |
| 395 | except OSError: |
| 396 | pass |
| 397 | except AttributeError: |
| 398 | pass |
| 399 | print('extracted {} of {} files (skipped {}{})'.format(extracted, total, skipped, (' / only headers' if (extracted and not source_found) else ''))) |
| 400 | return temp_path, source_found |
| 401 | |
| 402 | |
| 403 | def __run_command(cmd, print_cmd=True): |
nothing calls this directly
no test coverage detected