def add_versions(self, version_filename):
        """ class method to populate the .image_info file with the versions
        of the image.
        """
        self.logger.debug("adding the versions of the iso image")
        img_version_path = os.path.join(self.pkg_img_path, version_filename)

        # append the .image_info file with the version file information
        with open(self.img_info_path, "a") as img_fh:
            version_fh = TextFile(filename=img_version_path, lstrip_ws=True)
            version_line = version_fh.readline()
            while version_line:
                img_fh.write(version_line + '\n')
                version_line = version_fh.readline()
Ejemplo n.º 2
0
def parse_manifestin(template):
    """This function parses template file (usually MANIFEST.in)"""
    if not os.path.exists(template):
        return []

    template = TextFile(template, strip_comments=1, skip_blanks=1,
                        join_lines=1, lstrip_ws=1, rstrip_ws=1,
                        collapse_join=1)

    file_list = FileList()
    try:
        while True:
            line = template.readline()
            if line is None:  # end of file
                break

            try:
                file_list.process_template_line(line)
            # the call above can raise a DistutilsTemplateError for
            # malformed lines, or a ValueError from the lower-level
            # convert_path function
            except (DistutilsTemplateError, ValueError) as msg:
                print("%s, line %d: %s" % (template.filename,
                                           template.current_line,
                                           msg))
        return file_list.files
    finally:
        template.close()
Ejemplo n.º 3
0
    def read_template (self):
        """Read and parse manifest template file named by self.template.

        (usually "MANIFEST.in") The parsing and processing is done by
        'self.filelist', which updates itself accordingly.
        """
        log.info("reading manifest template '%s'", self.template)
        template = TextFile(self.template,
                            strip_comments=1,
                            skip_blanks=1,
                            join_lines=1,
                            lstrip_ws=1,
                            rstrip_ws=1,
                            collapse_join=1)

        while 1:
            line = template.readline()
            if line is None:            # end of file
                break

            try:
                self.filelist.process_template_line(line)
            except DistutilsTemplateError, msg:
                self.warn("%s, line %d: %s" % (template.filename,
                                               template.current_line,
                                               msg))
Ejemplo n.º 4
0
	def read_from_file(self, data_file, append_flag = False, filter = None, lagramge_flag = False):
		from distutils.text_file import TextFile;
		from string import split, atof;

		f = TextFile(filename = data_file);

		read_vars_flag = not append_flag or (self.length == 0);

		line = f.readline();
		if read_vars_flag:
			if lagramge_flag:
				self.vars = line[-1].split(" ");
			else:
				self.vars = line.split(" ");
			for v in self.vars: self.data[v] = [];

		line_index = -1;
		for line in f.readlines():
			line_index = line_index + 1;
			if (filter <> None) and (line_index not in filter): continue;

			if lagramge_flag:
				vals = line[:-1].split(" ");
			else:
				vals = line.split(" ");
			for i in range(len(vals)): 
				if vals[i] <> "?":
					self.data[self.vars[i]].append(atof(vals[i]));
				else:
					self.data[self.vars[i]].append(vals[i]);

			self.length = self.length + 1;

		f.close();
Ejemplo n.º 5
0
def _data_files():
    """List files to be copied to the TAU Commander installation.
    
    Start with the files listed in MANIFEST.in, then exclude files that should not be installed.
    """
    from distutils.filelist import FileList
    from distutils.text_file import TextFile
    from distutils.errors import DistutilsTemplateError
    filelist = FileList()
    template = TextFile(os.path.join(PACKAGE_TOPDIR, 'MANIFEST.in'),
                        strip_comments=1, skip_blanks=1, join_lines=1, 
                        lstrip_ws=1, rstrip_ws=1, collapse_join=1)
    try:
        while True:
            line = template.readline()
            if line is None:
                break
            try:
                filelist.process_template_line(line)
            except (DistutilsTemplateError, ValueError) as err:
                print "%s, line %d: %s" % (template.filename, template.current_line, err)
    finally:
        template.close()
    excluded = ['Makefile', 'VERSION', 'MANIFEST.in', '*Miniconda*']
    data_files = []
    for path in filelist.files:
        for excl in excluded:
            if fnmatch.fnmatchcase(path, excl):
                break
        else:
            data_files.append((os.path.dirname(path), [path]))
    return data_files
Ejemplo n.º 6
0
    def read_template(self):
        """Read and parse manifest template file named by self.template.

        (usually "MANIFEST.in") The parsing and processing is done by
        'self.filelist', which updates itself accordingly.
        """
        log.info("reading manifest template '%s'", self.template)
        template = TextFile(
            self.template, strip_comments=1, skip_blanks=1, join_lines=1, lstrip_ws=1, rstrip_ws=1, collapse_join=1
        )

        try:
            while True:
                line = template.readline()
                if line is None:  # end of file
                    break

                try:
                    self.filelist.process_template_line(line)
                # the call above can raise a DistutilsTemplateError for
                # malformed lines, or a ValueError from the lower-level
                # convert_path function
                except (DistutilsTemplateError, ValueError) as msg:
                    self.warn("%s, line %d: %s" % (template.filename, template.current_line, msg))
        finally:
            template.close()
Ejemplo n.º 7
0
def read_setup_file (filename):
    from distutils.sysconfig import \
         parse_makefile, expand_makefile_vars, _variable_rx
    from distutils.text_file import TextFile
    from distutils.util import split_quoted

    # First pass over the file to gather "VAR = VALUE" assignments.
    vars = parse_makefile(filename)

    # Second pass to gobble up the real content: lines of the form
    #   <module> ... [<sourcefile> ...] [<cpparg> ...] [<library> ...]
    file = TextFile(filename,
                    strip_comments=1, skip_blanks=1, join_lines=1,
                    lstrip_ws=1, rstrip_ws=1)
    extensions = []

    while 1:
        line = file.readline()
        if line is None:                # eof
            break
        if _variable_rx.match(line):    # VAR=VALUE, handled in first pass
            continue

        if line[0] == line[-1] == "*":
            file.warn("'%s' lines not handled yet" % line)
            continue

        #print "original line: " + line
        line = expand_makefile_vars(line, vars)
        words = split_quoted(line)
        #print "expanded line: " + line

        # NB. this parses a slightly different syntax than the old
        # makesetup script: here, there must be exactly one extension per
        # line, and it must be the first word of the line.  I have no idea
        # why the old syntax supported multiple extensions per line, as
        # they all wind up being the same.

        module = words[0]
        ext = Extension(module, [])
        append_next_word = None

        for word in words[1:]:
            if append_next_word is not None:
                append_next_word.append(word)
                append_next_word = None
                continue

            suffix = os.path.splitext(word)[1]
            switch = word[0:2] ; value = word[2:]

            if suffix in (".c", ".cc", ".cpp", ".cxx", ".c++", ".m", ".mm"):
                # hmm, should we do something about C vs. C++ sources?
                # or leave it up to the CCompiler implementation to
                # worry about?
                ext.sources.append(word)
            elif switch == "-I":
                ext.include_dirs.append(value)
            elif
Ejemplo n.º 8
0
def parse_cache(filename):
    substitutions = {}
    try:
        with open(filename, 'r') as cache:
            text_file = TextFile(filename, cache, strip_comments=True,
                                 lstrip_ws=True, rstrip_ws=True,
                                 skip_blanks=True, join_lines=True)
            line = text_file.readline()
            while line is not None:
                match = config_pattern.fullmatch(line)
                if not match:
                    raise ConfigureError("{}, {}".format(filename,
                                                         text_file.gen_error(
                                                             "Invalid configure cache")))
                substitutions[match.group("name")] = match.group("value")
                line = text_file.readline()
    except FileNotFoundError:
        pass
    return substitutions
Ejemplo n.º 9
0
    def get_file_list(self):
        self._get_file_list()
        manifest_filelist = self.filelist
        source_filelist = FileList()
        allfiles = self.filelist.allfiles
        if allfiles:
            source_filelist.set_allfiles(allfiles)
        else:
            source_filelist.findall()
        source_filelist.extend(source_filelist.allfiles)
        # Check for template (usually "MANIFEST.in")
        if os.path.isfile(self.template):
            template = TextFile(self.template,
                                strip_comments=1,
                                skip_blanks=1,
                                join_lines=1,
                                lstrip_ws=1,
                                rstrip_ws=1,
                                collapse_join=1)
            while 1:
                line = template.readline()
                if line is None:            # end of file
                    break
                try:
                    source_filelist.process_template_line(line)
                except DistutilsTemplateError:
                    # Already been warned by "real" filelist
                    pass
        if self.prune:
            try:
                self.filelist = source_filelist
                self.prune_file_list()
            finally:
                self.filelist = manifest_filelist
        source_filelist.sort()
        source_filelist.remove_duplicates()

        # Ensure file paths are formatted the same
        # This removes any dot-slashes and converts all slashes to
        # OS-specific separators.
        manifest = set(map(os.path.normpath, manifest_filelist.files))
        missing = False
        for filename in imap(os.path.normpath, source_filelist.files):
            if filename not in manifest:
                self.warn('missing from source distribution: %s' % filename)
                missing = True
        if missing:
            raw_input('WARNING: Not all source files in distribution! '
                      ' Press <Enter> to continue.')
Ejemplo n.º 10
0
def parse_makefile(fn, g=None):
    """Parse a Makefile-style file.

    A dictionary containing name/value pairs is returned.  If an
    optional dictionary is passed in as the second argument, it is
    used instead of a new dictionary.
    """
    from distutils.text_file import TextFile
    fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1)

    if g is None:
        g = {}
    done = {}
    notdone = {}

    while 1:
        line = fp.readline()
        if line is None:  # eof
            break
        m = _variable_rx.match(line)
        if m:
            n, v = m.group(1, 2)
            v = string.strip(v)
            if "$" in v:
                notdone[n] = v
            else:
                try:
                    v = int(v)
                except ValueError:
                    pass
                done[n] = v

    # do variable interpolation here
    while notdone:
        for name in notdone.keys():
            value = notdone[name]
            m = _findvar1_rx.search(value) or _findvar2_rx.search(value)
            if m:
                n = m.group(1)
                found = True
                if n in done:
                    item = str(done[n])
                elif n in notdone:
                    # get it on a subsequent round
                    found = False
                elif n in os.environ:
                    # do it like make: fall back to environment
                    item = os.environ[n]
                else:
                    done[n] = item = ""
                if found:
                    after = value[m.end():]
                    value = value[:m.start()] + item + after
                    if "$" in after:
                        notdone[name] = value
                    else:
                        try:
                            value = int(value)
                        except ValueError:
                            done[name] = string.strip(value)
                        else:
                            done[name] = value
                        del notdone[name]
            else:
                # bogus variable reference; just drop it since we can't deal
                del notdone[name]

    fp.close()

    # save the results in the global dictionary
    g.update(done)
    return g
Ejemplo n.º 11
0
def read_setup_file(filename):
    """Reads a Setup file and returns Extension instances."""
    from distutils.sysconfig import (parse_makefile, expand_makefile_vars,
                                     _variable_rx)

    from distutils.text_file import TextFile
    from distutils.util import split_quoted

    # First pass over the file to gather "VAR = VALUE" assignments.
    vars = parse_makefile(filename)

    # Second pass to gobble up the real content: lines of the form
    #   <module> ... [<sourcefile> ...] [<cpparg> ...] [<library> ...]
    file = TextFile(filename,
                    strip_comments=1, skip_blanks=1, join_lines=1,
                    lstrip_ws=1, rstrip_ws=1)
    extensions = []

    while True:
        line = file.readline()
        if line is None:                # eof
            break
        if _variable_rx.match(line):    # VAR=VALUE, handled in first pass
            continue

        if line[0] == line[-1] == "*":
            file.warn("'%s' lines not handled yet" % line)
            continue

        line = expand_makefile_vars(line, vars)
        words = split_quoted(line)

        # NB. this parses a slightly different syntax than the old
        # makesetup script: here, there must be exactly one extension per
        # line, and it must be the first word of the line.  I have no idea
        # why the old syntax supported multiple extensions per line, as
        # they all wind up being the same.

        module = words[0]
        ext = Extension(module, [])
        append_next_word = None

        for word in words[1:]:
            if append_next_word is not None:
                append_next_word.append(word)
                append_next_word = None
                continue

            suffix = os.path.splitext(word)[1]
            switch = word[0:2] ; value = word[2:]

            if suffix in (".c", ".cc", ".cpp", ".cxx", ".c++", ".m", ".mm"):
                # hmm, should we do something about C vs. C++ sources?
                # or leave it up to the CCompiler implementation to
                # worry about?
                ext.sources.append(word)
            elif switch == "-I":
                ext.include_dirs.append(value)
            elif switch == "-D":
                equals = value.find("=")
                if equals == -1:        # bare "-DFOO" -- no value
                    ext.define_macros.append((value, None))
                else:                   # "-DFOO=blah"
                    ext.define_macros.append((value[0:equals],
                                              value[equals+2:]))
            elif switch == "-U":
                ext.undef_macros.append(value)
            elif switch == "-C":        # only here 'cause makesetup has it!
                ext.extra_compile_args.append(word)
            elif switch == "-l":
                ext.libraries.append(value)
            elif switch == "-L":
                ext.library_dirs.append(value)
            elif switch == "-R":
                ext.runtime_library_dirs.append(value)
            elif word == "-rpath":
                append_next_word = ext.runtime_library_dirs
            elif word == "-Xlinker":
                append_next_word = ext.extra_link_args
            elif word == "-Xcompiler":
                append_next_word = ext.extra_compile_args
            elif switch == "-u":
                ext.extra_link_args.append(word)
                if not value:
                    append_next_word = ext.extra_link_args
            elif suffix in (".a", ".so", ".sl", ".o", ".dylib"):
                # NB. a really faithful emulation of makesetup would
                # append a .o file to extra_objects only if it
                # had a slash in it; otherwise, it would s/.o/.c/
                # and append it to sources.  Hmmmm.
                ext.extra_objects.append(word)
            else:
                file.warn("unrecognized argument '%s'" % word)

        extensions.append(ext)

    return extensions
Ejemplo n.º 12
0
def makefile(fileobj, dct=None):
    """Parse a Makefile-style file.

    A dictionary containing name/value pairs is returned.  If an
    optional dictionary is passed in as the second argument, it is
    used instead of a new dictionary.
    """
    fp = TextFile(file=fileobj,
                  strip_comments=1,
                  skip_blanks=1,
                  join_lines=1)

    if dct is None:
        dct = {}
    done = {}
    notdone = {}

    while 1:
        line = fp.readline()
        if line is None: # eof
            break
        m = _variable_rx.match(line)
        if m:
            n, v = m.group(1, 2)
            v = str.strip(v)
            if "$" in v:
                notdone[n] = v
            else:
                try: v = int(v)
                except ValueError: pass
                done[n] = v
                try: del notdone[n]
                except KeyError: pass
    fp.close()

    # do variable interpolation here
    while notdone:
        for name in list(notdone.keys()):
            value = notdone[name]
            m = _findvar1_rx.search(value) or _findvar2_rx.search(value)
            if m:
                n = m.group(1)
                found = True
                if n in done:
                    item = str(done[n])
                elif n in notdone:
                    # get it on a subsequent round
                    found = False
                else:
                    done[n] = item = ""
                if found:
                    after = value[m.end():]
                    value = value[:m.start()] + item + after
                    if "$" in after:
                        notdone[name] = value
                    else:
                        try: value = int(value)
                        except ValueError:
                            done[name] = str.strip(value)
                        else:
                            done[name] = value
                        del notdone[name]
            else:
                # bogus variable reference; 
                # just drop it since we can't deal
                del notdone[name]
    # save the results in the global dictionary
    dct.update(done)
    return dct
Ejemplo n.º 13
0
def parse_makefile(fn, g = None):
    """Parse a Makefile-style file.
    
    A dictionary containing name/value pairs is returned.  If an
    optional dictionary is passed in as the second argument, it is
    used instead of a new dictionary.
    """
    from distutils.text_file import TextFile
    fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1)
    if g is None:
        g = {}
    done = {}
    notdone = {}
    while 1:
        line = fp.readline()
        if line is None:
            break
        m = _variable_rx.match(line)
        if m:
            n, v = m.group(1, 2)
            v = v.strip()
            tmpv = v.replace('$$', '')
            if '$' in tmpv:
                notdone[n] = v
            else:
                try:
                    v = int(v)
                except ValueError:
                    done[n] = v.replace('$$', '$')
                else:
                    done[n] = v

    while notdone:
        for name in notdone.keys():
            value = notdone[name]
            m = _findvar1_rx.search(value) or _findvar2_rx.search(value)
            if m:
                n = m.group(1)
                found = True
                if n in done:
                    item = str(done[n])
                elif n in notdone:
                    found = False
                elif n in os.environ:
                    item = os.environ[n]
                else:
                    done[n] = item = ''
                if found:
                    after = value[m.end():]
                    value = value[:m.start()] + item + after
                    if '$' in after:
                        notdone[name] = value
                    else:
                        try:
                            value = int(value)
                        except ValueError:
                            done[name] = value.strip()
                        else:
                            done[name] = value

                        del notdone[name]
            else:
                del notdone[name]

    fp.close()
    for k, v in done.items():
        if isinstance(v, str):
            done[k] = v.strip()

    g.update(done)
    return g
Ejemplo n.º 14
0
def read_setup_file(filename):
    from distutils.sysconfig import parse_makefile, expand_makefile_vars, _variable_rx
    from distutils.text_file import TextFile
    from distutils.util import split_quoted
    vars = parse_makefile(filename)
    file = TextFile(filename, strip_comments=1, skip_blanks=1, join_lines=1, lstrip_ws=1, rstrip_ws=1)
    try:
        extensions = []
        while 1:
            line = file.readline()
            if line is None:
                break
            if _variable_rx.match(line):
                continue
                if line[0] == line[-1] == '*':
                    file.warn("'%s' lines not handled yet" % line)
                    continue
            line = expand_makefile_vars(line, vars)
            words = split_quoted(line)
            module = words[0]
            ext = Extension(module, [])
            append_next_word = None
            for word in words[1:]:
                if append_next_word is not None:
                    append_next_word.append(word)
                    append_next_word = None
                    continue
                suffix = os.path.splitext(word)[1]
                switch = word[0:2]
                value = word[2:]
                if suffix in ('.c', '.cc', '.cpp', '.cxx', '.c++', '.m', '.mm'):
                    ext.sources.append(word)
                elif switch == '-I':
                    ext.include_dirs.append(value)
                elif switch == '-D':
                    equals = string.find(value, '=')
                    if equals == -1:
                        ext.define_macros.append((value, None))
                    else:
                        ext.define_macros.append((value[0:equals], value[equals + 2:]))
                elif switch == '-U':
                    ext.undef_macros.append(value)
                elif switch == '-C':
                    ext.extra_compile_args.append(word)
                elif switch == '-l':
                    ext.libraries.append(value)
                elif switch == '-L':
                    ext.library_dirs.append(value)
                elif switch == '-R':
                    ext.runtime_library_dirs.append(value)
                elif word == '-rpath':
                    append_next_word = ext.runtime_library_dirs
                elif word == '-Xlinker':
                    append_next_word = ext.extra_link_args
                elif word == '-Xcompiler':
                    append_next_word = ext.extra_compile_args
                elif switch == '-u':
                    ext.extra_link_args.append(word)
                    if not value:
                        append_next_word = ext.extra_link_args
                elif word == '-Xcompiler':
                    append_next_word = ext.extra_compile_args
                elif switch == '-u':
                    ext.extra_link_args.append(word)
                    if not value:
                        append_next_word = ext.extra_link_args
                elif suffix in ('.a', '.so', '.sl', '.o', '.dylib'):
                    ext.extra_objects.append(word)
                else:
                    file.warn("unrecognized argument '%s'" % word)

            extensions.append(ext)

    finally:
        file.close()

    return extensions
def read_setup_file(filename):
    from distutils.sysconfig import \
         parse_makefile, expand_makefile_vars, _variable_rx
    from distutils.text_file import TextFile
    from distutils.util import split_quoted

    # First pass over the file to gather "VAR = VALUE" assignments.
    vars = parse_makefile(filename)

    # Second pass to gobble up the real content: lines of the form
    #   <module> ... [<sourcefile> ...] [<cpparg> ...] [<library> ...]
    file = TextFile(filename,
                    strip_comments=1,
                    skip_blanks=1,
                    join_lines=1,
                    lstrip_ws=1,
                    rstrip_ws=1)
    extensions = []

    while 1:
        line = file.readline()
        if line is None:  # eof
            break
        if _variable_rx.match(line):  # VAR=VALUE, handled in first pass
            continue

        if line[0] == line[-1] == "*":
            file.warn("'%s' lines not handled yet" % line)
            continue

        #print "original line: " + line
        line = expand_makefile_vars(line, vars)
        words = split_quoted(line)
        #print "expanded line: " + line

        # NB. this parses a slightly different syntax than the old
        # makesetup script: here, there must be exactly one extension per
        # line, and it must be the first word of the line.  I have no idea
        # why the old syntax supported multiple extensions per line, as
        # they all wind up being the same.

        module = words[0]
        ext = Extension(module, [])
        append_next_word = None

        for word in words[1:]:
            if append_next_word is not None:
                append_next_word.append(word)
                append_next_word = None
                continue

            suffix = os.path.splitext(word)[1]
            switch = word[0:2]
            value = word[2:]

            if suffix in (".c", ".cc", ".cpp", ".cxx", ".c++"):
                # hmm, should we do something about C vs. C++ sources?
                # or leave it up to the CCompiler implementation to
                # worry about?
                ext.sources.append(word)
            elif switch == "-I":
                ext.include_dirs.append(value)
            elif switch == "-D":
                equals = string.find(value, "=")
                if equals == -1:  # bare "-DFOO" -- no value
                    ext.define_macros.append((value, None))
                else:  # "-DFOO=blah"
                    ext.define_macros.append(
                        (value[0:equals], value[equals + 2:]))
            elif switch == "-U":
                ext.undef_macros.append(value)
            elif switch == "-C":  # only here 'cause makesetup has it!
                ext.extra_compile_args.append(word)
            elif switch == "-l":
                ext.libraries.append(value)
            elif switch == "-L":
                ext.library_dirs.append(value)
            elif switch == "-R":
                ext.runtime_library_dirs.append(value)
            elif word == "-rpath":
                append_next_word = ext.runtime_library_dirs
            elif word == "-Xlinker":
                append_next_word = ext.extra_link_args
            elif switch == "-u":
                ext.extra_link_args.append(word)
                if not value:
                    append_next_word = ext.extra_link_args
            elif suffix in (".a", ".so", ".sl", ".o"):
                # NB. a really faithful emulation of makesetup would
                # append a .o file to extra_objects only if it
                # had a slash in it; otherwise, it would s/.o/.c/
                # and append it to sources.  Hmmmm.
                ext.extra_objects.append(word)
            else:
                file.warn("unrecognized argument '%s'" % word)

        extensions.append(ext)

        #print "module:", module
        #print "source files:", source_files
        #print "cpp args:", cpp_args
        #print "lib args:", library_args

        #extensions[module] = { 'sources': source_files,
        #                       'cpp_args': cpp_args,
        #                       'lib_args': library_args }

    return extensions
Ejemplo n.º 16
0
def parse_makefile(fn, g=None):
    """Parse a Makefile-style file.

    A dictionary containing name/value pairs is returned.  If an
    optional dictionary is passed in as the second argument, it is
    used instead of a new dictionary.
    """
    from distutils.text_file import TextFile
    fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1)

    if g is None:
        g = {}
    done = {}
    notdone = {}

    while 1:
        line = fp.readline()
        if line is None:                # eof
            break
        m = _variable_rx.match(line)
        if m:
            n, v = m.group(1, 2)
            v = string.strip(v)
            if "$" in v:
                notdone[n] = v
            else:
                try: v = int(v)
                except ValueError: pass
                done[n] = v

    # do variable interpolation here
    while notdone:
        for name in notdone.keys():
            value = notdone[name]
            m = _findvar1_rx.search(value) or _findvar2_rx.search(value)
            if m:
                n = m.group(1)
                found = True
                if done.has_key(n):
                    item = str(done[n])
                elif notdone.has_key(n):
                    # get it on a subsequent round
                    found = False
                elif os.environ.has_key(n):
                    # do it like make: fall back to environment
                    item = os.environ[n]
                else:
                    done[n] = item = ""
                if found:
                    after = value[m.end():]
                    value = value[:m.start()] + item + after
                    if "$" in after:
                        notdone[name] = value
                    else:
                        try: value = int(value)
                        except ValueError:
                            done[name] = string.strip(value)
                        else:
                            done[name] = value
                        del notdone[name]
            else:
                # bogus variable reference; just drop it since we can't deal
                del notdone[name]

    fp.close()

    # save the results in the global dictionary
    g.update(done)
    return g
Ejemplo n.º 17
0
"""Provide access to Python's configuration information.  The specific
Ejemplo n.º 18
0
"""distutils.extension
Ejemplo n.º 19
0
def parse_makefile(fn, g=None):
    """Parse a Makefile-style file.

    A dictionary containing name/value pairs is returned.  If an
    optional dictionary is passed in as the second argument, it is
    used instead of a new dictionary.
    """
    from distutils.text_file import TextFile
    fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1, errors="surrogateescape")

    if g is None:
        g = {}
    done = {}
    notdone = {}

    while True:
        line = fp.readline()
        if line is None: # eof
            break
        m = _variable_rx.match(line)
        if m:
            n, v = m.group(1, 2)
            v = v.strip()
            # `$$' is a literal `$' in make
            tmpv = v.replace('$$', '')

            if "$" in tmpv:
                notdone[n] = v
            else:
                try:
                    v = int(v)
                except ValueError:
                    # insert literal `$'
                    done[n] = v.replace('$$', '$')
                else:
                    done[n] = v

    # Variables with a 'PY_' prefix in the makefile. These need to
    # be made available without that prefix through sysconfig.
    # Special care is needed to ensure that variable expansion works, even
    # if the expansion uses the name without a prefix.
    renamed_variables = ('CFLAGS', 'LDFLAGS', 'CPPFLAGS')

    # do variable interpolation here
    while notdone:
        for name in list(notdone):
            value = notdone[name]
            m = _findvar1_rx.search(value) or _findvar2_rx.search(value)
            if m:
                n = m.group(1)
                found = True
                if n in done:
                    item = str(done[n])
                elif n in notdone:
                    # get it on a subsequent round
                    found = False
                elif n in os.environ:
                    # do it like make: fall back to environment
                    item = os.environ[n]

                elif n in renamed_variables:
                    if name.startswith('PY_') and name[3:] in renamed_variables:
                        item = ""

                    elif 'PY_' + n in notdone:
                        found = False

                    else:
                        item = str(done['PY_' + n])
                else:
                    done[n] = item = ""
                if found:
                    after = value[m.end():]
                    value = value[:m.start()] + item + after
                    if "$" in after:
                        notdone[name] = value
                    else:
                        try: value = int(value)
                        except ValueError:
                            done[name] = value.strip()
                        else:
                            done[name] = value
                        del notdone[name]

                        if name.startswith('PY_') \
                            and name[3:] in renamed_variables:

                            name = name[3:]
                            if name not in done:
                                done[name] = value
            else:
                # bogus variable reference; just drop it since we can't deal
                del notdone[name]

    fp.close()

    # strip spurious spaces
    for k, v in done.items():
        if isinstance(v, str):
            done[k] = v.strip()

    # save the results in the global dictionary
    g.update(done)
    return g
Ejemplo n.º 20
0
def parse_makefile(fn, g=None):
    """Parse a Makefile-style file.
    
    A dictionary containing name/value pairs is returned.  If an
    optional dictionary is passed in as the second argument, it is
    used instead of a new dictionary.
    """
    from distutils.text_file import TextFile
    fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1)
    if g is None:
        g = {}
    done = {}
    notdone = {}
    while 1:
        line = fp.readline()
        if line is None:
            break
        m = _variable_rx.match(line)
        if m:
            n, v = m.group(1, 2)
            v = v.strip()
            tmpv = v.replace('$$', '')
            if '$' in tmpv:
                notdone[n] = v
            else:
                try:
                    v = int(v)
                except ValueError:
                    done[n] = v.replace('$$', '$')
                else:
                    done[n] = v

    while notdone:
        for name in notdone.keys():
            value = notdone[name]
            m = _findvar1_rx.search(value) or _findvar2_rx.search(value)
            if m:
                n = m.group(1)
                found = True
                if n in done:
                    item = str(done[n])
                elif n in notdone:
                    found = False
                elif n in os.environ:
                    item = os.environ[n]
                else:
                    done[n] = item = ''
                if found:
                    after = value[m.end():]
                    value = value[:m.start()] + item + after
                    if '$' in after:
                        notdone[name] = value
                    else:
                        try:
                            value = int(value)
                        except ValueError:
                            done[name] = value.strip()
                        else:
                            done[name] = value

                        del notdone[name]
            else:
                del notdone[name]

    fp.close()
    for k, v in done.items():
        if isinstance(v, str):
            done[k] = v.strip()

    g.update(done)
    return g
Ejemplo n.º 21
0
def read_setup_file(filename):
    """Reads a Setup file and returns Extension instances."""
    from distutils.sysconfig import parse_makefile, expand_makefile_vars, _variable_rx
    from distutils.text_file import TextFile
    from distutils.util import split_quoted
    vars = parse_makefile(filename)
    file = TextFile(filename, strip_comments=1, skip_blanks=1, join_lines=1,
        lstrip_ws=1, rstrip_ws=1)
    try:
        extensions = []
        while True:
            line = file.readline()
            if line is None:
                break
            if _variable_rx.match(line):
                continue
            if line[0] == line[-1] == '*':
                file.warn("'%s' lines not handled yet" % line)
                continue
            line = expand_makefile_vars(line, vars)
            words = split_quoted(line)
            module = words[0]
            ext = Extension(module, [])
            append_next_word = None
            for word in words[1:]:
                if append_next_word is not None:
                    append_next_word.append(word)
                    append_next_word = None
                    continue
                suffix = os.path.splitext(word)[1]
                switch = word[0:2]
                value = word[2:]
                if suffix in ('.c', '.cc', '.cpp', '.cxx', '.c++', '.m', '.mm'
                    ):
                    ext.sources.append(word)
                elif switch == '-I':
                    ext.include_dirs.append(value)
                elif switch == '-D':
                    equals = value.find('=')
                    if equals == -1:
                        ext.define_macros.append((value, None))
                    else:
                        ext.define_macros.append((value[0:equals], value[
                            equals + 2:]))
                elif switch == '-U':
                    ext.undef_macros.append(value)
                elif switch == '-C':
                    ext.extra_compile_args.append(word)
                elif switch == '-l':
                    ext.libraries.append(value)
                elif switch == '-L':
                    ext.library_dirs.append(value)
                elif switch == '-R':
                    ext.runtime_library_dirs.append(value)
                elif word == '-rpath':
                    append_next_word = ext.runtime_library_dirs
                elif word == '-Xlinker':
                    append_next_word = ext.extra_link_args
                elif word == '-Xcompiler':
                    append_next_word = ext.extra_compile_args
                elif switch == '-u':
                    ext.extra_link_args.append(word)
                    if not value:
                        append_next_word = ext.extra_link_args
                elif suffix in ('.a', '.so', '.sl', '.o', '.dylib'):
                    ext.extra_objects.append(word)
                else:
                    file.warn("unrecognized argument '%s'" % word)
            extensions.append(ext)
    finally:
        file.close()
    return extensions
def parse_makefile(fn, existing_modules=None):
    """Parse a Makefile-style file.

    A dictionary containing name/value pairs is returned.  If an
    optional dictionary is passed in as the second argument, it is
    used instead of a new dictionary.
    """
    from distutils.text_file import TextFile
    fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1)

    local_modules = ModulePool()
    if existing_modules:
        local_modules.pool.update(existing_modules.pool) 
    variable_pool = AndroidMKVariablePool(fn)

    current_module = None
    within_func_definition = False

    while 1:
        line = fp.readline()
        if line is None:  # eof
            break
        if line.upper() == "include $(CLEAR_VARS)".upper():
            current_module = None
        if line.lower().startswith("define "):
            within_func_definition = True
        if line.lower().strip() == "endef":
            within_func_definition = False

        if within_func_definition:
#don't parse the line if we're within function definition
            continue

        match = makefile_parser.VariablePool.VAR_ASSIGNMENT_RX.match(line)
        if match:
            (var_name, var_value) = variable_pool.add_variable(match)
            if not current_module:
                current_module = Module()
                current_module.directory = os.path.dirname(fn)

            if var_name == "LOCAL_MODULE":
                var_value = variable_pool.eval_expression(var_value)
                temp_module = local_modules.find_module(var_value)
                if temp_module and temp_module != current_module:
                    temp_module.src = current_module.src
                    temp_module.depends = current_module.depends
                    current_module = temp_module
                current_module.name = var_value
                local_modules.add_module(current_module)

            if var_name == "LOCAL_SRC_FILES":
                if current_module:
                    current_module.src = var_value

            if var_name == "LOCAL_STATIC_LIBRARIES" or \
                    var_name == "LOCAL_SHARED_LIBRARIES":
                if current_module:
                    for i in var_value.split():
                        current_module.depends.append(i)

    fp.close()

    # update values in modules
    for (key,item) in local_modules.pool.items():
        number = len(item.depends)
        index = 0
        while index < number:
            value = item.depends[index]
            value = variable_pool.eval_expression(value)
            items = value.split()
            if len(items) > 0:
                item.depends[index] = items[0]
                item.depends.extend(items[1:])
                number += len(items) - 1
                index += 1
            else:
                item.depends.pop(index)
                number -= 1
    #print variable_pool.immediate_variables

    return local_modules
Ejemplo n.º 23
0
"""distutils.command.sdist
Ejemplo n.º 24
0
def parse_makefile(fn, g=None):
    """Parse a Makefile-style file.

    A dictionary containing name/value pairs is returned.  If an
    optional dictionary is passed in as the second argument, it is
    used instead of a new dictionary.
    """
    from distutils.text_file import TextFile
    fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1, errors="surrogateescape")

    if g is None:
        g = {}
    done = {}
    notdone = {}

    while True:
        line = fp.readline()
        if line is None: # eof
            break
        m = _variable_rx.match(line)
        if m:
            n, v = m.group(1, 2)
            v = v.strip()
            # `$$' is a literal `$' in make
            tmpv = v.replace('$$', '')

            if "$" in tmpv:
                notdone[n] = v
            else:
                try:
                    v = int(v)
                except ValueError:
                    # insert literal `$'
                    done[n] = v.replace('$$', '$')
                else:
                    done[n] = v

    # Variables with a 'PY_' prefix in the makefile. These need to
    # be made available without that prefix through sysconfig.
    # Special care is needed to ensure that variable expansion works, even
    # if the expansion uses the name without a prefix.
    renamed_variables = ('CFLAGS', 'LDFLAGS', 'CPPFLAGS')

    # do variable interpolation here
    while notdone:
        for name in list(notdone):
            value = notdone[name]
            m = _findvar1_rx.search(value) or _findvar2_rx.search(value)
            if m:
                n = m.group(1)
                found = True
                if n in done:
                    item = str(done[n])
                elif n in notdone:
                    # get it on a subsequent round
                    found = False
                elif n in os.environ:
                    # do it like make: fall back to environment
                    item = os.environ[n]

                elif n in renamed_variables:
                    if name.startswith('PY_') and name[3:] in renamed_variables:
                        item = ""

                    elif 'PY_' + n in notdone:
                        found = False

                    else:
                        item = str(done['PY_' + n])
                else:
                    done[n] = item = ""
                if found:
                    after = value[m.end():]
                    value = value[:m.start()] + item + after
                    if "$" in after:
                        notdone[name] = value
                    else:
                        try: value = int(value)
                        except ValueError:
                            done[name] = value.strip()
                        else:
                            done[name] = value
                        del notdone[name]

                        if name.startswith('PY_') \
                            and name[3:] in renamed_variables:

                            name = name[3:]
                            if name not in done:
                                done[name] = value
            else:
                # bogus variable reference; just drop it since we can't deal
                del notdone[name]

    fp.close()

    # strip spurious spaces
    for k, v in done.items():
        if isinstance(v, str):
            done[k] = v.strip()

    # save the results in the global dictionary
    g.update(done)
    return g
Ejemplo n.º 25
0
def parse_makefile(fn, conf, g=None):
    """Parse a Makefile-style file.

    A dictionary containing name/value pairs is returned.  If an
    optional dictionary is passed in as the second argument, it is
    used instead of a new dictionary.
    """
    from distutils.text_file import TextFile
    fp = TextFile(fn,
                  strip_comments=1,
                  skip_blanks=1,
                  join_lines=1,
                  errors="surrogateescape")

    if g is None:
        g = {}
    done = {}
    notdone = {}

    while True:
        line = fp.readline()
        if line is None:  # eof
            break
        n = cond = app = v = None
        m = _variable_rx.match(line)
        if m:
            n, app, v = m.group(1, 2, 3)
        else:
            m = _variable_conditional_rx.match(line)
            if m:
                n, cond, app, v = m.group(1, 2, 3, 4)

        if v:
            v = v.strip()

            # `$$' is a literal `$' in make
            tmpv = v.replace('$$', '')

            if cond:
                boolean = cond in conf and conf[cond]
                n += ('-yes' if boolean else '-no')

            if "$" in tmpv:
                notdone[n] = v
            else:
                v = v.replace('$$', '$')
                if app:
                    if n not in done:
                        done[n] = v
                    else:
                        done[n] += ' ' + v
                else:
                    done[n] = v

    # hacky. just assume they were all +=
    notdone_done = {}
    # do variable interpolation here
    while notdone:
        for name in list(notdone):
            value = notdone[name]
            m = _findvar1_rx.search(value) or _findvar2_rx.search(value)
            if m:
                n = m.group(1)
                found = True
                if n in done:
                    item = str(done[n])
                elif n in notdone:
                    # get it on a subsequent round
                    found = False
                elif n in os.environ:
                    # do it like make: fall back to environment
                    item = os.environ[n]

                else:
                    notdone_done[n] = item = ""
                if found:
                    after = value[m.end():]
                    value = value[:m.start()] + item + after
                    if "$" in after:
                        notdone[name] = value
                    else:
                        notdone_done[name] = value
                        del notdone[name]
            else:
                # bogus variable reference; just drop it since we can't deal
                del notdone[name]
    for k in notdone_done:
        if k in done:
            done[k] += ' ' + notdone_done[k]
        else:
            done[k] = notdone_done[k]

    fp.close()

    # strip spurious spaces
    for k, v in done.items():
        if isinstance(v, str):
            done[k] = v.strip()

    # save the results in the global dictionary
    g.update(done)
    return g