BGP-Ranking/bin/archiver.py

43 lines
1.4 KiB
Python
Raw Normal View History

2018-07-13 14:51:00 +02:00
#!/usr/bin/env python3
2018-03-29 22:37:28 +02:00
# -*- coding: utf-8 -*-
from bgpranking.archive import DeepArchive
import logging
from pathlib import Path
from bgpranking.libs.helpers import get_config_path, get_homedir
2018-03-29 22:37:28 +02:00
from pid import PidFile, PidFileError
logger = logging.getLogger('Archiver')
logging.basicConfig(format='%(asctime)s %(name)s %(levelname)s:%(message)s',
level=logging.INFO, datefmt='%I:%M:%S')
# NOTE:
# * Supposed to run once every ~2 months
class ModulesArchiver():
def __init__(self, config_dir: Path=None, storage_directory: Path=None, loglevel: int=logging.INFO):
if not config_dir:
config_dir = get_config_path()
if not storage_directory:
self.storage_directory = get_homedir() / 'rawdata'
2018-03-29 22:37:28 +02:00
modules_config = config_dir / 'modules'
modules_paths = [modulepath for modulepath in modules_config.glob('*.json')]
self.modules = [DeepArchive(path, self.storage_directory, loglevel) for path in modules_paths]
def archive(self):
[module.archive() for module in self.modules]
if __name__ == '__main__':
archiver = ModulesArchiver()
try:
with PidFile(piddir=archiver.storage_directory):
logger.info('Archiving...')
archiver.archive()
logger.info('... done.')
except PidFileError:
logger.warning('Archiver already running, skip.')