Exemplo n.º 1
0
        solver._make_assertion_rules_decisions(decisions, rules)
        return decisions

    def to_php(self, filename="test_installed_map.php", composer_location=None):
        if composer_location is None:
            bootstrap_path = "__DIR__.'/src/bootstrap.php'"
        else:
            bootstrap_path = "'%s'" % op.join(composer_location, "src", "bootstrap.php")

        template = tempita.Template(TEMPLATE)

        remote_packages = self.remote_repository.list_packages()
        installed_packages = self.installed_repository.list_packages()

        variables = {
                "bootstrap_path": bootstrap_path,
                "remote_repo_json_string": packages_list_to_php_json(remote_packages),
                "installed_repo_json_string": packages_list_to_php_json(installed_packages),
                "request": [(job.job_type, job.requirement.name, job_to_php_constraints(job)) \
                            for job in self.request.jobs],
                "common_imports": COMMON_IMPORTS,
        }
        with open(filename, "wt") as fp:
            fp.write(template.substitute(variables))

if __name__ == "__main__":
    data_directory = op.join(op.dirname(__file__), "data", "rules_generator")
    test_directory = op.join(op.dirname(__file__), "data", "make_assertion_rules")

    run_php_scenarios(data_directory, MakeAssertionRulesScenario, lambda x: x, test_directory)
Exemplo n.º 2
0
                "request": [(job.job_type, job.requirement.name, job_to_php_constraints(job)) \
                            for job in self.request.jobs],
                "common_imports": COMMON_IMPORTS,
        }
        with open(filename, "wt") as fp:
            fp.write(template.substitute(variables))

def post_process(output):
    """Crappy function to convert php rule string to depsolver ones."""
    lines = []
    for line in output.splitlines():
        new_parts = []
        parts = [p.strip() for p in line[1:-1].split("|")]
        for part in parts:
            if part.startswith("-"):
                part = part[1:-2]
                name, version = parse_package_full_name(part)
                new_part = "-" + "%s-%s" % (name, str(version))
            else:
                part = part[:-2]
                name, version = parse_package_full_name(part)
                new_part = "%s-%s" % (name, str(version))
            new_parts.append(new_part)
        lines.append("(" + " | ".join(new_parts) + ")")
    lines.append("")
    return "\n".join(lines)

if __name__ == "__main__":
    data_directory = op.join(op.dirname(__file__), "data", "rules_generator")
    run_php_scenarios(data_directory, RulesGeneratorScenario, post_process)
Exemplo n.º 3
0
                "installed_repo_json_string": packages_list_to_php_json(installed_packages),
                "request": [(job.job_type, job.requirement.name, job_to_php_constraints(job)) \
                            for job in self.request.jobs],
                "common_imports": COMMON_IMPORTS,
        }
        with open(filename, "wt") as fp:
            fp.write(template.substitute(variables))


class SolverOperationsScenario(SolverDecisionsScenario):
    template_string = Unicode(OPERATIONS_TEMPLATE)

    def compute_operations(self):
        """
        Compute the operations for this scenario.
        """
        return self.solver.solve(self.request)


if __name__ == "__main__":
    data_directory = op.join(op.dirname(__file__), "data", "rules_generator")
    decisions_test_directory = op.join(op.dirname(__file__), "data",
                                       "solver_decisions")
    operations_test_directory = op.join(op.dirname(__file__), "data",
                                        "solver_operations")

    run_php_scenarios(data_directory, SolverDecisionsScenario, lambda x: x,
                      decisions_test_directory)
    run_php_scenarios(data_directory, SolverOperationsScenario, lambda x: x,
                      operations_test_directory)
Exemplo n.º 4
0
        remote_packages = self.remote_repository.list_packages()
        installed_packages = self.installed_repository.list_packages()

        variables = {
                "bootstrap_path": bootstrap_path,
                "remote_repo_json_string": packages_list_to_php_json(remote_packages),
                "installed_repo_json_string": packages_list_to_php_json(installed_packages),
                "request": [(job.job_type, job.requirement.name, job_to_php_constraints(job)) \
                            for job in self.request.jobs],
                "common_imports": COMMON_IMPORTS,
        }
        with open(filename, "wt") as fp:
            fp.write(template.substitute(variables))

class SolverOperationsScenario(SolverDecisionsScenario):
    template_string = Unicode(OPERATIONS_TEMPLATE)

    def compute_operations(self):
        """
        Compute the operations for this scenario.
        """
        return self.solver.solve(self.request)

if __name__ == "__main__":
    data_directory = op.join(op.dirname(__file__), "data", "rules_generator")
    decisions_test_directory = op.join(op.dirname(__file__), "data", "solver_decisions")
    operations_test_directory = op.join(op.dirname(__file__), "data", "solver_operations")

    run_php_scenarios(data_directory, SolverDecisionsScenario, lambda x: x, decisions_test_directory)
    run_php_scenarios(data_directory, SolverOperationsScenario, lambda x: x, operations_test_directory)
Exemplo n.º 5
0
                "common_imports": COMMON_IMPORTS,
        }
        with open(filename, "wt") as fp:
            fp.write(template.substitute(variables))


def post_process(output):
    """Crappy function to convert php rule string to depsolver ones."""
    lines = []
    for line in output.splitlines():
        new_parts = []
        parts = [p.strip() for p in line[1:-1].split("|")]
        for part in parts:
            if part.startswith("-"):
                part = part[1:-2]
                name, version = parse_package_full_name(part)
                new_part = "-" + "%s-%s" % (name, str(version))
            else:
                part = part[:-2]
                name, version = parse_package_full_name(part)
                new_part = "%s-%s" % (name, str(version))
            new_parts.append(new_part)
        lines.append("(" + " | ".join(new_parts) + ")")
    lines.append("")
    return "\n".join(lines)


if __name__ == "__main__":
    data_directory = op.join(op.dirname(__file__), "data", "rules_generator")
    run_php_scenarios(data_directory, RulesGeneratorScenario, post_process)