Ejemplo n.º 1
0
    if args["time"]:
        global LATENCY
        LATENCY = args["time"][0]

    if args["verbose"]:
        global verbose
        verbose = True


if __name__ == '__main__':
    mail_service = Mailing()
    parse_args(mail_service)

    db = SqliteDB()
    is_db_filled = bool(db.get_used_versions())
    db.close_db()

    if not is_db_filled:
        exit("Please, fill the database before running novigrad")

    s = scheduler(time, sleep)
    if verbose:
        print('\nVerbose mode launched,'
              '\nReport will be generated on '
              'etc/reports.txt in ' + str(LATENCY) + ' seconds\n')
        s.enter(LATENCY, 1, check_dependencies_and_print)
    else:
        s.enter(LATENCY, 1, check_dependencies_and_report, mail_service)

    s.run()
Ejemplo n.º 2
0
    def generate_pdf(self, values: dict):
        """Generate PDF

        Check Dependencies
        Then order them 
        Finally create pdf report
        """
        db = SqliteDB()
        db_content = db.get_used_versions()
        db.close_db()

        _text = []

        _title = " - Dependencies Report - "
        _text.append(Paragraph(_title, self._styles_title))
        _text.append(Paragraph(self._formatted_time, self._styles_title))

        if bool(values):
            _text.append(
                Paragraph("UP TO DATE : ", self._styles_alert_uptodate))

            for _name in values:
                if (values[_name][0] == db_content[_name][0]
                    or values[_name][0] == 'Missing') \
                        and values[_name][1] == db_content[_name][1]:
                    _newest = _name + \
                              " : " + \
                              values[_name][0] + \
                              " - " + \
                              values[_name][1]

                    _text.append(Paragraph(_newest, self._styles_default))
                    _text.append(Paragraph("", self._styles_space))

            _text.append(
                Paragraph("NEW COMMIT AVAILABLE : ",
                          self._styles_alert_commit))

            for _name in values:
                if values[_name][1] != db_content[_name][1]:
                    _newest = _name + \
                              " : " + \
                              'https://github.com/' + \
                              db_content[_name][2] + \
                              '/' + _name + \
                              " " + \
                              values[_name][0] + \
                              " - " + \
                              values[_name][1]

                    _text.append(Paragraph(_newest, self._styles_default))
                    _text.append(Paragraph("", self._styles_space))

            _text.append(
                Paragraph("NEW RELEASE AVAILABLE : ",
                          self._styles_alert_release))

            for _name in values:
                if values[_name][0] != db_content[_name][0] \
                        and values[_name][0] != 'Missing':
                    _newest = _name + \
                              " : " + \
                              'https://github.com/' + \
                              db_content[_name][2] + \
                              '/' + _name + \
                              " - " + values[_name][0] + \
                              " - " + values[_name][1]

                    _text.append(Paragraph(_newest, self._styles_default))
                    _text.append(Paragraph("", self._styles_space))

        else:
            exit("Novigrad encountered an error checking, " +
                 "whether the database is non-empty.")

        self._doc_param.build(_text)
Ejemplo n.º 3
0
class GitChecker:
    """Reference Git_Checker

    Get and check github repositories
    If the API is unavailable, wait 35mn for the refresh

    Attributes:
        _base_url : base url for the github api
        _db       : database connection
    """
    def __init__(self):
        self._base_url = "https://api.github.com/repos/"
        self._db = SqliteDB()

    @staticmethod
    def __exec_request(req):
        """Returns the result of the request

        Verify that the API is reachable
        Otherwise wait for the refresh
        Then return the result
        """
        r = requests.get("https://api.github.com/rate_limit")

        if int(json.loads(r.text or r.content)["rate"]["remaining"]) == 0:
            sleep(HOLD)

        return requests.get(req)

    def __r_get_last_commit(self, name):
        """Returns the last commit

        Get the name of the repo and its owner
        Then build the request
        Then get the commit as a 7 digits string

        Returns:
            String containing the commit
            "Missing" on failure
        """
        owner = self._db.get_repo_owner(name)

        r = self.__exec_request(self._base_url + owner + "/" + name +
                                "/commits")

        if r.ok:
            for item in json.loads(r.text or r.content):
                return item["sha"][:7]

        return "Missing"

    def __r_get_last_release(self, name):
        """Returns the name of the last release

        Get the name of the repo and its owner
        Then build the request
        Then gather its name

        Returns:
            A String containing the version
            "Missing" on failure
        """
        owner = self._db.get_repo_owner(name)

        r = self.__exec_request(self._base_url + owner + "/" + name +
                                "/releases/latest")

        if r.ok:
            return json.loads(r.text or r.content)["tag_name"]

        return "Missing"

    def close_db(self):
        """Close the checker's database
        """
        self._db.close_db()

    def get_all_releases(self) -> dict:
        """Gather the latest releases for all repos

        Check each repository and its latest release

        Returns:
            A dict as :
                {
                    repo: [
                            latest_release,
                            latest_commit
                          ],
                    ...
                }
        """
        release = {}
        repo = []
        used_versions = self._db.get_used_versions()

        for elem in used_versions:
            repo.append(elem)

        for repository in repo:
            newest_info = [
                self.__r_get_last_release(repository),
                self.__r_get_last_commit(repository)
            ]

            release[repository] = newest_info

        return release
Ejemplo n.º 4
0
 def test_databaseCanConnectToTheDefaultDataBase_assertTrue(self):
     try:
         db = SqliteDB()
         db.close_db()
     except Exception:
         self.assertEqual(True, False)