Example #1
0
    def __init__(self):
        # Create config dir, if not existing
        self.queueFolder = create_config_dir()
        self.logDir = create_log_dir()
        self.config = get_config()

        remove_old_logs(self.config['log']['logTime'], self.logDir)
        self.read_queue()
        # Load previous queue
        # Reset queue if all jobs from last session are finished
        if self.get_next_item() is None:
            # Rotate old log
            self.log(rotate=True)
            self.queue = {}
            # Remove old log file
            self.log()
            self.write_queue()
        self.socket = create_daemon_socket()

        # If there are still jobs in the queue the daemon might pause,
        # if this behaviour is defined in the config file.
        # The old logfile is beeing loaded as well.
        self.paused = False
        if len(self.queue) > 0:
            self.nextKey = max(self.queue.keys()) + 1
            if not self.config['default']['resumeAfterStart']:
                self.paused = True
        else:
            self.nextKey = 0

        self.active = True
        self.stopping = False
        self.reset = False
        self.remove_current = False

        # Variables to get the current state of a process
        self.processStatus = 'No running process'

        # Variables for handling sockets and child process
        self.clientAddress = None
        self.clientSocket = None
        self.process = None
        self.read_list = [self.socket]

        # Stdout/Stderr management
        self.stdout = get_stdout_descriptor()
        self.stderr = get_stderr_descriptor()
Example #2
0
def daemon_setup(request):
    queue = create_config_dir()+'/queue'
    if os.path.exists(queue):
        os.remove(queue)

    process = subprocess.Popen(
        'pueue --daemon',
        shell=True,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE
    )
    output, error = process.communicate()
    command_factory('reset')

    def daemon_teardown():
        command_factory('reset')
        command_factory('STOPDAEMON')
    request.addfinalizer(daemon_teardown)
Example #3
0
def get_config():
    configFile = create_config_dir() + '/pueue.ini'
    config = configparser.ConfigParser()
    # Try to get config, if this doesn't work a new default config will be created
    if os.path.exists(configFile):
        try:
            config.read(configFile)
            return config
        except:
            print('Error while parsing config file. Deleting old config')

    config['default'] = {
        'stopAtError': True,
        'resumeAfterStart': False
    }
    config['log'] = {
        'logTime': 60*60*24*14,
    }
    with open(configFile, 'w') as fileDescriptor:
        config.write(fileDescriptor)

    return config