1 from pathlib import Path
2 from shutil import rmtree
3 from configparser import ConfigParser
5 from subprocess import Popen, PIPE
8 from logging.config import fileConfig
10 fileConfig((Path.cwd() / 'config') / 'logging.cfg')
11 logger = logging.getLogger()
15 if argument in ['data', 'all']:
16 logger.info("Cleaning and restoring data directory")
17 directory = Path.cwd() / 'data'
18 if directory.is_dir():
20 p = Path(Path.cwd() / 'data')
23 # Cleaning the postgresql database
24 if argument in ['db', 'all']:
25 config = ConfigParser()
26 config.read((Path.cwd() / 'config') / 'main.cfg')
28 host = config['postgresql']['host']
29 user = config['postgresql']['user']
30 port = config['postgresql']['port']
31 dbname = config['postgresql']['dbname']
33 logger.info("PostgreSQL database deletion")
34 command = ['dropdb', '-h', host, '-U', user, '-p', port, dbname]
35 process = Popen(command, stdout=PIPE, stderr=PIPE)
36 stdout, stderr = process.communicate()
38 logger.info("PostgreSQL database creation")
39 command = ['createdb', '-h', host, '-U', user, '-p', port, dbname]
40 process = Popen(command, stdout=PIPE, stderr=PIPE)
41 stdout, stderr = process.communicate()