Exemplo n.º 1
0
    def test_databaseExitIfDependencyNameIsEmpty_assertFalse(self):
        huge_str = ''
        for i in range(150):
            huge_str += '#'

        db = Sqlite_db()
        with self.assertRaises(SystemExit):
            db.add_dep(huge_str, "v0.0.2", "e45d87", "owner")
Exemplo n.º 2
0
    def test_databaseExitIfownerNameIsEmpty_assertFalse(self):
        huge_str = ''
        for i in range(150):
            huge_str += '#'

        db = Sqlite_db()
        with self.assertRaises(SystemExit):
            db.add_dep("Some_repo", "v0.0.2", "e45d87", huge_str)
Exemplo n.º 3
0
    def generatePDF(self,dictionary):
        """Generate PDF

        Check Depedencies
        Then order them 
        Finaly create pdf report

        Attributes:
            _text  : list to build pdf
            _title : stock title of document
            _newest: strock verified element
            _name  : increment value
        """     
        db = Sqlite_db()
        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(dictionary) == True:

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

            for _name in dictionary:
                if (dictionary[_name][0] == db_content[_name][0] \
                or dictionary[_name][0] == 'Missing') \
                and dictionary[_name][1] == db_content[_name][1]:
                    _newest = (_name + " : " + dictionary[_name][0] + " - " 
                    + dictionary[_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 dictionary:
                if dictionary[_name][1] != db_content[_name][1] :
                    _newest = (_name + " : " +
                    'https://github.com/' + db_content[_name][2] + '/' + 
                    _name + " " + dictionary[_name][0] + 
                    " - " + dictionary[_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 dictionary:
                if dictionary[_name][0] != db_content[_name][0] \
                and dictionary[_name][0] != 'Missing' :
                    _newest = (_name + " : " +
                    'https://github.com/' + db_content[_name][2] + '/' + 
                    _name + " - " + dictionary[_name][0] + 
                    " - " + dictionary[_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)
Exemplo n.º 4
0
        mail_service.add_mailadress(args["mail"][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 = Sqlite_db()
    verif = bool(db.get_used_versions())
    db.close_db()

    if not verif:
        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()
Exemplo n.º 5
0
 def __init__(self):
     self._base_url = "https://api.github.com/repos/"
     self._db = Sqlite_db()
Exemplo n.º 6
0
class Git_Checker:
    """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 = Sqlite_db()

    def __exec_request(self, 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(TEMPORISATION)

        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
        """
        last_release_json = {}
        owner = self._db.get_repo_owner(name)

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

        if r.ok:
            commitInfos = json.loads(r.text or r.content)
            for item in commitInfos:
                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
        """
        last_release_json = {}
        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):
        """Gather the latest releases for all repos

        Check each repository and its latest release

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

        for elem in used_versions:
            repo_list.append(elem)

        for repository in repo_list:
            newest_infos = []
            newest_infos.append(self.__r_get_last_release(repository))
            newest_infos.append(self.__r_get_last_commit(repository))

            realease_dict[repository] = newest_infos

        return realease_dict
Exemplo n.º 7
0
 def test_databaseExitIfownerNameIsEmpty_assertFalse(self):
     db = Sqlite_db()
     with self.assertRaises(SystemExit):
         db.add_dep("Some_repo", "v0.0.2", "e45d87", "")
Exemplo n.º 8
0
 def test_databaseExitIfDependencyNameIsEmpty_assertFalse(self):
     db = Sqlite_db()
     with self.assertRaises(SystemExit):
         db.add_dep("", "v0.0.2", "e45d87", "owner")
Exemplo n.º 9
0
 def test_databaseExitIfNoRepositoryExists_assertFalse(self):
     db = Sqlite_db()
     with self.assertRaises(SystemExit):
         db.get_repo_owner("some_imaginary_repository")
Exemplo n.º 10
0
 def test_databaseCanConnectToTheDefaultDataBase_assertTrue(self):
     try:
         db = Sqlite_db()
     except Error:
         self.assertEqual(True, False)
         db.close_db()
Exemplo n.º 11
0
 def test_databaseCantOpenWrongDataBase_assertFalse(self):
     with self.assertRaises(SystemExit):
         Sqlite_db("test/sql/unknown_db.db")