Example #1
0
def rewrite_script(fn, prefix):
    """Take a file from the bin directory and rewrite it into the python-scripts
    directory after it passes some sanity checks for noarch pacakges"""

    # Load and check the source file for not being a binary
    src = join(prefix, 'Scripts' if ISWIN else 'bin', fn)
    with io.open(src, encoding=locale.getpreferredencoding()) as fi:
        try:
            data = fi.read()
        except UnicodeDecodeError:  # file is binary
            _error_exit("Noarch package contains binary script: %s" % fn)
    os.unlink(src)

    # Get rid of '-script.py' suffix on Windows
    if ISWIN and fn.endswith('-script.py'):
        fn = fn[:-10]

    # Check that it does have a #! python string, and skip it
    encoding = sys.stdout.encoding or 'utf8'

    m = SHEBANG_PAT.match(data.encode(encoding))
    if m and b'python' in m.group():
        new_data = data[data.find('\n') + 1:]
    elif ISWIN:
        new_data = data
    else:
        _error_exit("No python shebang in: %s" % fn)

    # Rewrite the file to the python-scripts directory
    dst_dir = join(prefix, 'python-scripts')
    _force_dir(dst_dir)
    with open(join(dst_dir, fn), 'w') as fo:
        fo.write(new_data)
    return fn
Example #2
0
def rewrite_script(fn):
    """Take a file from the bin directory and rewrite it into the python-scripts
    directory after it passes some sanity checks for noarch pacakges"""

    # Load and check the source file for not being a binary
    src = join(config.build_prefix, 'Scripts' if ISWIN else 'bin', fn)
    with io.open(src, encoding=locale.getpreferredencoding()) as fi:
        try:
            data = fi.read()
        except UnicodeDecodeError:  # file is binary
            _error_exit("Noarch package contains binary script: %s" % fn)
    os.unlink(src)

    # Get rid of '-script.py' suffix on Windows
    if ISWIN and fn.endswith('-script.py'):
        fn = fn[:-10]

    # Check that it does have a #! python string, and skip it
    encoding = sys.stdout.encoding or 'utf8'

    m = SHEBANG_PAT.match(data.encode(encoding))
    if m and b'python' in m.group():
        new_data = data[data.find('\n') + 1:]
    elif ISWIN:
        new_data = data
    else:
        _error_exit("No python shebang in: %s" % fn)

    # Rewrite the file to the python-scripts directory
    dst_dir = join(config.build_prefix, 'python-scripts')
    _force_dir(dst_dir)
    with open(join(dst_dir, fn), 'w') as fo:
        fo.write(new_data)
    return fn
Example #3
0
def rewrite_script(fn):
    src = join(config.build_prefix, 'bin', fn)
    with io.open(src, encoding=locale.getpreferredencoding()) as fi:
        try:
            data = fi.read()
        except UnicodeDecodeError:  # file is binary
            raise Exception("Binary: %s" % fn)
    os.unlink(src)

    m = SHEBANG_PAT.match(data)
    if not (m and 'python' in m.group()):
        raise Exception("No python shebang in: %s" % fn)
    new_data = data[data.find('\n') + 1:]

    dst_dir = join(config.build_prefix, 'python-scripts')
    if not isdir(dst_dir):
        os.makedirs(dst_dir)
    with open(join(dst_dir, fn), 'w') as fo:
        fo.write(new_data)
Example #4
0
def rewrite_script(fn):
    src = join(config.build_prefix, 'bin', fn)
    with io.open(src, encoding=locale.getpreferredencoding()) as fi:
        try:
            data = fi.read()
        except UnicodeDecodeError: # file is binary
            raise Exception("Binary: %s" % fn)
    os.unlink(src)

    m = SHEBANG_PAT.match(data)
    if not (m and 'python' in m.group()):
        raise Exception("No python shebang in: %s" % fn)
    new_data = data[data.find('\n') + 1:]

    dst_dir = join(config.build_prefix, 'python-scripts')
    if not isdir(dst_dir):
        os.makedirs(dst_dir)
    with open(join(dst_dir, fn), 'w') as fo:
        fo.write(new_data)
Example #5
0
def rewrite_script(fn):
    """Take a file from the bin directory and rewrite it into the python-scripts
    directory after it passes some sanity checks for noarch pacakges"""

    # Load and check the source file for not being a binary
    src = join(config.build_prefix, 'bin', fn)
    with io.open(src, encoding=locale.getpreferredencoding()) as fi:
        try:
            data = fi.read()
        except UnicodeDecodeError:  # file is binary
            _error_exit("Noarch package contains binary script: %s" % fn)
    os.unlink(src)

    # Check that it does have a #! python string
    m = SHEBANG_PAT.match(data)
    if not (m and 'python' in m.group()):
        _error_exit("No python shebang in: %s" % fn)

    # Rewrite the file to the python-scripts directory after skipping the #! line
    new_data = data[data.find('\n') + 1:]
    dst_dir = join(config.build_prefix, 'python-scripts')
    _force_dir(dst_dir)
    with open(join(dst_dir, fn), 'w') as fo:
        fo.write(new_data)
Example #6
0
def rewrite_script(fn):
    """Take a file from the bin directory and rewrite it into the python-scripts
    directory after it passes some sanity checks for noarch pacakges"""

    # Load and check the source file for not being a binary
    src = join(config.build_prefix, 'bin', fn)
    with io.open(src, encoding=locale.getpreferredencoding()) as fi:
        try:
            data = fi.read()
        except UnicodeDecodeError:  # file is binary
            _error_exit("Noarch package contains binary script: %s" % fn)
    os.unlink(src)

    # Check that it does have a #! python string
    m = SHEBANG_PAT.match(data)
    if not (m and 'python' in m.group()):
        _error_exit("No python shebang in: %s" % fn)

    # Rewrite the file to the python-scripts directory after skipping the #! line
    new_data = data[data.find('\n') + 1:]
    dst_dir = join(config.build_prefix, 'python-scripts')
    _force_dir(dst_dir)
    with open(join(dst_dir, fn), 'w') as fo:
        fo.write(new_data)