예제 #1
0
 def fixture(self):
     u1 = User('u1')
     u1.email = 'test@test'
     u2 = User('u2')
     u2.email = 'test@test'
     r1 = Repo('r1', u1)
     r2 = Repo('r2', u2)
     p1 = Package('p1')
     p2 = Package('p2')
     req1 = Requirement(r1, p1)
     req2 = Requirement(r2, p1)
     req3 = Requirement(r2, p2)
     db.session.add(u1)
     db.session.add(u2)
     db.session.add(req1)
     db.session.add(req2)
     db.session.add(req3)
     db.session.commit()
     return locals()
예제 #2
0
    def add_new_requirement(self, name, specs):
        from pypi_notifier.models.requirement import Requirement
        package = db.session.query(Package).filter(
            Package.name == name).first()
        if not package:
            package = Package(name=name)
            db.session.add(package)
            db.session.flush([package])

        requirement = db.session.query(Requirement).filter(
            Requirement.repo_id == self.id,
            Requirement.package_id == package.id).first()
        if not requirement:
            requirement = Requirement(repo=self, package=package)

        requirement.specs = specs
        self.requirements.append = requirement
예제 #3
0
파일: repo.py 프로젝트: Gnof/pypi-notifier
    def update_requirements(self):
        """
        Fetches the content of the requirements.txt files from GitHub,
        parses the file and adds each requirement to the repo.

        """
        for project_name, specs in self.parse_requirements_file():
            # specs may be empty list if no version is specified in file
            # No need to add to table since we can't check updates.
            if specs:
                # There must be '==' operator in specs.
                operators = [s[0] for s in specs]
                if '==' in operators:
                    # If the project is not registered on PyPI,
                    # we are not adding it.
                    if project_name.lower() in Package.get_all_names():
                        self.add_new_requirement(project_name, specs)

        self.last_check = datetime.utcnow()
예제 #4
0
    def update_requirements(self):
        """
        Fetches the content of the requirements.txt files from GitHub,
        parses the file and adds each requirement to the repo.

        """
        for project_name, specs in self.parse_requirements_file():
            # specs may be empty list if no version is specified in file
            # No need to add to table since we can't check updates.
            if specs:
                # There must be '==' operator in specs.
                operators = [s[0] for s in specs]
                if '==' in operators:
                    # If the project is not registered on PyPI,
                    # we are not adding it.
                    if project_name.lower() in Package.get_all_names():
                        self.add_new_requirement(project_name, specs)

        self.last_check = datetime.utcnow()
예제 #5
0
    def _update_requirements(self, force=False):
        try:
            content = self.fetch_requirements(force=force)
        except RequirementsNotModified:
            logger.info("requirements.txt file not modified")
            return
        except RequirementsNotFound:
            logger.info("requirements.txt file not found")
            self.requirements.clear()
            return
        except InvalidToken:
            logger.info("invalid token, deleting user: %s", self.user.name)
            db.session.delete(self.user)
            return

        try:
            requirements = Repo.parse_requirements_file(content)
        except RequirementParseError as e:
            logger.warning("parsing error for %s: %s", self.name, e)
            self.requirements.clear()
            return

        tracked_packages = set()
        for package_name, specs in requirements:
            # specs may be empty list if no version is specified in file
            # No need to add to table since we can't check updates.
            if specs:
                # There must be '==' operator in specs.
                operators = [s[0] for s in specs]
                if '==' in operators:
                    package_name = package_name.lower()
                    # If the project is not registered on PyPI,
                    # we are not adding it.
                    if package_name in Package.get_all_names():
                        tracked_packages.add(package_name)
                        self.add_new_requirement(package_name, specs)

        # Delete removed requirements
        for req in list(self.requirements):
            if req.package.name not in tracked_packages:
                self.requirements.remove(req)
예제 #6
0
파일: repo.py 프로젝트: cenk/pypi-notifier
    def _update_requirements(self, force=False):
        try:
            content = self.fetch_requirements(force=force)
        except RequirementsNotModified:
            logger.info("requirements.txt file not modified")
            return
        except RequirementsNotFound:
            logger.info("requirements.txt file not found")
            self.requirements.clear()
            return
        except InvalidToken:
            logger.info("invalid token, deleting user: %s", self.user.name)
            db.session.delete(self.user)
            return

        try:
            requirements = Repo.parse_requirements_file(content)
        except RequirementParseError as e:
            logger.warning("parsing error for %s: %s", self.name, e)
            self.requirements.clear()
            return

        tracked_packages = set()
        for package_name, specs in requirements:
            # specs may be empty list if no version is specified in file
            # No need to add to table since we can't check updates.
            if specs:
                # There must be '==' operator in specs.
                operators = [s[0] for s in specs]
                if '==' in operators:
                    package_name = package_name.lower()
                    # If the project is not registered on PyPI,
                    # we are not adding it.
                    if package_name in Package.get_all_names():
                        tracked_packages.add(package_name)
                        self.add_new_requirement(package_name, specs)

        # Delete removed requirements
        for req in list(self.requirements):
            if req.package.name not in tracked_packages:
                self.requirements.remove(req)
예제 #7
0
파일: repo.py 프로젝트: Gnof/pypi-notifier
 def add_new_requirement(self, name, specs):
     from pypi_notifier.models.requirement import Requirement
     package = Package.get_or_create(name=name)
     requirement = Requirement.get_or_create(repo=self, package=package)
     requirement.specs = specs
     self.requirements.append = requirement
예제 #8
0
 def add_new_requirement(self, name, specs):
     from pypi_notifier.models.requirement import Requirement
     package = Package.get_or_create(name=name)
     requirement = Requirement.get_or_create(repo=self, package=package)
     requirement.specs = specs
     self.requirements.append = requirement