Changeset View
Changeset View
Standalone View
Standalone View
swh/provenance/tools/origins/client.py
Show All 13 Lines | |||||
from swh.core import config | from swh.core import config | ||||
from swh.model.hashutil import hash_to_bytes | from swh.model.hashutil import hash_to_bytes | ||||
from swh.provenance import get_archive, get_provenance | from swh.provenance import get_archive, get_provenance | ||||
from swh.provenance.origin import OriginEntry, origin_add | from swh.provenance.origin import OriginEntry, origin_add | ||||
CONFIG_ENVVAR = "SWH_CONFIG_FILENAME" | CONFIG_ENVVAR = "SWH_CONFIG_FILENAME" | ||||
DEFAULT_PATH = os.environ.get(CONFIG_ENVVAR, None) | DEFAULT_PATH = os.environ.get(CONFIG_ENVVAR, None) | ||||
LOG_FORMAT = ( | |||||
"%(asctime)s-%(levelname)s - %(process)d - %(name)s.%(funcName)s:%(lineno)d" | |||||
": %(message)s" | |||||
) | |||||
class Client(multiprocessing.Process): | class Client(multiprocessing.Process): | ||||
def __init__( | def __init__( | ||||
self, | self, | ||||
conf: Dict[str, Any], | conf: Dict[str, Any], | ||||
group: None = None, | group: None = None, | ||||
target: Optional[Callable[..., Any]] = ..., | target: Optional[Callable[..., Any]] = ..., | ||||
Show All 28 Lines | def run(self): | ||||
OriginEntry(origin["url"], hash_to_bytes(origin["snapshot"])) | OriginEntry(origin["url"], hash_to_bytes(origin["snapshot"])) | ||||
) | ) | ||||
origin_add(provenance, archive, batch) | origin_add(provenance, archive, batch) | ||||
logging.info(f"Client {self.name} stopped") | logging.info(f"Client {self.name} stopped") | ||||
if __name__ == "__main__": | if __name__ == "__main__": | ||||
logging.basicConfig(level=logging.INFO) | logging.basicConfig(level=logging.WARN, format=LOG_FORMAT) | ||||
# Check parameters | # Check parameters | ||||
if len(sys.argv) != 2: | if len(sys.argv) != 2: | ||||
print("usage: client <processes>") | print("usage: client <processes>") | ||||
exit(-1) | exit(-1) | ||||
processes = int(sys.argv[1]) | processes = int(sys.argv[1]) | ||||
Show All 34 Lines |