Example #1
0
def get_script_header(executable=SYS_EXECUTABLE, wininst=False):
    from distutils.command.build_scripts import first_line_re

    match = first_line_re.match(six.b(""))

    options = ""
    if match:
        options = match.group(1) or ""
        if options:
            options = " " + options
    if wininst:
        executable = "python.exe"
    else:
        executable = nt_quote_arg(executable)

    hdr = "#!%(executable)s%(options)s\n" % locals()
    if six.u(hdr).encode("ascii") != hdr:
        # Non-ascii path to sys.executable, use -x to prevent warnings
        if options:
            if options.strip().startswith("-"):
                options = " -x" + options.strip()[1:]
            # else: punt, we can't do it, let the warning happen anyway
        else:
            options = " -x"
    # executable = fix_jython_executable(executable, options)
    hdr = "#!%(executable)s%(options)s\n" % locals()
    return hdr
Example #2
0
def get_script_header(executable=SYS_EXECUTABLE, wininst=False):
    from distutils.command.build_scripts import first_line_re

    match = first_line_re.match(six.b(""))

    options = ''
    if match:
        options = match.group(1) or ''
        if options:
            options = ' ' + options
    if wininst:
        executable = "python.exe"
    else:
        executable = nt_quote_arg(executable)

    hdr = "#!%(executable)s%(options)s\n" % locals()
    if six.u(hdr).encode('ascii') != hdr:
        # Non-ascii path to sys.executable, use -x to prevent warnings
        if options:
            if options.strip().startswith('-'):
                options = ' -x' + options.strip()[1:]
            # else: punt, we can't do it, let the warning happen anyway
        else:
            options = ' -x'
    #executable = fix_jython_executable(executable, options)
    hdr = "#!%(executable)s%(options)s\n" % locals()
    return hdr
Example #3
0
def get_script_header(script_text, executable=easy_install.sys_executable,
                      wininst=False):
    from distutils.command.build_scripts import first_line_re
    first, rest = (script_text+'\n').split('\n',1)
    match = first_line_re.match(first)
    options = ''
    if match:
        script_text = rest
        options = match.group(1) or ''
        if options:
            options = ' '+options
    if wininst:
        executable = "python.exe"
    else:
        executable = easy_install.nt_quote_arg(executable)
    if options.find('-S') == -1:
        options += ' -S'
    shbang = "#!%(executable)s%(options)s\n" % locals()
    shbang += ("import sys, os\n"
               "join, dirname, abspath = os.path.join, os.path.dirname, os.path.abspath\n"
               "site_dirs = [join(dirname(dirname(abspath(__file__))), 'lib', 'python%s.%s' % tuple(sys.version_info[:2])), join(dirname(dirname(abspath(__file__))), 'lib', 'python')]\n"
               "sys.path[0:0] = site_dirs\n"
               "import site\n"
               "[site.addsitedir(d) for d in site_dirs]\n")
    return shbang
Example #4
0
def copy_file(self, infile, outfile, *args, **kw):
    if infile == version["__file__"]:
        if not self.dry_run:
            log.info("generating %s -> %s", infile, outfile)
            with open(outfile, "wb") as f:
                for x in sorted(version.iteritems()):
                    if not x[0].startswith("_"):
                        f.write("%s = %r\n" % x)
        return outfile, 1
    elif isinstance(self, build_py) and \
         os.stat(infile).st_mode & stat.S_IEXEC:
        if os.path.isdir(infile) and os.path.isdir(outfile):
            return (outfile, 0)
        # Adjust interpreter of OpenVPN hooks.
        with open(infile) as src:
            first_line = src.readline()
            m = first_line_re.match(first_line)
            if m and not self.dry_run:
                log.info("copying and adjusting %s -> %s", infile, outfile)
                executable = self.distribution.command_obj['build'].executable
                patched = "#!%s%s\n" % (executable, m.group(1) or '')
                patched += src.read()
                dst = os.open(outfile, os.O_CREAT | os.O_WRONLY | os.O_TRUNC)
                try:
                    os.write(dst, patched)
                finally:
                    os.close(dst)
                return outfile, 1
    cls, = self.__class__.__bases__
    return cls.copy_file(self, infile, outfile, *args, **kw)
Example #5
0
def copy_file(self, infile, outfile, *args, **kw):
    if infile == version["__file__"]:
        if not self.dry_run:
            log.info("generating %s -> %s", infile, outfile)
            with open(outfile, "wb") as f:
                for x in sorted(version.iteritems()):
                    if not x[0].startswith("_"):
                        f.write("%s = %r\n" % x)
        return outfile, 1
    elif isinstance(self, build_py) and \
         os.stat(infile).st_mode & stat.S_IEXEC:
        # Adjust interpreter of OpenVPN hooks.
        with open(infile) as src:
            first_line = src.readline()
            m = first_line_re.match(first_line)
            if m and not self.dry_run:
                log.info("copying and adjusting %s -> %s", infile, outfile)
                executable = self.distribution.command_obj['build'].executable
                patched = "#!%s%s\n" % (executable, m.group(1) or '')
                patched += src.read()
                dst = os.open(outfile, os.O_CREAT | os.O_WRONLY | os.O_TRUNC)
                try:
                    os.write(dst, patched)
                finally:
                    os.close(dst)
                return outfile, 1
    cls, = self.__class__.__bases__
    return cls.copy_file(self, infile, outfile, *args, **kw)
Example #6
0
    def _transform_script_name(self, script_name):
        script_base = os.path.basename(script_name)
        filu = open(script_name, 'r')
        firstline = filu.readline()
        filu.close()
        if firstline:
            match = first_line_re.match(firstline)
        else:
            match = None

        file_name = script_base
        if match:
            if self.distribution.add_prefix and not script_base.endswith(
                    ".py"):
                file_name = "%s.py" % script_base
            if self.distribution.remove_prefix and script_base.endswith(".py"):
                file_name = script_base[:-3]

        if not file_name.startswith("tema."):
            file_name = "tema.%s" % file_name

        return file_name
Example #7
0
    def _transform_script_name(self,script_name):
        script_base = os.path.basename(script_name)
        filu = open(script_name,'r')
        firstline = filu.readline()
        filu.close()
        if firstline:
            match = first_line_re.match(firstline)
        else:
            match = None
                    
        file_name = script_base
        if match:
            if self.distribution.add_prefix and not script_base.endswith(".py"):
                file_name = "%s.py" % script_base
            if self.distribution.remove_prefix and script_base.endswith(".py"):
                file_name = script_base[:-3]


        if not file_name.startswith("tema."):
            file_name = "tema.%s" % file_name

        return file_name