Exemple #1
0
def getQueue(config, user):
    """
    Generate a list of all fax entries in the send queue.

    Result is a list of (job-number, description) tuples, where
    'description' is the content of the job's controlfile as a
    dictionary.
    """
    for num, controlfile in getQueueFiles(config, user):
        jobDesc = JobDescription(controlfile).items()
        yield (num, jobDesc)
Exemple #2
0
def moveJob(controlfile, newdir, user=None):
    # todo: important: update 'filenmae' in job description!
    control = JobDescription(controlfile)
    filename = control.get('filename')
    cname = os.path.split(controlfile)[1]
    fname = os.path.split(filename)[1]
    if not user:
        cname = os.path.join(newdir, cname)
        fname = os.path.join(newdir, fname)
    else:
        cname = os.path.join(newdir, "%s-%s" % (user, cname))
        fname = os.path.join(newdir, "%s-%s" % (user, fname))

    # move controlfile to keep owner and protection!
    os.rename(controlfile, cname)
    os.rename(filename, fname)
    # update controlfile
    control.set('filename', fname)
    control.write(cname)

    return control
Exemple #3
0
def moveJob(controlfile, newdir, user=None):
    # todo: important: update 'filenmae' in job description!
    control = JobDescription(controlfile)
    filename = control.get('filename')
    cname = os.path.split(controlfile)[1]
    fname = os.path.split(filename)[1]
    if not user:
        cname = os.path.join(newdir, cname)
        fname = os.path.join(newdir, fname)
    else:
        cname = os.path.join(newdir, "%s-%s" % (user, cname))
        fname = os.path.join(newdir, "%s-%s" % (user, fname))

    # move controlfile to keep owner and protection!
    os.rename(controlfile, cname)
    os.rename(filename,    fname)
    # update controlfile
    control.set('filename', fname)
    control.write(cname)

    return control
Exemple #4
0
    # todo: security: May this be missused for deleting other users files?
    # todo: security: should ensure controlfile and filename are in the same
    #                 directory
    lockname = fileutils.lockname(controlfile)
    if not os.access(controlfile, os.W_OK):
        raise InvalidJob(None, controlfile)
    try:
        lock = fileutils._getLock(lockname, blocking=0)
    except IOError, err:
        if err.errno in (errno.EACCES, errno.EAGAIN):
            raise JobLockedError(None, controlfile)
        else:
            raise
    else:
        try:
            control = JobDescription(controlfile)
            filename = control.get('filename')
            os.unlink(filename)
            os.unlink(controlfile)
        finally:
            fileutils._releaseLock(lock)


def createReceivedJob(user, filename, call_from, call_to, causes):
    """
    Create a file description for a received fax. The description file
    is written to the same directory as the filename.
    """
    import time
    control = {
        'call_from': call_from,
Exemple #5
0
    # todo: security: May this be missused for deleting other users files?
    # todo: security: should ensure controlfile and filename are in the same
    #                 directory
    lockname = fileutils.lockname(controlfile)
    if not os.access(controlfile, os.W_OK):
        raise InvalidJob(None, controlfile)
    try:
        lock = fileutils._getLock(lockname, blocking=0)
    except IOError, err:
        if err.errno in (errno.EACCES, errno.EAGAIN):
            raise JobLockedError(None, controlfile)
        else:
            raise
    else:
        try:
            control = JobDescription(controlfile)
            filename = control.get('filename')
            os.unlink(filename)
            os.unlink(controlfile)
        finally:
            fileutils._releaseLock(lock)


def createReceivedJob(user, filename, call_from, call_to, causes):
    """
    Create a file description for a received fax. The description file
    is written to the same directory as the filename.
    """
    import time
    control = {
        'call_from': call_from,