def get_sleep_duration(cfg, start_time, dont_sleep, key='espa_min_request_duration_in_seconds'): """Logs details and returns number of seconds to sleep """ try: logger = EspaLogging.get_logger(settings.PROCESSING_LOGGER) except Exception: logger = get_base_logger() # Determine if we need to sleep end_time = datetime.datetime.now() seconds_elapsed = (end_time - start_time).seconds logger.info('Processing Time Elapsed {0} Seconds'.format(seconds_elapsed)) min_seconds = int((cfg.get(key))) seconds_to_sleep = 1 if dont_sleep: # We don't need to sleep seconds_to_sleep = 1 elif seconds_elapsed < min_seconds: seconds_to_sleep = (min_seconds - seconds_elapsed) logger.info('Sleeping An Additional {0} Seconds'.format(seconds_to_sleep)) return seconds_to_sleep
def change_ownership(product_path, user, group, recursive=False): """ Change the ownership of a product Args: product_path: The full path to a file or folder whose ownership will be updated user: The new owner user group: The new owner group recursive: Whether or not to apply chown recursively Returns: None """ try: logger = EspaLogging.get_logger(settings.PROCESSING_LOGGER) except Exception: logger = get_base_logger() ownership = '{u}:{g}'.format(u=user, g=group) if recursive: cmd = ' '.join(['chown', '-R', ownership, product_path]) else: cmd = ' '.join(['chown', ownership, product_path]) output = execute_cmd(cmd) if len(output) > 0: logger.info(output)
import datetime import commands import config import random import resource import settings import json from pwd import getpwuid from os import stat from collections import defaultdict from subprocess import check_output, CalledProcessError, check_call from config_utils import retrieve_pigz_cfg from espa_exception import ESPAException from logging_tools import get_base_logger, EspaLogging base_logger = get_base_logger() cfg = config.config() PIGZ_WRAPPER_FILENAME = 'pigz_wrapper.sh' class NETRCException(Exception): pass def build_netrc(): """ make a .netrc in the home dir Returns: """ try: