Example #1
0
def misc_walker(arguments, directory_name, names):
    """
    Walker method to be used by the path walker for running the
    normalization misc process.

    :type arguments: Tuple
    :param arguments: The arguments tuple sent by the walker method.
    :type directory_name: String
    :param directory_name: The name of the current directory in the walk.
    :type names: List
    :param names: The list of names in the current directory.
    """

    # unpacks the arguments tuple into its values
    file_exclusion, configuration = arguments

    # retrieves the complete set of extensions registered for the chmod
    # operations and then gathers their keys as the basis for the extension
    # based filtering operations (optimization)
    chmod = configuration.get("chmod", {})
    extensions = legacy.keys(chmod)
    extensions = tuple(extensions)

    # tries to run the handle ignore operation for the current set of names and
    # in case there's a processing returns the control flow immediately as no
    # more handling is meant to occur for the current operation (ignored)
    if extra.handle_ignore(names): return

    # removes the complete set of names that are meant to be excluded from the
    # current set names to be visit (avoid visiting them)
    for exclusion in file_exclusion:
        if not exclusion in names: continue
        names.remove(exclusion)

    # retrieves the valid names for the names list (removes directory entries)
    valid_complete_names = [directory_name + "/" + name for name in names\
        if not os.path.isdir(directory_name + "/" + name)]

    # filters the names with non valid file extensions so that only the
    # ones that conform with the misc source ones are selected
    valid_complete_names = [os.path.normpath(name) for name in valid_complete_names\
        if name.endswith(tuple(extensions))]

    # iterates over all the valid complete names with valid structure
    # as defined by the misc file structure definition
    for valid_complete_name in valid_complete_names:
        # print a message a message about the misc
        # operation that is going to be performed and
        # then runs the operation with the correct path
        extra.echo("Running the misc operations on file: %s" % valid_complete_name)
        misc_file(valid_complete_name, configuration)
Example #2
0
    def _into(self, kwargs):
        buffer = self.owner._buffer()

        is_first = True

        names = legacy.keys(kwargs)
        names_s = ", ".join(names)

        buffer.write("(")
        buffer.write(names_s)
        buffer.write(") values(")

        for value in legacy.values(kwargs):
            if is_first: is_first = False
            else: buffer.write(", ")
            buffer.write_value(value)

        buffer.write(')')

        return buffer.join()
Example #3
0
def pydev_file(file_path, fix = True):
    """
    Runs the pydev configuration file normalization that consists
    in the definition in order of each of the xml lines.

    This operation should fail with an exception in case the
    structure of the xml document is not the expected one.

    :type file_path: String
    :param file_path: The path to the file that contains the
    pydev configuration specification in xml.
    :type fix: bool
    :param fix: If any "fixable" error in the pydev project
    file should be automatically fixes using the known heuristics,
    this is a dangerous option as errors may be created.
    """

    paths = []
    properties = dict()
    buffer = []

    xmldoc = xml.dom.minidom.parse(file_path)
    nodes = xmldoc.getElementsByTagName("pydev_property")

    for node in nodes:
        value = text_value(node)
        name = node.attributes["name"].value
        properties[name] = value

    nodes = xmldoc.getElementsByTagName("pydev_pathproperty")
    nodes = nodes[0].childNodes if nodes else []

    for node in nodes:
        value = text_value(node)
        if not value: continue
        paths.append(value)

    for key in legacy.keys(properties):
        if key in VALID_PROPERTIES: continue
        raise RuntimeError("Invalid property '%s'" % key)

    if fix: paths, properties = fix_values(paths, properties)

    python_version = properties.get("org.python.pydev.PYTHON_PROJECT_VERSION", None)
    if not python_version: extra.warn("No python version defined")
    elif not python_version == "python 2.6": extra.warn("Python version not 2.6")

    for path in paths:
        if path.startswith("/${PROJECT_DIR_NAME}"): continue
        extra.warn("Project directory path not normalized '%s'" % path)

    property_keys = legacy.keys(properties)
    property_keys.sort()

    buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n")
    buffer.append("<?eclipse-pydev version=\"1.0\"?><pydev_project>\n")
    if paths: buffer.append("<pydev_pathproperty name=\"org.python.pydev.PROJECT_SOURCE_PATH\">\n")
    for path in paths:
        buffer.append("<path>%s</path>\n" % path)
    if paths: buffer.append("</pydev_pathproperty>\n")
    for key in property_keys:
        value = properties[key]
        buffer.append("<pydev_property name=\"%s\">%s</pydev_property>\n" % (key, value))
    buffer.append("</pydev_project>\n")

    result = "".join(buffer)
    result = result.encode("utf-8")

    file = open(file_path, "wb")
    try: file.write(result)
    finally: file.close()