Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

https://github.com/amirhertz/geometric-textures
29 May 2025, 17:48:24 UTC
  • Code
  • Branches (1)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/master
    No releases to show
  • 962e26d
  • /
  • process_data
  • /
  • files_utils.py
Raw File Download
Take a new snapshot of a software origin

If the archived software origin currently browsed is not synchronized with its upstream version (for instance when new commits have been issued), you can explicitly request Software Heritage to take a new snapshot of it.

Use the form below to proceed. Once a request has been submitted and accepted, it will be processed as soon as possible. You can then check its processing state by visiting this dedicated page.
swh spinner

Processing "take a new snapshot" request ...

Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
  • revision
  • snapshot
origin badgecontent badge Iframe embedding
swh:1:cnt:f0c0246f211c0cdc117c0a14729078ed874b81ac
origin badgedirectory badge Iframe embedding
swh:1:dir:5034db5f69ed9beaa307b23886f56209968533e3
origin badgerevision badge
swh:1:rev:087c967a74b023bae3cd874816ab8e0e5e30ddd7
origin badgesnapshot badge
swh:1:snp:2ffda93bc4e90ae1516ae67f1a7a50d8630a7bad
Citations

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
  • revision
  • snapshot
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Tip revision: 087c967a74b023bae3cd874816ab8e0e5e30ddd7 authored by Rana Hanocka on 21 October 2020, 10:05:00 UTC
Update README.md
Tip revision: 087c967
files_utils.py
import os
import constants as const
import time
import pickle
from typing import List
import requests
import tarfile
import shutil


def init_folders(*folders):
    if not const.DEBUG:
        for f in folders:
            dir_name = os.path.dirname(f)
            if dir_name and not os.path.exists(dir_name):
                os.makedirs(dir_name)


def load_pickle(path: str, pointer: List) -> bool:
    path = add_suffix(path, '.pkl')
    if os.path.isfile(path):
        with open(path, 'rb') as f:
             pointer.append(pickle.load(f))
        return True
    return False


def save_pickle(obj, path: str):
    path = add_suffix(path, '.pkl')
    init_folders(path)
    with open(path, 'wb') as f:
        pickle.dump(obj, f, pickle.HIGHEST_PROTOCOL)


def collect(root:str, *suffix, prefix='') -> list:
    paths = []
    if not os.path.isdir(root):
        print(f'Warning: trying to collect from {root} but dir isn\'t exist')
    else:
        p_len = len(prefix)
        for path, _, files in os.walk(root):
            for file in files:
                file_name, file_extension = os.path.splitext(file)
                p_len_ = min(p_len, len(file_name))
                if file_extension in suffix and file_name[:p_len_] == prefix:
                    paths.append((path, file_name, file_extension))
        paths.sort(key=lambda x: os.path.join(x[1], x[2]))
    return paths


def add_suffix(path: str, suffix: str) -> str:
    if len(path) < len(suffix) or path[-len(suffix):] != suffix:
        path = f'{path}{suffix}'
    return path


def measure_time(func, num_iters: int, *args):
    start_time = time.time()
    for i in range(num_iters):
        func(*args)
    total_time = time.time() - start_time
    avg_time = total_time / num_iters
    print(f"{str(func).split()[1].split('.')[-1]} total time: {total_time}, average time: {avg_time}")


def download_file_from_google_drive(id, destination):
    init_folders(destination)
    # taken from this stackoverflow: https://stackoverflow.com/a/39225039

    def get_confirm_token(response_):
        for key, value in response_.cookies.items():
            if key.startswith('download_warning'):
                return value
        return None

    def save_response_content(response_, destination_):
        CHUNK_SIZE = 32768
        with open(destination_, "wb") as f:
            for chunk in response_.iter_content(CHUNK_SIZE):
                if chunk:  # filter out keep-alive new chunks
                    f.write(chunk)
    URL = "https://docs.google.com/uc?export=download"
    session = requests.Session()

    response = session.get(URL, params={'id': id}, stream=True)
    token = get_confirm_token(response)

    if token:
        params = {'id':id, 'confirm': token}
        response = session.get(URL, params=params, stream=True)

    save_response_content(response, destination)


def decompress_data(path: str):
    src = f'{const.DATA_ROOT}/_raw/'
    init_folders(f'{const.RAW_MESHES}/')
    tar = tarfile.open(path)
    tar.extractall(f'{const.DATA_ROOT}/')
    tar.close()
    os.remove(path)
    files = os.listdir(src)
    for name in files:
        srcname = os.path.join(src, name)
        dstname = os.path.join(f'{const.RAW_MESHES}/', name)
        if not os.path.isfile(dstname):
            shutil.move(srcname, f'{const.RAW_MESHES}/')
    shutil.rmtree(src)

back to top

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Contact— JavaScript license information— Web API