Esempio n. 1
0
def which(name, additional_dirs=None):
    full_name = distutils.spawn.find_executable(name)
    if full_name:
        return full_name
    for dir_name in additional_dirs or []:
        full_name = joinpths(dirname(dirname(abspth(anvil.__file__))),
                             dir_name, name)
        if isfile(full_name):
            return full_name
    raise excp.FileException("Cannot find %s" % name)
Esempio n. 2
0
def which_first(bin_names, additional_dirs=None, ensure_executable=True):
    assert bin_names, 'Binary names required'
    for b in bin_names:
        try:
            return which(b,
                         additional_dirs=additional_dirs,
                         ensure_executable=ensure_executable)
        except excp.FileException:
            pass
    bin_names = ", ".join(bin_names)
    raise excp.FileException("Can't find any of %s" % bin_names)
Esempio n. 3
0
def touch_file(fn, die_if_there=True, quiet=False, file_size=0, tracewriter=None):
    if not isfile(fn):
        if not quiet:
            LOG.debug("Touching and truncating file %r (truncate size=%s)", fn, file_size)
        if not is_dry_run():
            mkdirslist(dirname(fn), tracewriter=tracewriter)
            with open(fn, "w") as fh:
                fh.truncate(file_size)
            if tracewriter:
                tracewriter.file_touched(fn)
    else:
        if die_if_there:
            msg = "Can not touch & truncate file %r since it already exists" % (fn)
            raise excp.FileException(msg)
Esempio n. 4
0
def touch_file(fn, die_if_there=True, quiet=False, file_size=0):
    if not isfile(fn):
        if not quiet:
            LOG.debug("Touching and truncating file %r (truncate size=%s)", fn,
                      file_size)
        if not is_dry_run():
            with open(fn, "w") as f:
                f.truncate(file_size)
    else:
        if die_if_there:
            msg = "Can not touch & truncate file %r since it already exists" % (
                fn)
            raise excp.FileException(msg)
    return fn
Esempio n. 5
0
def which(bin_name, additional_dirs=None, ensure_executable=True):
    def check_it(path):
        if not path:
            return False
        if not isfile(path):
            return False
        if ensure_executable and not os.access(path, os.X_OK):
            return False
        return True

    full_name = distutils.spawn.find_executable(bin_name)
    if check_it(full_name):
        return full_name
    if not additional_dirs:
        additional_dirs = []
    for dir_name in additional_dirs:
        full_name = joinpths(dirname(dirname(abspth(anvil.__file__))),
                             dir_name, bin_name)
        if check_it(full_name):
            return full_name
    raise excp.FileException("Can't find %s" % bin_name)