text
stringlengths
0
828
md.postprocessors.add(processor.__name__.lower(), processor(md), '_end')"
1587,"def run(
paths,
output=_I_STILL_HATE_EVERYTHING,
recurse=core.flat,
sort_by=None,
ls=core.ls,
stdout=stdout,
):
""""""
Project-oriented directory and file information lister.
""""""
if output is _I_STILL_HATE_EVERYTHING:
output = core.columnized if stdout.isatty() else core.one_per_line
if sort_by is None:
if output == core.as_tree:
def sort_by(thing):
return (
thing.parent(),
thing.basename().lstrip(string.punctuation).lower(),
)
else:
def sort_by(thing):
return thing
def _sort_by(thing):
return not getattr(thing, ""_always_sorts_first"", False), sort_by(thing)
contents = [
path_and_children
for path in paths or (project.from_path(FilePath(""."")),)
for path_and_children in recurse(path=path, ls=ls)
]
for line in output(contents, sort_by=_sort_by):
stdout.write(line)
stdout.write(""\n"")"
1588,"def getCustomLogger(name, logLevel, logFormat='%(asctime)s %(levelname)-9s:%(name)s:%(module)s:%(funcName)s: %(message)s'):
'''
Set up logging
:param str name: What log level to set
:param str logLevel: What log level to use
:param str logFormat: Format string for logging
:rtype: logger
'''
assert isinstance(logFormat, basestring), (""logFormat must be a string but is %r"" % logFormat)
assert isinstance(logLevel, basestring), (""logLevel must be a string but is %r"" % logLevel)
assert isinstance(name, basestring), (""name must be a string but is %r"" % name)
validLogLevels = ['CRITICAL', 'DEBUG', 'ERROR', 'INFO', 'WARNING']
if not logLevel:
logLevel = 'DEBUG'
# If they don't specify a valid log level, err on the side of verbosity
if logLevel.upper() not in validLogLevels:
logLevel = 'DEBUG'
numericLevel = getattr(logging, logLevel.upper(), None)
if not isinstance(numericLevel, int):
raise ValueError(""Invalid log level: %s"" % logLevel)
logging.basicConfig(level=numericLevel, format=logFormat)
logger = logging.getLogger(name)
return logger"
1589,"def mkdir_p(path):
'''
Mimic `mkdir -p` since os module doesn't provide one.
:param str path: directory to create
'''
assert isinstance(path, basestring), (""path must be a string but is %r"" % path)
try:
os.makedirs(path)
except OSError as exception:
if exception.errno != errno.EEXIST:
raise"
1590,"def limit_chord_unlock_tasks(app):
""""""
Set max_retries for chord.unlock tasks to avoid infinitely looping
tasks. (see celery/celery#1700 or celery/celery#2725)
""""""
task = app.tasks['celery.chord_unlock']
if task.max_retries is None:
retries = getattr(app.conf, 'CHORD_UNLOCK_MAX_RETRIES', None)
task.max_retries = retries"
1591,"def setup_exchanges(app):
""""""
Setup result exchange to route all tasks to platform queue.
""""""
with app.producer_or_acquire() as P:
# Ensure all queues are noticed and configured with their
# appropriate exchange.
for q in app.amqp.queues.values():
P.maybe_declare(q)"
1592,"def setup_app(app, throw=True):
""""""
Ensure application is set up to expected configuration. This function is