def multi_args(p, cmd='celery worker', append='', prefix='', suffix=''): names = p.values options = dict(p.options) passthrough = p.passthrough ranges = len(names) == 1 if ranges: try: noderange = int(names[0]) except ValueError: pass else: names = [str(n) for n in range(1, noderange + 1)] prefix = 'celery' cmd = options.pop('--cmd', cmd) append = options.pop('--append', append) hostname = options.pop('--hostname', options.pop('-n', socket.gethostname())) prefix = options.pop('--prefix', prefix) or '' suffix = options.pop('--suffix', suffix) or hostname if suffix in ('""', "''"): suffix = '' for ns_name, ns_opts in list(items(p.namespaces)): if ',' in ns_name or (ranges and '-' in ns_name): for subns in parse_ns_range(ns_name, ranges): p.namespaces[subns].update(ns_opts) p.namespaces.pop(ns_name) # Numbers in args always refers to the index in the list of names. # (e.g. `start foo bar baz -c:1` where 1 is foo, 2 is bar, and so on). for ns_name, ns_opts in list(items(p.namespaces)): if ns_name.isdigit(): ns_index = int(ns_name) - 1 if ns_index < 0: raise KeyError('Indexes start at 1 got: %r' % (ns_name, )) try: p.namespaces[names[ns_index]].update(ns_opts) except IndexError: raise KeyError('No node at index %r' % (ns_name, )) for name in names: this_suffix = suffix if '@' in name: this_name = options['-n'] = name nodename, this_suffix = nodesplit(name) name = nodename else: nodename = '%s%s' % (prefix, name) this_name = options['-n'] = '%s@%s' % (nodename, this_suffix) expand = abbreviations({'%h': this_name, '%n': name, '%N': nodename, '%d': this_suffix}) argv = ([expand(cmd)] + [format_opt(opt, expand(value)) for opt, value in items(p.optmerge(name, options))] + [passthrough]) if append: argv.append(expand(append)) yield multi_args_t(this_name, argv, expand, name)
def multi_args(p, cmd="celery worker", append="", prefix="", suffix=""): names = p.values options = dict(p.options) passthrough = p.passthrough ranges = len(names) == 1 if ranges: try: noderange = int(names[0]) except ValueError: pass else: names = [str(n) for n in range(1, noderange + 1)] prefix = "celery" cmd = options.pop("--cmd", cmd) append = options.pop("--append", append) hostname = options.pop("--hostname", options.pop("-n", socket.gethostname())) prefix = options.pop("--prefix", prefix) or "" suffix = options.pop("--suffix", suffix) or hostname if suffix in ('""', "''"): suffix = "" for ns_name, ns_opts in list(items(p.namespaces)): if "," in ns_name or (ranges and "-" in ns_name): for subns in parse_ns_range(ns_name, ranges): p.namespaces[subns].update(ns_opts) p.namespaces.pop(ns_name) # Numbers in args always refers to the index in the list of names. # (e.g. `start foo bar baz -c:1` where 1 is foo, 2 is bar, and so on). for ns_name, ns_opts in list(items(p.namespaces)): if ns_name.isdigit(): ns_index = int(ns_name) - 1 if ns_index < 0: raise KeyError("Indexes start at 1 got: %r" % (ns_name,)) try: p.namespaces[names[ns_index]].update(ns_opts) except IndexError: raise KeyError("No node at index %r" % (ns_name,)) for name in names: hostname = suffix if "@" in name: nodename = options["-n"] = host_format(name) shortname, hostname = nodesplit(nodename) name = shortname else: shortname = "%s%s" % (prefix, name) nodename = options["-n"] = host_format("{0}@{1}".format(shortname, hostname)) expand = partial(node_format, nodename=nodename, N=shortname, d=hostname, h=nodename) argv = ( [expand(cmd)] + [format_opt(opt, expand(value)) for opt, value in items(p.optmerge(name, options))] + [passthrough] ) if append: argv.append(expand(append)) yield multi_args_t(nodename, argv, expand, name)
def multi_args(p, cmd='celery worker', append='', prefix='', suffix=''): names = p.values options = dict(p.options) passthrough = p.passthrough ranges = len(names) == 1 if ranges: try: noderange = int(names[0]) except ValueError: pass else: names = [str(n) for n in range(1, noderange + 1)] prefix = 'celery' cmd = options.pop('--cmd', cmd) append = options.pop('--append', append) hostname = options.pop('--hostname', options.pop('-n', socket.gethostname())) prefix = options.pop('--prefix', prefix) or '' suffix = options.pop('--suffix', suffix) or hostname if suffix in ('""', "''"): suffix = '' for ns_name, ns_opts in list(items(p.namespaces)): if ',' in ns_name or (ranges and '-' in ns_name): for subns in parse_ns_range(ns_name, ranges): p.namespaces[subns].update(ns_opts) p.namespaces.pop(ns_name) for name in names: this_suffix = suffix if '@' in name: this_name = options['-n'] = name nodename, this_suffix = nodesplit(name) name = nodename else: nodename = '%s%s' % (prefix, name) this_name = options['-n'] = '%s@%s' % (nodename, this_suffix) expand = abbreviations({ '%h': this_name, '%n': name, '%N': nodename, '%d': this_suffix }) argv = ([expand(cmd)] + [ format_opt(opt, expand(value)) for opt, value in items(p.optmerge(name, options)) ] + [passthrough]) if append: argv.append(expand(append)) yield multi_args_t(this_name, argv, expand, name)
def multi_args(p, cmd='celery worker', append='', prefix='', suffix=''): names = p.values options = dict(p.options) passthrough = p.passthrough ranges = len(names) == 1 if ranges: try: noderange = int(names[0]) except ValueError: pass else: names = [str(n) for n in range(1, noderange + 1)] prefix = 'celery' cmd = options.pop('--cmd', cmd) append = options.pop('--append', append) hostname = options.pop('--hostname', options.pop('-n', socket.gethostname())) prefix = options.pop('--prefix', prefix) or '' suffix = options.pop('--suffix', suffix) or hostname if suffix in ('""', "''"): suffix = '' for ns_name, ns_opts in list(items(p.namespaces)): if ',' in ns_name or (ranges and '-' in ns_name): for subns in parse_ns_range(ns_name, ranges): p.namespaces[subns].update(ns_opts) p.namespaces.pop(ns_name) for name in names: this_suffix = suffix if '@' in name: this_name = options['-n'] = name nodename, this_suffix = nodesplit(name) name = nodename else: nodename = '%s%s' % (prefix, name) this_name = options['-n'] = '%s@%s' % (nodename, this_suffix) expand = abbreviations({'%h': this_name, '%n': name, '%N': nodename, '%d': this_suffix}) argv = ([expand(cmd)] + [format_opt(opt, expand(value)) for opt, value in items(p.optmerge(name, options))] + [passthrough]) if append: argv.append(expand(append)) yield this_name, argv, expand
def _get_nodename(name, prefix, suffix, options): hostname = suffix if '@' in name: nodename = options['-n'] = host_format(name) shortname, hostname = nodesplit(nodename) name = shortname else: shortname = '%s%s' % (prefix, name) nodename = options['-n'] = host_format( '{0}@{1}'.format(shortname, hostname), ) expand = partial( node_format, nodename=nodename, N=shortname, d=hostname, h=nodename, i='%i', I='%I', ) return name, nodename, expand
def multi_args(p, cmd="celery worker", append="", prefix="", suffix=""): names = p.values options = dict(p.options) passthrough = p.passthrough ranges = len(names) == 1 if ranges: try: noderange = int(names[0]) except ValueError: pass else: names = list(map(str, range(1, noderange + 1))) prefix = "celery" cmd = options.pop("--cmd", cmd) append = options.pop("--append", append) hostname = options.pop("--hostname", options.pop("-n", socket.gethostname())) prefix = options.pop("--prefix", prefix) or "" suffix = options.pop("--suffix", suffix) or hostname if suffix in ('""', "''"): suffix = "" for ns_name, ns_opts in list(items(p.namespaces)): if "," in ns_name or (ranges and "-" in ns_name): for subns in parse_ns_range(ns_name, ranges): p.namespaces[subns].update(ns_opts) p.namespaces.pop(ns_name) for name in names: this_suffix = suffix if "@" in name: this_name = options["-n"] = name nodename, this_suffix = nodesplit(name) name = nodename else: nodename = "%s%s" % (prefix, name) this_name = options["-n"] = "%s@%s" % (nodename, this_suffix) expand = abbreviations({"%h": this_name, "%n": name, "%N": nodename, "%d": this_suffix}) argv = ( [expand(cmd)] + [format_opt(opt, expand(value)) for opt, value in items(p.optmerge(name, options))] + [passthrough] ) if append: argv.append(expand(append)) yield this_name, argv, expand
def default_nodename(hostname): name, host = nodesplit(hostname or '') return nodename(name or 'celery', host or socket.gethostname())
def node_format(self, s, nodename, **extra): name, host = nodesplit(nodename) return self._simple_format( s, host, n=name or NODENAME_DEFAULT, **extra)
def multi_args(p, cmd='celery worker', append='', prefix='', suffix=''): names = p.values options = dict(p.options) passthrough = p.passthrough ranges = len(names) == 1 if ranges: try: noderange = int(names[0]) except ValueError: pass else: names = [str(n) for n in range(1, noderange + 1)] prefix = 'celery' cmd = options.pop('--cmd', cmd) append = options.pop('--append', append) hostname = options.pop('--hostname', options.pop('-n', socket.gethostname())) prefix = options.pop('--prefix', prefix) or '' suffix = options.pop('--suffix', suffix) or hostname if suffix in ('""', "''"): suffix = '' for ns_name, ns_opts in list(items(p.namespaces)): if ',' in ns_name or (ranges and '-' in ns_name): for subns in parse_ns_range(ns_name, ranges): p.namespaces[subns].update(ns_opts) p.namespaces.pop(ns_name) # Numbers in args always refers to the index in the list of names. # (e.g. `start foo bar baz -c:1` where 1 is foo, 2 is bar, and so on). for ns_name, ns_opts in list(items(p.namespaces)): if ns_name.isdigit(): ns_index = int(ns_name) - 1 if ns_index < 0: raise KeyError('Indexes start at 1 got: %r' % (ns_name, )) try: p.namespaces[names[ns_index]].update(ns_opts) except IndexError: raise KeyError('No node at index %r' % (ns_name, )) for name in names: hostname = suffix if '@' in name: nodename = options['-n'] = host_format(name) shortname, hostname = nodesplit(nodename) name = shortname else: shortname = '%s%s' % (prefix, name) nodename = options['-n'] = host_format( '{0}@{1}'.format(shortname, hostname), ) expand = partial( node_format, nodename=nodename, N=shortname, d=hostname, h=nodename, i='%i', I='%I', ) argv = ([expand(cmd)] + [ format_opt(opt, expand(value)) for opt, value in items(p.optmerge(name, options)) ] + [passthrough]) if append: argv.append(expand(append)) yield multi_args_t(nodename, argv, expand, name)
def node_format(self, s, nodename, **extra): name, host = nodesplit(nodename) return self._simple_format(s, host, n=name or NODENAME_DEFAULT, **extra)
def default_nodename(hostname): name, host = nodesplit(hostname or "") return nodename(name or "celery", host or socket.gethostname())