Return the string content of the metadata of a .gem archive file at ``location`` or None. This performs an extracion to a temp directory.
(location)
| 388 | |
| 389 | # FIXME: we should unify this with handling extracted gems |
| 390 | def extract_gem_metadata(location): |
| 391 | """ |
| 392 | Return the string content of the metadata of a .gem archive file at |
| 393 | ``location`` or None. |
| 394 | This performs an extracion to a temp directory. |
| 395 | """ |
| 396 | extract_loc = None |
| 397 | try: |
| 398 | # Extract first level of tar archive |
| 399 | extract_loc = fileutils.get_temp_dir(prefix='scancode-extract-') |
| 400 | abs_location = abspath(expanduser(location)) |
| 401 | archive.extract_tar(abs_location, extract_loc) |
| 402 | |
| 403 | # The gzipped metadata is the second level of archive. |
| 404 | metadata = os.path.join(extract_loc, 'metadata') |
| 405 | # or it can be a plain, non-gzipped file |
| 406 | metadata_gz = metadata + '.gz' |
| 407 | |
| 408 | if os.path.exists(metadata): |
| 409 | with open(metadata, 'rb') as met: |
| 410 | content = met.read() |
| 411 | |
| 412 | elif os.path.exists(metadata_gz): |
| 413 | content = archive.get_gz_compressed_file_content(metadata_gz) |
| 414 | |
| 415 | else: |
| 416 | raise Exception(f'No RubyGems metadata file found inside .gem archive: {location!r}') |
| 417 | |
| 418 | return content |
| 419 | |
| 420 | finally: |
| 421 | if extract_loc: |
| 422 | fileutils.delete(extract_loc) |
| 423 | |
| 424 | |
| 425 | def build_rubygem_package_data(gem_data, datasource_id, package_only=False): |