Exemple #1
0
def main(argv):
    global _PROG, _VERBOSE
    flag = None

    _PROG = argv[0]
    try:
        opts, args = getopt.getopt(argv[1:], 'hv', ( '--help',
                                   '--verbose', ))
        for flag, opt in opts:
            if flag in ( '-v', '--verbose', ):
                _VERBOSE = True
            elif flag in ( '-h', '--help', ):
                return usage(1)

        if 2 > len(args):
            return usage()

        for queue in args[1:]:
            chirp('upping host {0} for queue {1}'.format(args[0], queue))
            fsq.up_host(queue, args[0])

    except ( fsq.FSQEnvError, fsq.FSQCoerceError, ):
        shout('invalid argument for flag: {0}'.format(flag))
        return fsq.const('FSQ_FAIL_PERM')
    except fsq.FSQInstallError as e:
        shout(e.strerror)
        return fsq.const('FSQ_FAIL_TMP')
    except getopt.GetoptError as e:
        shout('invalid flag: -{0}{1}'.format('-' if 1 < len(e.opt) else '',
              e.opt))
        return fsq.const('FSQ_FAIL_TMP')
Exemple #2
0
def main(argv):
    global _PROG, _VERBOSE
    flag = None

    _PROG = argv[0]
    try:
        opts, args = getopt.getopt(argv[1:], "hvo:g:m:", ("--help", "--owner", "--group", "--mode"))
        for flag, opt in opts:
            if flag in ("-v", "--verbose"):
                _VERBOSE = True
            elif flag in ("-o", "--owner"):
                for c in ("FSQ_QUEUE_USER", "FSQ_ITEM_USER"):
                    fsq.set_const(c, opt)
            elif flag in ("-g", "--group"):
                for c in ("FSQ_QUEUE_GROUP", "FSQ_ITEM_GROUP"):
                    fsq.set_const(c, opt)
            elif flag in ("-m", "--mode"):
                for c in ("FSQ_QUEUE_MODE", "FSQ_ITEM_MODE"):
                    fsq.set_const(c, opt)
            elif flag in ("-h", "--help"):
                return usage(1)

        if 2 > len(args):
            return usage()

        for queue in args[1:]:
            chirp("downing host {0} for queue {1}".format(args[0], queue))
            fsq.down_host(queue, args[0])

    except (fsq.FSQEnvError, fsq.FSQCoerceError):
        shout("invalid argument for flag: {0}".format(flag))
        return fsq.const("FSQ_FAIL_PERM")
    except fsq.FSQInstallError, e:
        shout(e.strerror)
        return fsq.const("FSQ_FAIL_TMP")
Exemple #3
0
def main(argv):
    global _PROG, _VERBOSE
    force = False
    ignore = False
    flag = None

    _PROG = argv[0]
    try:
        opts, args = getopt.getopt(argv[1:], 'hvfo:g:m:i', ( '--help',
                                   '--force', '--verbose', '--owner',
                                   '--group', '--mode', '--ignore-exists', ))
        for flag, opt in opts:
            if flag in ( '-v', '--verbose', ):
                _VERBOSE = True
            elif flag in ( '-f', '--force', ):
                force = True
            elif flag in ( '-i', '--ignore-exists', ):
                ignore = True
            elif flag in ( '-o', '--owner', ):
                for c in ( 'FSQ_QUEUE_USER', 'FSQ_ITEM_USER', ):
                    fsq.set_const(c, opt)
            elif flag in ( '-g', '--group', ):
                for c in ( 'FSQ_QUEUE_GROUP', 'FSQ_ITEM_GROUP', ):
                    fsq.set_const(c, opt)
            elif flag in ( '-m', '--mode', ):
                for c in ( 'FSQ_QUEUE_MODE', 'FSQ_ITEM_MODE', ):
                    fsq.set_const(c, opt)
            elif flag in ( '-h', '--help', ):
                return usage(1)

        if 2 > len(args):
            return usage()

        host = args[0]

        for queue in args[1:]:
            try:
                chirp('installing host {0} to {1}'.format(host, queue))
                fsq.install_host(queue, host)
            except fsq.FSQInstallError, e:
                if e.errno == errno.ENOTEMPTY or e.errno == errno.ENOTDIR:
                    if force:
                        fsq.uninstall_host(queue, *host)
                        fsq.install_host(queue, *host)
                    elif ignore:
                        chirp('skipping {0}; already installed'.format(queue))
                    else:
                        raise
                else:
                    raise

    except ( fsq.FSQEnvError, fsq.FSQCoerceError, ):
        shout('invalid argument for flag: {0}'.format(flag))
        return fsq.const('FSQ_FAIL_PERM')
    except fsq.FSQInstallError, e:
        shout(e.strerror)
        return fsq.const('FSQ_FAIL_TMP')
Exemple #4
0
def usage(asked_for=0):
    '''Exit with a usage string, used for bad argument or with -h'''
    exit =  fsq.const('FSQ_SUCCESS') if asked_for else\
                fsq.const('FSQ_FAIL_PERM')
    f = sys.stdout if asked_for else sys.stderr
    shout('{0} [opts] queue [queue [...]]'.format(os.path.basename(_PROG)), f)
    if asked_for:
        shout('{0} [-h|--help] [-v|--verbose]'.format(os.path.basename(_PROG)),
              f)
        shout('        queue [queue [...]]', f)
    sys.exit(exit)
Exemple #5
0
def usage(asked_for=0):
    '''Exit with a usage string, used for bad argument or with -h'''
    exit =  fsq.const('FSQ_SUCCESS') if asked_for else\
                fsq.const('FSQ_FAIL_PERM')
    f = sys.stdout if asked_for else sys.stderr
    shout('{0} [opts] host queue [queue [...]]'.format(
          os.path.basename(_PROG)), f)
    if asked_for:
        shout('{0} [-h|--help] [-v|--verbose]'.format(os.path.basename(_PROG))
                                                      , f)
        shout('        host queue [queue [...]]', f)
    return 0 if asked_for else fsq.const('FSQ_FAIL_PERM')
Exemple #6
0
def usage(asked_for=0):
    """Exit with a usage string, used for bad argument or with -h"""
    exit = fsq.const("FSQ_SUCCESS") if asked_for else fsq.const("FSQ_FAIL_PERM")
    f = sys.stdout if asked_for else sys.stderr
    shout("{0} [opts] host queue [queue [...]]".format(os.path.basename(_PROG)), f)
    if asked_for:
        shout("{0} [-h|--help] [-v|--verbose]".format(os.path.basename(_PROG)), f)
        shout("        [-o owner|--owner=user|uid]", f)
        shout("        [-g group|--group=group|gid]", f)
        shout("        [-m mode|--mode=int]", f)
        shout("        host queue [queue [...]]", f)
    return 0 if asked_for else fsq.const("FSQ_FAIL_PERM")
Exemple #7
0
def main(argv):
    global _PROG, _VERBOSE
    protocol = 'jsonrpc'
    lock, trigger, ignore_listener = True, False, False

    _PROG = argv[0]
    try:
        opts, args = getopt.getopt(argv[1:], 'vhLtip:',
                     ( '--verbose', '--help', '--no-lock', '--trigger',
                       '--ignore-listener', '--protocol=', ))
        for flag, opt in opts:
            if flag in ( '-v', '--verbose', ):
                _VERBOSE = True
            if flag in ( '-p', '--protocol', ):
                protocol = opt
            if flag in ( '-L', '--no-lock', ):
                lock = False
            if flag in ( '-t', '--trigger', ):
                trigger = True
            if flag in ( '-i', '--ignore-listener', ):
                ignore_listener = True
            elif flag in ( '-h', '--help', ):
                return usage(1)

        if 5 > len(args):
            return usage()
        remote = args[0]
        src_queue = args[1]
        trg_queue = args[2]
        host = args[3]

        for item_id in args[4:]:
            chirp('pushing item {0} to remote {1} from queue {2}, host queue '\
                  '{3} to queue {4}'.format(item_id, remote, src_queue, host,
                                            trg_queue))
            item = fsq.FSQWorkItem(src_queue, item_id , host=host, lock=lock)
            fsq.push(item, remote, trg_queue, protocol=protocol)
            if trigger:
                fsq.remote_trigger_pull(remote, trg_queue,
                                   ignore_listener=ignore_listener,
                                   protocol=protocol)

    except ( fsq.FSQEnvError, fsq.FSQCoerceError, ):
        shout('invalid argument for flag: {0}'.format(flag))
        return fsq.const('FSQ_FAIL_PERM')
    except fsq.FSQInstallError as e:
        shout(e.strerror)
        return fsq.const('FSQ_FAIL_TMP')
    except getopt.GetoptError as e:
        shout('invalid flag: -{0}{1}'.format('-' if 1 < len(e.opt) else '',
              e.opt))
        return fsq.const('FSQ_FAIL_TMP')
Exemple #8
0
def done_item(item, code):
    '''Succeed or fail an item based on the return code of a program'''
    try:
        if fsq.const('FSQ_SUCCESS') == code:
            fsq.success(item)
            chirp('{0}: succeeded'.format(item.id))
        elif fsq.const('FSQ_FAIL_TMP') == code:
            fsq.fail_tmp(item)
            shout('{0}: failed temporarily'.format(item.id))
        else:
            fsq.fail_perm(item)
            shout('{0}: failed permanantly'.format(item.id))
    except fsq.FSQEnqueueError, e:
        shout(e.strerror.encode(_CHARSET))
        return -1
Exemple #9
0
def usage(asked_for=0):
    '''Exit with a usage string, used for bad argument or with -h'''
    exit =  fsq.const('FSQ_SUCCESS') if asked_for else\
                fsq.const('FSQ_FAIL_PERM')
    f = sys.stdout if asked_for else sys.stderr
    shout('{0} [opts] queue prog [args [...]]'.format(
          os.path.basename(_PROG)), f)
    if asked_for:
        shout('{0} [-h|--help] [-v|--verbose]'.format(
            os.path.basename(_PROG)), f)
        shout('        [-u user|--user=user]', f)
        shout('        [-g group|--group=group]', f)
        shout('        [-m mode|--mode=mode]', f)
        shout('        queue [queue [...]]', f)
    sys.exit(exit)
Exemple #10
0
def done_item(item, code):
    '''Succeed or fail an item based on the return code of a program'''
    try:
        if fsq.const('FSQ_SUCCESS') == code:
            fsq.success(item)
            chirp('{0}: succeeded'.format(item.id))
        elif fsq.const('FSQ_FAIL_TMP') == code:
            fsq.fail_tmp(item)
            shout('{0}: failed temporarily'.format(item.id))
        else:
            fsq.fail_perm(item)
            shout('{0}: failed permanantly'.format(item.id))
    except fsq.FSQEnqueueError, e:
        shout(e.strerror.encode(_CHARSET))
        return -1
Exemple #11
0
def main(argv):
    global _PROG, _VERBOSE
    protocol = 'jsonrpc'
    lock, trigger, ignore_listener = True, False, False

    _PROG = argv[0]
    try:
        opts, args = getopt.getopt(argv[1:], 'vhLtip:',
                     ( '--verbose', '--help', '--no-lock', '--trigger',
                       '--ignore-listener', '--protocol=', ))
        for flag, opt in opts:
            if flag in ( '-v', '--verbose', ):
                _VERBOSE = True
            if flag in ( '-p', '--protocol', ):
                protocol = opt
            if flag in ( '-L', '--no-lock', ):
                lock = False
            if flag in ( '-t', '--trigger', ):
                trigger = True
            if flag in ( '-i', '--ignore-listener', ):
                ignore_listener = True
            elif flag in ( '-h', '--help', ):
                return usage(1)

        if 5 > len(args):
            return usage()
        remote = args[0]
        src_queue = args[1]
        trg_queue = args[2]
        host = args[3]

        for item_id in args[4:]:
            chirp('pushing item {0} to remote {1} from queue {2}, host queue '\
                  '{3} to queue {4}'.format(item_id, remote, src_queue, host,
                                            trg_queue))
            item = fsq.FSQWorkItem(src_queue, item_id , host=host, lock=lock)
            fsq.push(item, remote, trg_queue, protocol=protocol)
            if trigger:
                fsq.remote_trigger_pull(remote, trg_queue,
                                   ignore_listener=ignore_listener,
                                   protocol=protocol)

    except ( fsq.FSQEnvError, fsq.FSQCoerceError, ):
        shout('invalid argument for flag: {0}'.format(flag))
        return fsq.const('FSQ_FAIL_PERM')
    except fsq.FSQInstallError, e:
        shout(e.strerror)
        return fsq.const('FSQ_FAIL_TMP')
Exemple #12
0
def usage(asked_for=0):
    '''Exit with a usage string, used for bad argument or with -h'''
    exit =  fsq.const('FSQ_SUCCESS') if asked_for else\
                fsq.const('FSQ_FAIL_PERM')
    f = sys.stdout if asked_for else sys.stderr
    shout('{0} [opts] host queue [queue [...]]'.format(
          os.path.basename(_PROG)), f)
    if asked_for:
        shout('{0} [-h|--help] [-v|--verbose] [-f|--force]'.format(
              os.path.basename(_PROG)), f)
        shout('        [-i|--ignore-exists]', f)
        shout('        [-o owner|--owner=user|uid]', f)
        shout('        [-g group|--group=group|gid]', f)
        shout('        [-m mode|--mode=int]', f)
        shout('        host queue [queue [...]]', f)
    return 0 if asked_for else fsq.const('FSQ_FAIL_PERM')
Exemple #13
0
def usage(asked_for=0):
    '''Exit with a usage string, used for bad argument or with -h'''
    exit =  fsq.const('FSQ_SUCCESS') if asked_for else\
                fsq.const('FSQ_FAIL_PERM')
    f = sys.stdout if asked_for else sys.stderr
    shout('{0} [opts] src_queue trg_queue host item_id [item_id [...]]'.format(
          os.path.basename(_PROG)), f)
    if asked_for:
        shout('{0} [-p|--protocol=jsonrpc] [-L|--no-lock] [-t|--trigger] '\
              '[-i|--ignore-listener] <proto>://<host>:<port>/url'\
              .format(os.path.basename(_PROG)), f)
        shout('{0} [-p|--protocol=jsonrpc] [-L|--no-lock] [-t|--trigger]'\
              '[-i|--ignore-listener] unix://var/sock/foo.sock'\
              .format(os.path.basename(_PROG)), f)
        shout('        src_queue trg_queue host_queue item [item [...]]', f)
    return exit
Exemple #14
0
def usage(asked_for=0):
    '''Exit with a usage string, used for bad argument or with -h'''
    exit =  fsq.const('FSQ_SUCCESS') if asked_for else\
                fsq.const('FSQ_FAIL_PERM')
    f = sys.stdout if asked_for else sys.stderr
    shout('{0} [opts] src_queue trg_queue host item_id [item_id [...]]'.format(
          os.path.basename(_PROG)), f)
    if asked_for:
        shout('{0} [-p|--protocol=jsonrpc] [-L|--no-lock] [-t|--trigger] '\
              '[-i|--ignore-listener] <proto>://<host>:<port>/url'\
              .format(os.path.basename(_PROG)), f)
        shout('{0} [-p|--protocol=jsonrpc] [-L|--no-lock] [-t|--trigger]'\
              '[-i|--ignore-listener] unix://var/sock/foo.sock'\
              .format(os.path.basename(_PROG)), f)
        shout('        src_queue trg_queue host_queue item [item [...]]', f)
    return exit
Exemple #15
0
def usage(asked_for=0):
    '''Exit with a usage string, used for bad argument or with -h'''
    exit =  fsq.const('FSQ_SUCCESS') if asked_for else\
                fsq.const('FSQ_FAIL_PERM')
    f = sys.stdout if asked_for else sys.stderr
    shout(
        '{0} [opts] host queue [queue [...]]'.format(os.path.basename(_PROG)),
        f)
    if asked_for:
        shout('{0} [-h|--help] [-v|--verbose]'.format(os.path.basename(_PROG)),
              f)
        shout('        [-o owner|--owner=user|uid]', f)
        shout('        [-g group|--group=group|gid]', f)
        shout('        [-m mode|--mode=int]', f)
        shout('        host queue [queue [...]]', f)
    return 0 if asked_for else fsq.const('FSQ_FAIL_PERM')
Exemple #16
0
def usage(asked_for=0):
    '''Exit with a usage string, used for bad argument or with -h'''
    exit =  fsq.const('FSQ_SUCCESS') if asked_for else\
                fsq.const('FSQ_FAIL_PERM')
    f = sys.stdout if asked_for else sys.stderr
    shout('{0} [opts] queue [args [...]]'.format(os.path.basename(_PROG)), f)
    if asked_for:
        shout('{0} [-h|--help] [-v|--verbose]'.format(os.path.basename(_PROG)),
              f)
        shout('        [-u user|--user=user]', f)
        shout('        [-g group|--group=group]', f)
        shout('        [-m mode|--mode=mode]', f)
        shout('        [-f file|--file=file]', f)
        shout('        [-e | --empty]', f)
        shout('        [-t | --trigger]', f)
        shout('        queue [arg [...]]', f)
    sys.exit(exit)
Exemple #17
0
def usage(asked_for=0):
    '''Exit with a usage string, used for bad argument or with -h'''
    exit =  fsq.const('FSQ_SUCCESS') if asked_for else\
                fsq.const('FSQ_FAIL_PERM')
    f = sys.stdout if asked_for else sys.stderr
    shout('{0} [opts] queue prog [args [...]]'.format(os.path.basename(_PROG)),
          f)
    if asked_for:
        shout('{0} [-h|--help] [-v|--verbose] [-f|--force]'\
              ' [-d|--down]'.format(os.path.basename(_PROG)), f)
        shout('        [-t|--triggered] [-i|--ignore-exists]', f)
        shout('        [-o owner|--owner=user|uid]', f)
        shout('        [-g group|--group=group|gid]', f)
        shout('        [-m mode|--mode=int]', f)
        shout('        [-a host|--add-host=host]', f)
        shout('        queue [queue [...]]', f)
    return 0 if asked_for else fsq.const('FSQ_FAIL_PERM')
Exemple #18
0
def usage(asked_for=0):
    '''Exit with a usage string, used for bad argument or with -h'''
    exit =  fsq.const('FSQ_SUCCESS') if asked_for else\
                fsq.const('FSQ_FAIL_PERM')
    f = sys.stdout if asked_for else sys.stderr
    shout('{0} [opts] queue prog [args [...]]'.format(
          os.path.basename(_PROG)), f)
    if asked_for:
        shout('{0} [-h|--help] [-v|--verbose] [-e|--env]'\
              ' [-E|--no-env]'.format(os.path.basename(_PROG)), f)
        shout('        [-n|--no-open] [-i|--ignore-down]', f)
        shout('        [-k|--empty-ok] [-D|--no-done]', f)
        shout('        [-l|--lock] [-L|--no-lock]', f)
        shout('        [-t ttl_seconds|--ttl=seconds]', f)
        shout('        [-m max_tries|--max-tries=int]', f)
        shout('        [-S success_code|--success-code=int]', f)
        shout('        [-T fail_tmp_code|--fail-tmp-code=int]', f)
        shout('        [-F fail_perm_code|--fail-perm-code=int]', f)
        shout('        queue prog [args [...]]', f)
    sys.exit(exit)
Exemple #19
0
def main(argv):
    global _PROG, _VERBOSE
    flag = None

    _PROG = argv[0]
    try:
        opts, args = getopt.getopt(argv[1:], 'hvo:g:m:', ( '--help', '--owner',
                                   '--group', '--mode', ))
        for flag, opt in opts:
            if flag in ( '-v', '--verbose', ):
                _VERBOSE = True
            elif flag in ( '-o', '--owner', ):
                for c in ( 'FSQ_QUEUE_USER', 'FSQ_ITEM_USER', ):
                    fsq.set_const(c, opt)
            elif flag in ( '-g', '--group', ):
                for c in ( 'FSQ_QUEUE_GROUP', 'FSQ_ITEM_GROUP', ):
                    fsq.set_const(c, opt)
            elif flag in ( '-m', '--mode', ):
                for c in ( 'FSQ_QUEUE_MODE', 'FSQ_ITEM_MODE', ):
                    fsq.set_const(c, opt)
            elif flag in ( '-h', '--help', ):
                return usage(1)

        if 2 > len(args):
            return usage()

        for queue in args[1:]:
            chirp('downing host {0} for queue {1}'.format(args[0], queue))
            fsq.down_host(queue, args[0])

    except ( fsq.FSQEnvError, fsq.FSQCoerceError, ):
        shout('invalid argument for flag: {0}'.format(flag))
        return fsq.const('FSQ_FAIL_PERM')
    except fsq.FSQInstallError as e:
        shout(e.strerror)
        return fsq.const('FSQ_FAIL_TMP')
    except getopt.GetoptError as e:
        shout('invalid flag: -{0}{1}'.format('-' if 1 < len(e.opt) else '',
              e.opt))
        return fsq.const('FSQ_FAIL_TMP')
Exemple #20
0
def usage(asked_for=0):
    '''Exit with a usage string, used for bad argument or with -h'''
    exit =  fsq.const('FSQ_SUCCESS') if asked_for else\
                fsq.const('FSQ_FAIL_PERM')
    f = sys.stdout if asked_for else sys.stderr
    shout('{0} [opts] queue host [host [...]]'.format(os.path.basename(_PROG)),
          f)
    if asked_for:
        shout(
            '{0} [-h|--help] [-v|--verbose] [-I|--link]'.format(
                os.path.basename(_PROG)), f)
        shout('        [-g|--trigger]', f)
        shout('        [-n|--no-open] [-i|--ignore-down]', f)
        shout('        [-l|--lock] [-L|--no-lock]', f)
        shout('        [-t ttl_seconds|--ttl=seconds]', f)
        shout('        [-m max_tries|--max-tries=int]', f)
        shout('        [-S success_code|--success-code=int]', f)
        shout('        [-T fail_tmp_code|--fail-tmp-code=int]', f)
        shout('        [-F fail_perm_code|--fail-perm-code=int]', f)
        shout('        queue host [host [...]]', f)

    return exit
Exemple #21
0
def main(argv):
    global _PROG, _VERBOSE
    flag = None

    _PROG = argv[0]
    try:
        opts, args = getopt.getopt(argv[1:], 'hv', (
            '--help',
            '--verbose',
        ))
        for flag, opt in opts:
            if flag in (
                    '-v',
                    '--verbose',
            ):
                _VERBOSE = True
            elif flag in (
                    '-h',
                    '--help',
            ):
                return usage(1)

        if 2 > len(args):
            return usage()

        for queue in args[1:]:
            chirp('upping host {0} for queue {1}'.format(args[0], queue))
            fsq.up_host(queue, args[0])

    except (
            fsq.FSQEnvError,
            fsq.FSQCoerceError,
    ):
        shout('invalid argument for flag: {0}'.format(flag))
        return fsq.const('FSQ_FAIL_PERM')
    except fsq.FSQInstallError, e:
        shout(e.strerror)
        return fsq.const('FSQ_FAIL_TMP')
Exemple #22
0
def usage(asked_for=0):
    '''Exit with a usage string, used for bad argument or with -h'''
    exit =  fsq.const('FSQ_SUCCESS') if asked_for else\
                fsq.const('FSQ_FAIL_PERM')
    f = sys.stdout if asked_for else sys.stderr
    shout('{0} [opts] queue prog [args [...]]'.format(os.path.basename(_PROG)),
          f)
    if asked_for:
        shout('{0} [-h|--help] [-v|--verbose] [-e|--env]'\
              ' [-E|--no-env]'.format(os.path.basename(_PROG)), f)
        shout('        [-n|--no-open] [-i|--ignore-down]', f)
        shout('        [-k|--empty-ok] [-D|--no-done]', f)
        shout('        [-l|--lock] [-L|--no-lock]', f)
        shout('        [-t ttl_seconds|--ttl=seconds]', f)
        shout('        [-m max_tries|--max-tries=int]', f)
        shout('        [-a all_hosts |--all-hosts]', f)
        shout('        [-A host |--host=host]', f)
        shout('        [-S success_code|--success-code=int]', f)
        shout('        [-T fail_tmp_code|--fail-tmp-code=int]', f)
        shout('        [-F fail_perm_code|--fail-perm-code=int]', f)
        shout('        [-r rate | --max-rate=int]', f)
        shout('        queue prog [args [...]]', f)
    sys.exit(exit)
Exemple #23
0
def main(argv):
    global _PROG, _VERBOSE
    flag = None
    force = False

    _PROG = argv[0]
    try:
        opts, args = getopt.getopt(argv[1:], 'hvf', ( '--help',
                                   '--verbose', '--force', ))
        for flag, opt in opts:
            if flag in ( '-v', '--verbose', ):
                _VERBOSE = True
            if flag in ( '-f', '--force', ):
                force = True
            elif flag in ( '-h', '--help', ):
                return usage(1)

        if 2 > len(args):
            return usage()

        for queue in args[1:]:
            chirp('removing host {0} for queue {1}'.format(args[0], queue))
            try:
                fsq.uninstall_host(queue, args[0])
            except fsq.FSQInstallError:
                if force:
                    pass
                else:
                    raise

    except ( fsq.FSQEnvError, fsq.FSQCoerceError, ):
        shout('invalid argument for flag: {0}'.format(flag))
        return fsq.const('FSQ_FAIL_PERM')
    except fsq.FSQInstallError, e:
        shout(e.strerror)
        return fsq.const('FSQ_FAIL_TMP')
Exemple #24
0
def barf(msg, exit=None, f=sys.stderr):
    '''Exit with a log message (usually a fatal error)'''
    exit = fsq.const('FSQ_FAIL_TMP') if exit is None else exit
    shout(msg, f)
    sys.exit(exit)
Exemple #25
0
#!/usr/bin/env python
# fsq-add-host(1) -- a program for turning on host queues
#
# @author: Jeff Rand <*****@*****.**>
# @depends: fsq(1), fsq(7), python (>=2.7)
#
# This software is for POSIX compliant systems only.
import getopt
import sys
import fsq
import os

_PROG = "fsq-up-host"
_VERBOSE = False
_CHARSET = fsq.const('FSQ_CHARSET')


def chirp(msg):
    if _VERBOSE:
        shout(msg)


def shout(msg, f=sys.stderr):
    '''Log to file (usually stderr), with progname: <log>'''
    print >> f, "{0}: {1}".format(_PROG, msg)
    f.flush()


def usage(asked_for=0):
    '''Exit with a usage string, used for bad argument or with -h'''
    exit =  fsq.const('FSQ_SUCCESS') if asked_for else\
Exemple #26
0
def barf(msg, exit=None, f=sys.stderr):
    '''Exit with a log message (usually a fatal error)'''
    exit = fsq.const('FSQ_FAIL_TMP') if exit is None else exit
    shout(msg, f)
    sys.exit(exit)
Exemple #27
0
def main(argv):
    global _PROG, _VERBOSE
    force = False
    is_down = False
    is_triggered = False
    is_host_triggered = False
    ignore = False
    flag = None
    hosts = []

    _PROG = argv[0]
    try:
        opts, args = getopt.getopt(argv[1:], 'hvfdto:g:m:ia:', (
            '--help',
            '--verbose',
            '--force',
            '--down',
            '--triggered',
            '--owner',
            '--group',
            '--mode',
            '--ignore-exists',
            '--add-host',
        ))
        for flag, opt in opts:
            if flag in (
                    '-v',
                    '--verbose',
            ):
                _VERBOSE = True
            elif flag in (
                    '-f',
                    '--force',
            ):
                force = True
            elif flag in (
                    '-d',
                    '--down',
            ):
                is_down = True
            elif flag in (
                    '-t',
                    '--triggered',
            ):
                is_triggered = True
            elif flag in (
                    '-i',
                    '--ignore-exists',
            ):
                ignore = True
            elif flag in (
                    '-o',
                    '--owner',
            ):
                for c in (
                        'FSQ_QUEUE_USER',
                        'FSQ_ITEM_USER',
                ):
                    fsq.set_const(c, opt)
            elif flag in (
                    '-g',
                    '--group',
            ):
                for c in (
                        'FSQ_QUEUE_GROUP',
                        'FSQ_ITEM_GROUP',
                ):
                    fsq.set_const(c, opt)
            elif flag in (
                    '-m',
                    '--mode',
            ):
                for c in (
                        'FSQ_QUEUE_MODE',
                        'FSQ_ITEM_MODE',
                ):
                    fsq.set_const(c, opt)
            elif flag in (
                    '-a',
                    '--add-host',
            ):
                hosts.append(opt)
            elif flag in (
                    '-h',
                    '--help',
            ):
                return usage(1)

        if 0 == len(args):
            return usage()
        if hosts and is_triggered:
            is_host_triggered = True
        for queue in args:
            try:
                chirp('installing {0} to {1}'.format(queue,
                                                     fsq.const('FSQ_ROOT')))
                fsq.install(queue,
                            is_down=is_down,
                            is_triggered=is_triggered,
                            hosts=hosts or None,
                            is_host_triggered=is_host_triggered)
            except fsq.FSQInstallError, e:
                if e.errno == errno.ENOTEMPTY or e.errno == errno.ENOTDIR:
                    if force:
                        fsq.uninstall(queue)
                        fsq.install(queue)
                    elif ignore:
                        chirp('skipping {0}; already installed'.format(queue))
                    else:
                        raise
                else:
                    raise

    except (
            fsq.FSQEnvError,
            fsq.FSQCoerceError,
    ):
        shout('invalid argument for flag: {0}'.format(flag))
        return fsq.const('FSQ_FAIL_PERM')
    except fsq.FSQInstallError, e:
        shout(e.strerror)
        return fsq.const('FSQ_FAIL_TMP')
Exemple #28
0
#!/usr/bin/env python
# fsq-host-dist(1) -- a program for distributing queues to host queues
#
# @author: Jeff Rand <*****@*****.**>
# @depends: fsq(1), fsq(7), python (>=2.7)
#
# This software is for POSIX compliant systems only.
import getopt
import sys
import fsq
import os

_PROG = "fsq-host-dist"
_VERBOSE = False
_CHARSET = fsq.const('FSQ_CHARSET')

def chirp(msg):
    if _VERBOSE:
        shout(msg)

def shout(msg, f=sys.stderr):
    '''Log to file (usually stderr), with progname: <log>'''
    print >> f, "{0}: {1}".format(_PROG, msg)
    f.flush()

def barf(msg, exit=None, f=sys.stderr):
    '''Exit with a log message (usually a fatal error)'''
    exit = fsq.const('FSQ_FAIL_TMP') if exit is None else exit
    shout(msg, f)
    sys.exit(exit)
Exemple #29
0
#      is terminated by signal, scan stops scanning.
#
# @author: Matthew Story <*****@*****.**>
# @depends: fsq(1), fsq(7), python (>=2.7)
#
# TODO: Concurrency? -- not right now
#
# This software is for POSIX compliant systems only.
import getopt
import sys
import fsq
import os

_PROG = "fsq-scan"
_VERBOSE = False
_CHARSET = fsq.const('FSQ_CHARSET')

def chirp(msg):
    if _VERBOSE:
        shout(msg)

def shout(msg, f=sys.stderr):
    '''Log to file (usually stderr), with progname: <log>'''
    print >> f, "{0}: {1}".format(_PROG, msg)
    f.flush()

def barf(msg, exit=None, f=sys.stderr):
    '''Exit with a log message (usually a fatal error)'''
    exit = fsq.const('FSQ_FAIL_TMP') if exit is None else exit
    shout(msg, f)
    sys.exit(exit)
Exemple #30
0
#!/usr/bin/env python
# fsq-add-host(1) -- a program for turning on host queues
#
# @author: Jeff Rand <*****@*****.**>
# @depends: fsq(1), fsq(7), python (>=2.7)
#
# This software is for POSIX compliant systems only.
import getopt
import sys
import fsq
import os

_PROG = "fsq-up-host"
_VERBOSE = False
_CHARSET = fsq.const('FSQ_CHARSET')

def chirp(msg):
    if _VERBOSE:
        shout(msg)

def shout(msg, f=sys.stderr):
    '''Log to file (usually stderr), with progname: <log>'''
    print >> f, "{0}: {1}".format(_PROG, msg)
    f.flush()

def usage(asked_for=0):
    '''Exit with a usage string, used for bad argument or with -h'''
    exit =  fsq.const('FSQ_SUCCESS') if asked_for else\
                fsq.const('FSQ_FAIL_PERM')
    f = sys.stdout if asked_for else sys.stderr
    shout('{0} [opts] host queue [queue [...]]'.format(
Exemple #31
0
# fsq-enqueue(1) -- a program for adding an item to a queue
#
# @author: O'Meara <*****@*****.**>
#          Matthew Story <*****@*****.**>
# @depends: fsq(1), fsq(7), python (>=2.7)
#
# This software is for POSIX compliant systems only.
import getopt
import sys
import fsq
import os
import StringIO

_PROG = "fsq-enqueue"
_VERBOSE = False
_CHARSET = fsq.const('FSQ_CHARSET')


def chirp(msg):
    if _VERBOSE:
        shout(msg)


def shout(msg, f=sys.stderr):
    '''Log to file (usually stderr), with progname: <log>'''
    print >> f, "{0}: {1}".format(_PROG, msg)
    f.flush()


def barf(msg, exit=None, f=sys.stderr):
    '''Exit with a log message (usually a fatal error)'''
Exemple #32
0
def main(argv):
    global _PROG, _VERBOSE
    flag = None

    _PROG = argv[0]
    try:
        opts, args = getopt.getopt(argv[1:], 'hvo:g:m:', (
            '--help',
            '--owner',
            '--group',
            '--mode',
        ))
        for flag, opt in opts:
            if flag in (
                    '-v',
                    '--verbose',
            ):
                _VERBOSE = True
            elif flag in (
                    '-o',
                    '--owner',
            ):
                for c in (
                        'FSQ_QUEUE_USER',
                        'FSQ_ITEM_USER',
                ):
                    fsq.set_const(c, opt)
            elif flag in (
                    '-g',
                    '--group',
            ):
                for c in (
                        'FSQ_QUEUE_GROUP',
                        'FSQ_ITEM_GROUP',
                ):
                    fsq.set_const(c, opt)
            elif flag in (
                    '-m',
                    '--mode',
            ):
                for c in (
                        'FSQ_QUEUE_MODE',
                        'FSQ_ITEM_MODE',
                ):
                    fsq.set_const(c, opt)
            elif flag in (
                    '-h',
                    '--help',
            ):
                return usage(1)

        if 2 > len(args):
            return usage()

        for queue in args[1:]:
            chirp('downing host {0} for queue {1}'.format(args[0], queue))
            fsq.down_host(queue, args[0])

    except (
            fsq.FSQEnvError,
            fsq.FSQCoerceError,
    ):
        shout('invalid argument for flag: {0}'.format(flag))
        return fsq.const('FSQ_FAIL_PERM')
    except fsq.FSQInstallError, e:
        shout(e.strerror)
        return fsq.const('FSQ_FAIL_TMP')
Exemple #33
0
#!/usr/bin/env python
# fsq-add-host(1) -- a program for turning off host queues
#
# @author: Jeff Rand <*****@*****.**>
# @depends: fsq(1), fsq(7), python (>=2.7)
#
# This software is for POSIX compliant systems only.
import getopt
import sys
import fsq
import os

_PROG = "fsq-down-host"
_VERBOSE = False
_CHARSET = fsq.const("FSQ_CHARSET")


def chirp(msg):
    if _VERBOSE:
        shout(msg)


def shout(msg, f=sys.stderr):
    """Log to file (usually stderr), with progname: <log>"""
    print >> f, "{0}: {1}".format(_PROG, msg)
    f.flush()


def usage(asked_for=0):
    """Exit with a usage string, used for bad argument or with -h"""
    exit = fsq.const("FSQ_SUCCESS") if asked_for else fsq.const("FSQ_FAIL_PERM")
Exemple #34
0
def main(argv):
    global _PROG, _VERBOSE
    force = False
    is_down = False
    is_triggered = False
    is_host_triggered = False
    ignore = False
    flag = None
    hosts = []

    _PROG = argv[0]
    try:
        opts, args = getopt.getopt(argv[1:], 'hvfdto:g:m:ia:', ( '--help',
                                   '--verbose', '--force', '--down',
                                   '--triggered', '--owner', '--group',
                                   '--mode', '--ignore-exists', '--add-host',))
        for flag, opt in opts:
            if flag in ( '-v', '--verbose', ):
                _VERBOSE = True
            elif flag in ( '-f', '--force', ):
                force = True
            elif flag in ( '-d', '--down', ):
                is_down = True
            elif flag in ( '-t', '--triggered', ):
                is_triggered = True
            elif flag in ( '-i', '--ignore-exists', ):
                ignore = True
            elif flag in ( '-o', '--owner', ):
                for c in ( 'FSQ_QUEUE_USER', 'FSQ_ITEM_USER', ):
                    fsq.set_const(c, opt)
            elif flag in ( '-g', '--group', ):
                for c in ( 'FSQ_QUEUE_GROUP', 'FSQ_ITEM_GROUP', ):
                    fsq.set_const(c, opt)
            elif flag in ( '-m', '--mode', ):
                for c in ( 'FSQ_QUEUE_MODE', 'FSQ_ITEM_MODE', ):
                    fsq.set_const(c, opt)
            elif flag in ( '-a', '--add-host', ):
                hosts.append(opt)
            elif flag in ( '-h', '--help', ):
                return usage(1)

        if 0 == len(args):
            return usage()
        if hosts and is_triggered:
            is_host_triggered = True
        for queue in args:
            try:
                chirp('installing {0} to {1}'.format(queue,
                                                     fsq.const('FSQ_ROOT')))
                fsq.install(queue, is_down=is_down, is_triggered=is_triggered,
                            hosts=hosts or None,
                            is_host_triggered=is_host_triggered)
            except fsq.FSQInstallError as e:
                if e.errno == errno.ENOTEMPTY or e.errno == errno.ENOTDIR:
                    if force:
                        fsq.uninstall(queue)
                        fsq.install(queue)
                    elif ignore:
                        chirp('skipping {0}; already installed'.format(queue))
                    else:
                        raise
                else:
                    raise

    except ( fsq.FSQEnvError, fsq.FSQCoerceError, ):
        shout('invalid argument for flag: {0}'.format(flag))
        return fsq.const('FSQ_FAIL_PERM')
    except fsq.FSQInstallError as e:
        shout(e.strerror)
        return fsq.const('FSQ_FAIL_TMP')
    except getopt.GetoptError as e:
        shout('invalid flag: -{0}{1}'.format('-' if 1 < len(e.opt) else '',
              e.opt))
        return fsq.const('FSQ_FAIL_TMP')
Exemple #35
0
def main(argv):
    global _PROG, _VERBOSE
    force = False
    ignore = False
    flag = None

    _PROG = argv[0]
    try:
        opts, args = getopt.getopt(argv[1:], 'hvfo:g:m:i', (
            '--help',
            '--force',
            '--verbose',
            '--owner',
            '--group',
            '--mode',
            '--ignore-exists',
        ))
        for flag, opt in opts:
            if flag in (
                    '-v',
                    '--verbose',
            ):
                _VERBOSE = True
            elif flag in (
                    '-f',
                    '--force',
            ):
                force = True
            elif flag in (
                    '-i',
                    '--ignore-exists',
            ):
                ignore = True
            elif flag in (
                    '-o',
                    '--owner',
            ):
                for c in (
                        'FSQ_QUEUE_USER',
                        'FSQ_ITEM_USER',
                ):
                    fsq.set_const(c, opt)
            elif flag in (
                    '-g',
                    '--group',
            ):
                for c in (
                        'FSQ_QUEUE_GROUP',
                        'FSQ_ITEM_GROUP',
                ):
                    fsq.set_const(c, opt)
            elif flag in (
                    '-m',
                    '--mode',
            ):
                for c in (
                        'FSQ_QUEUE_MODE',
                        'FSQ_ITEM_MODE',
                ):
                    fsq.set_const(c, opt)
            elif flag in (
                    '-h',
                    '--help',
            ):
                return usage(1)

        if 2 > len(args):
            return usage()

        host = args[0]

        for queue in args[1:]:
            try:
                chirp('installing host {0} to {1}'.format(host, queue))
                fsq.install_host(queue, host)
            except fsq.FSQInstallError, e:
                if e.errno == errno.ENOTEMPTY or e.errno == errno.ENOTDIR:
                    if force:
                        fsq.uninstall_host(queue, *host)
                        fsq.install_host(queue, *host)
                    elif ignore:
                        chirp('skipping {0}; already installed'.format(queue))
                    else:
                        raise
                else:
                    raise

    except (
            fsq.FSQEnvError,
            fsq.FSQCoerceError,
    ):
        shout('invalid argument for flag: {0}'.format(flag))
        return fsq.const('FSQ_FAIL_PERM')
    except fsq.FSQInstallError, e:
        shout(e.strerror)
        return fsq.const('FSQ_FAIL_TMP')