Пример #1
0
    def __init__(self, repo, uri):
        LineCounter.__init__(self, repo, uri)

        self.commit_pattern = re.compile("^(\w+) ")
        self.file_pattern = re.compile("^(\d+)\s+(\d+)\s+([^\s].*)$")

        # Dictionary for storing added, removed pairs, keyed by commit.
        self.lines = {}
        # Dictionary for storing list of paths, keyed by commit.
        self.paths = {}
        # Dictionary for storing added, removed pairs, keyed by commit.
        # and path
        self.lines_files = {}

        # Run git command
        self.git = find_program('git')
        if self.git is None:
            raise ExtensionRunError ("Error running CommitsLOCDet extension: " + \
                                     "required git command cannot be found in path")
        cmd = [
            self.git, 'log', '--all', '--topo-order', '--numstat',
            '--pretty=oneline'
        ]
        c = Command(cmd, uri)
        try:
            c.run(parser_out_func=self.__parse_line)
        except CommandError, e:
            if e.error:
                printerr("Error running git log command: %s", (e.error, ))
            raise ExtensionRunError(
                "Error running " + "CommitsLOCDet extension: %s", str(e))
Пример #2
0
    def run(self, repo, uri, db):
        profiler_start("Running HunkBlame extension")

        self.db = db

        cnn = self.db.connect()
        read_cursor = cnn.cursor()
        write_cursor = cnn.cursor()
        try:
            path = uri_to_filename(uri)
            if path is not None:
                repo_uri = repo.get_uri_for_path(path)
            else:
                repo_uri = uri

            read_cursor.execute(
                statement("SELECT id from repositories where uri = ?",
                          db.place_holder), (repo_uri, ))
            repoid = read_cursor.fetchone()[0]
        except NotImplementedError:
            raise ExtensionRunError(
                "HunkBlame extension is not supported for %s repositories" %
                (repo.get_type()))
        except Exception, e:
            raise ExtensionRunError(
                "Error creating repository %s. Exception: %s" %
                (repo.get_uri(), str(e)))
Пример #3
0
    def run(self, repo, uri, db):
        # Start the profiler, per every other extension
        profiler_start("Running FileCount extension")

        # Open a connection to the database and get cursors
        self.db = db
        connection = self.db.connect()
        read_cursor = connection.cursor()
        write_cursor = connection.cursor()

        # Try to get the repository and get its ID from the database
        try:
            path = uri_to_filename(uri)
            if path is not None:
                repo_uri = repo.get_uri_for_path(path)
            else:
                repo_uri = uri

            read_cursor.execute(statement( \
                    "SELECT id from repositories where uri = ?", \
                    db.place_holder), (repo_uri,))
            repo_id = read_cursor.fetchone()[0]
        except NotImplementedError:
            raise ExtensionRunError( \
                    "FileCount extension is not supported for %s repos" % \
                    (repo.get_type()))
        except Exception, e:
            raise ExtensionRunError( \
                    "Error creating repository %s. Exception: %s" % \
                    (repo.get_uri(), str(e)))
Пример #4
0
    def run(self, repo, uri, db):
        profiler_start("Running PatchLOC extension")

        # Open a connection to the database and get cursors
        self.db = db
        connection = self.db.connect()
        cursor = connection.cursor()

        path = uri_to_filename(uri)
        if path is not None:
            repo_uri = repo.get_uri_for_path(path)
        else:
            repo_uri = uri

        cursor.execute(
            statement("SELECT id from repositories where uri = ?",
                      db.place_holder), (repo_uri, ))
        repo_id = cursor.fetchone()[0]

        try:
            self.__create_table(connection)
        except TableAlreadyExists:
            pass
        except Exception, e:
            raise ExtensionRunError(str(e))
Пример #5
0
    def run(self, repo, uri, db):
        self.db = db

        path = uri_to_filename(uri)
        if path is not None:
            repo_uri = repo.get_uri_for_path(path)
        else:
            repo_uri = uri

        cnn = self.db.connect()

        cursor = cnn.cursor()
        cursor.execute(
            statement("SELECT id from repositories where uri = ?",
                      db.place_holder), (repo_uri, ))
        repo_id = cursor.fetchone()[0]

        # If table does not exist, the list of commits is empty,
        # otherwise it will be filled within the except block below
        commits = []

        try:
            self.__create_table(cnn)
        except TableAlreadyExists:
            cursor.execute(
                statement("SELECT max(id) from commits_lines",
                          db.place_holder))
            id = cursor.fetchone()[0]
            if id is not None:
                DBCommitLines.id_counter = id + 1

            commits = self.__get_commits_lines_for_repository(repo_id, cursor)
        except Exception, e:
            raise ExtensionRunError(str(e))
Пример #6
0
    def run(self, repo, uri, db):
        self.db = db

        path = uri_to_filename(uri)
        if path is not None:
            repo_uri = repo.get_uri_for_path(path)
        else:
            repo_uri = uri

        cnn = self.db.connect()

        cursor = cnn.cursor()
        cursor.execute(
            statement("SELECT id from repositories where uri = ?",
                      db.place_holder), (repo_uri, ))
        repo_id = cursor.fetchone()[0]

        files = []

        try:
            self.__create_table(cnn)
        except TableAlreadyExists:
            cursor.execute(
                statement("SELECT max(id) from file_types", db.place_holder))
            id = cursor.fetchone()[0]
            if id is not None:
                DBFileType.id_counter = id + 1

            files = self.__get_files_for_repository(repo_id, cursor)
        except Exception, e:
            raise ExtensionRunError(str(e))
Пример #7
0
def create_line_counter_for_repository(repo, uri):
    try:
        counter = _counters[repo.get_type()]
    except KeyError:
        raise ExtensionRunError("Repository type %s is not supported by CommitsLOC extension" % (repo.get_type()))

    return counter(repo, uri)
Пример #8
0
 def __init__(self, repo, uri):
     LineCounter.__init__(self, repo, uri)
     self.diffstat = find_program('diffstat')
     if self.diffstat is None:
         raise ExtensionRunError(
             "Error running CommitsLOC extension: " +
             "required diffstat command cannot be found in path")
Пример #9
0
    def __init__(self, repo, uri):
        LineCounter.__init__(self, repo, uri)

        self.git = find_program('git')
        if self.git is None:
            raise ExtensionRunError("Error running CommitsLOC extension: " +
                                    "required git command cannot be found in path")

        self.lines = {}

        cmd = [self.git, 'log', '--all', '--topo-order', '--shortstat', '--pretty=oneline', 'origin']
        c = Command(cmd, uri)
        try:
            c.run(parser_out_func=self.__parse_line)
        except CommandError, e:
            if e.error:
                printerr("Error running git log command: %s", (e.error,))
            raise ExtensionRunError("Error running CommitsLOC extension: %s", str(e))
Пример #10
0
    def _create_table(self, cursor):
        """Create the table, and raise exception if it already exists.

        TableAlreadyExists is the exception that may be raised."""

        if isinstance(self.db, SqliteDatabase):
            self._create_table_sqlite(cursor)
        elif isinstance(self.db, MysqlDatabase):
            self._create_table_mysql(cursor)
        else:
            raise ExtensionRunError("Database type is not supported " +
                                    "by CommitsLOCDet extension")
Пример #11
0
def create_line_counter_for_repository(repo, uri):
    """Creates and returns a counter for the kind of repository specified.

    Raises exception if repository is not supported.
    """

    try:
        counter = _counters[repo.get_type()]
    except KeyError:
        error = "Repository type %s is not supported " + \
            "by CommitsLOCDet extension"
        raise ExtensionRunError(error % (repo.get_type()))
    return counter(repo, uri)
Пример #12
0
    def run(self, repo, uri, db):
        # Start the profiler, per every other extension
        profiler_start("Running BugFixMessage extension")

        # Open a connection to the database and get cursors
        self.db = db
        connection = self.db.connect()
        read_cursor = connection.cursor()
        write_cursor = connection.cursor()

        # Try to get the repository and get its ID from the database
        try:
            repo_uri = get_repo_uri(uri, repo)
            repo_id = get_repo_id(repo_uri, read_cursor, db)

        except NotImplementedError:
            raise ExtensionRunError( \
                    "BugFixMessage extension is not supported for %s repos" % \
                    (repo.get_type()))
        except Exception, e:
            raise ExtensionRunError( \
                    "Error creating repository %s. Exception: %s" % \
                    (repo.get_uri(), str(e)))
Пример #13
0
    def __init__(self, db, cnn, repo):
        """Initialize the table.

        Initialization can be either by creating it or by getting rows
        from and already existing table.
        If the table already exists, rows are got from it, so that new rows
        are compared with them before inserting (we don't want to
        re-insert already inserted rows).
        If the table does not exists, create it.

        db: database holding the table.
        cnn: connection to that database
        repo: git repository
        """

        # Counter for unique row ids
        self.counter = 1
        # Rows already in table
        self.table = []
        # Rows still not inserted in the table table
        self.pending = []

        # Initialize variables related to the database
        self.db = db
        self.cnn = cnn
        self.repo = repo

        cursor = cnn.cursor()
        try:
            # Try to create the table (self.table will be empty)
            self._create_table(cursor)
        except TableAlreadyExists:
            # If the table already exisits, fill in self.table with its data
            self._init_from_table(cursor)
        except Exception, e:
            raise ExtensionRunError(str(e))
Пример #14
0
            repoid = read_cursor.fetchone()[0]
        except NotImplementedError:
            raise ExtensionRunError(
                "HunkBlame extension is not supported for %s repositories" %
                (repo.get_type()))
        except Exception, e:
            raise ExtensionRunError(
                "Error creating repository %s. Exception: %s" %
                (repo.get_uri(), str(e)))

        try:
            self.__create_table(cnn)
        except TableAlreadyExists:
            pass
        except Exception, e:
            raise ExtensionRunError(str(e))

        try:
            self.__create_cache(cnn)
        except TableAlreadyExists:
            pass
        except Exception, e:
            raise ExtensionRunError(str(e))

        blames = self.__get_hunk_blames(read_cursor, repoid)

        job_pool = JobPool(repo, path or repo.get_uri(), queuesize=100)

        outer_query = """select distinct h.file_id, h.commit_id
            from hunks h, scmlog s
            where h.commit_id=s.id and s.repository_id=?
Пример #15
0
        except NotImplementedError:
            raise ExtensionRunError( \
                    "Content extension is not supported for %s repos" % \
                    (repo.get_type()))
        except Exception, e:
            raise ExtensionRunError( \
                    "Error creating repository %s. Exception: %s" % \
                    (repo.get_uri(), str(e)))

        # Try to create a table for storing the content
        # TODO: Removed use case for choosing between all or just the HEAD,
        # should ideally put that back again. Just all for now is fine.
        try:
            self.__prepare_table(connection)
        except Exception as e:
            raise ExtensionRunError("Couldn't prepare table because " + \
                                    str(e))

        queuesize = Config().max_threads
        printdbg("Setting queuesize to " + str(queuesize))

        # This is where the threading stuff comes in, I expect
        job_pool = JobPool(repo, path or repo.get_uri(), queuesize=queuesize)

        # This filters files if they're not source files.
        # I'm pretty sure "unknown" is returning binary files too, but
        # these are implicitly left out when trying to convert to utf-8
        # after download. However, ignore them for now to speed things up
        query = "select f.id from file_types ft, files f " + \
                "where f.id = ft.file_id and " + \
                "ft.type in('code') and " + \
                "f.repository_id = ?"