33 lines
872 B
Python
33 lines
872 B
Python
"""
|
|
This module creates the required paths for or moving the files.
|
|
"""
|
|
|
|
import os
|
|
import logging
|
|
|
|
module_logger = logging.getLogger(__name__)
|
|
|
|
def create_paths(db, base_path, dry_run):
|
|
cursor = db.cursor()
|
|
result = cursor.execute(
|
|
'''SELECT name FROM DIRECTORIES'''
|
|
)
|
|
|
|
for (pathname,) in result:
|
|
real_path_name = os.path.join(base_path, pathname)
|
|
if(dry_run):
|
|
if(os.path.exists(real_path_name)):
|
|
module_logger.info("EXISTS: {}".format(real_path_name))
|
|
else:
|
|
module_logger.warn("CREATE {}".format(real_path_name))
|
|
continue
|
|
try:
|
|
if(os.path.exists(real_path_name)):
|
|
module_logger.info("EXISTS: {}".format(real_path_name))
|
|
else:
|
|
module_logger.info("CREATE {}".format(real_path_name))
|
|
os.makedirs(real_path_name)
|
|
except Exception as e:
|
|
module_logger.error("failed to create directory {}".format(real_path_name))
|
|
raise e
|