Example #1
0
    def connectDb(self):

        self.db_config = self.cfg.ConfigSectionMap("Database")
        logging.debug("Database configuration = %r\n", self.db_config)
        self.dbCon = DatabaseCon(self.db_config['database'], self.db_config['user'], \
                                 self.db_config['host'], self.db_config['port'], \
                                 self.db_config['password'])
Example #2
0
class DbProj:

	def __init__(self, proj=None, lang=None):
		self.project = proj
		self.language = lang
		self.projects = []

	def __str__(self):

		print_str = ""

		for p in self.projects:
			print_str += str(p)

		return print_str

	def connectDb(self, db, dbUser, dbHost, dbPort):

		self.dbCon = DatabaseCon(db, dbUser, dbHost, dbPort)

	def fetchDatesFromTable(self, table):

		sql_command = "SELECT tag, project, min(commit_date), max(commit_date)"
		sql_command +=  " FROM " + table + " Where tag like \'" + self.language + "\'"
		sql_command +=  " and project = \'" + self.project + "\' group by tag, project"

		print sql_command

		rows = self.dbCon.execute(sql_command)

		for row in rows:
			language, project, commit_date_min, commit_date_max = row
			p = proj(language, project, commit_date_min, commit_date_max)
			self.projects.append(p)

	def countCommitBetweenDates(self, table, snapshot1, snapshot2):

            snapshot1 = "'" + snapshot1 + "'"
            snapshot2 = "'" + snapshot2 + "'"

            sql_command = "SELECT distinct file_name, sha"
            sql_command +=  " FROM " + table + " Where tag like \'" + self.language + "\'"
            sql_command +=  " and project = \'" + self.project + "\' and commit_date >= " \
                               + snapshot1 + " and commit_date < " + snapshot2

            #print sql_command
            rows = self.dbCon.execute(sql_command)
            return len(rows)


	def printCommitDates(self):

		for p in self.projects:
			print p
Example #3
0
class DbProj:
    def __init__(self, proj=None, lang=None):
        self.project = proj
        self.language = lang
        self.projects = []

    def __str__(self):

        print_str = ""

        for p in self.projects:
            print_str += str(p)

        return print_str

    def connectDb(self, db, dbUser, dbHost, dbPort):

        self.dbCon = DatabaseCon(db, dbUser, dbHost, dbPort)

    def fetchDatesFromTable(self, table):

        sql_command = "SELECT tag, project, min(commit_date), max(commit_date)"
        sql_command += " FROM " + table + " Where tag like \'" + self.language + "\'"
        sql_command += " and project = \'" + self.project + "\' group by tag, project"

        print sql_command

        rows = self.dbCon.execute(sql_command)

        for row in rows:
            language, project, commit_date_min, commit_date_max = row
            p = proj(language, project, commit_date_min, commit_date_max)
            self.projects.append(p)

    def countCommitBetweenDates(self, table, snapshot1, snapshot2):

        snapshot1 = "'" + snapshot1 + "'"
        snapshot2 = "'" + snapshot2 + "'"

        sql_command = "SELECT distinct file_name, sha"
        sql_command += " FROM " + table + " Where tag like \'" + self.language + "\'"
        sql_command +=  " and project = \'" + self.project + "\' and commit_date >= " \
                           + snapshot1 + " and commit_date < " + snapshot2

        #print sql_command
        rows = self.dbCon.execute(sql_command)
        return len(rows)

    def printCommitDates(self):

        for p in self.projects:
            print p
Example #4
0
    def connectDb(self):

        self.db_config = self.cfg.ConfigSectionMap("Database")
        logging.debug("Database configuration = %r\n", self.db_config)
        self.dbCon = DatabaseCon(self.db_config['database'], self.db_config['user'], \
                                 self.db_config['host'], self.db_config['port'], \
                                 self.db_config['password'])
Example #5
0
class DbEdits:

	def __init__(self, proj, lang):
		self.project = proj
		self.language = lang
		self.edits = []

	def __str__(self):

		print_str = ""
		for e in self.edits:
			print_str += str(e)

		return print_str

	def connectDb(self, db, dbUser, dbHost, dbPort):

		self.dbCon = DatabaseCon(db, dbUser, dbHost, dbPort)

	def fetchEditsFromTable(self, table):

		sql_command = "SELECT project, file_name, sha, commit_date, isbug, is_test "
		sql_command +=  " FROM " + table + " WHERE tag = \'" + self.language + \
						"\' and project = \'" + self.project + "\'"

		print sql_command
		
		rows = self.dbCon.execute(sql_command)

		for row in rows:
			project, file_name, sha, commit_date, isbug, is_test = row
			e = edit(project, file_name, is_test, sha, commit_date, isbug)
			self.edits.append(e)


	def printEdits(self):

		for e in self.edits:
			print e
Example #6
0
class DbAll_changes:
    def __init__(self, proj=None, lang=None):
        self.project = proj
        self.language = lang
        self.projects = []

    def __str__(self):

        print_str = ""

        for p in self.projects:
            print_str += str(p)

        return print_str

    def connectDb(self, db, dbUser, dbHost, dbPort):

        self.dbCon = DatabaseCon(db, dbUser, dbHost, dbPort)

    def fetchDatesFromTable(self, table):

        sql_command = "SELECT language, project, min(commit_date), max(commit_date)"
        sql_command += " FROM " + table + " Where language iLike \'" + self.language + "\'"
        sql_command += " and project = \'" + self.project + "\' group by language, project"

        print sql_command

        rows = self.dbCon.execute(sql_command)

        for row in rows:
            language, project, commit_date_min, commit_date_max = row
            p = proj(language, project, commit_date_min, commit_date_max)
            self.projects.append(p)

    def printCommitDates(self):

        for p in self.projects:
            print p
Example #7
0
class DbEdits:
    def __init__(self, proj, lang):
        self.project = proj
        self.language = lang
        self.edits = []

    def __str__(self):

        print_str = ""
        for e in self.edits:
            print_str += str(e)

        return print_str

    def connectDb(self, db, dbUser, dbHost, dbPort):

        self.dbCon = DatabaseCon(db, dbUser, dbHost, dbPort)

    def fetchEditsFromTable(self, table):

        sql_command = "SELECT project, file_name, sha, commit_date, isbug, is_test "
        sql_command +=  " FROM " + table + " WHERE tag = \'" + self.language + \
            "\' and project = \'" + self.project + "\'"

        print sql_command

        rows = self.dbCon.execute(sql_command)

        for row in rows:
            project, file_name, sha, commit_date, isbug, is_test = row
            e = edit(project, file_name, is_test, sha, commit_date, isbug)
            self.edits.append(e)

    def printEdits(self):

        for e in self.edits:
            print e
Example #8
0
class dumpLogs:
    def __init__(self, password, c_info):
        self.config_info = c_info
        self.cfg = Config(self.config_info.CONFIG)
        self.dbPass = password
        self.connectDb()
        #self.cleanDb()

    @staticmethod
    def getFullTitleString(keywordDictionary):
        '''
        Create a string specifying not only the database column names
        but also their types.  This is used when automatically creating
        the database table.
        '''

        dictStr = "(project character varying(500), sha text, language character varying(500)," + \
            " file_name text, is_test boolean, method_name text"
        for key, value in keywordDictionary.items():
            dictStr= dictStr+", \""+ str(key).replace(" ", "_").replace("(", "_").replace(")", "_") + \
                "\" integer" #ToStr will add ' around the strings...

        dictStr += ", total_adds integer, total_dels integer, warning_alert boolean)"

        return dictStr

    def connectDb(self):
        self.db_config = self.cfg.ConfigSectionMap("Database")
        logging.debug("Database configuration = %r\n", self.db_config)
        self.dbCon = DatabaseCon(self.db_config['database'], self.db_config['user'], \
                                 self.db_config['host'], self.db_config['port'], \
                                 self.dbPass)

    def cleanDb(self):

        schema = self.db_config['schema']
        response = 'y'  # raw_input("Deleting database %s ?" % (self.db_config['schema']))

        schema = self.db_config['schema']
        tables = []
        tables.append(schema + "." + self.db_config['table_method_detail'])
        tables.append(schema + "." + self.db_config['table_change_summary'])

        if response.lower().startswith('y'):
            for table in tables:
                print(("Deleting table %r \n" % table))
                sql_command = "DELETE FROM " + table
                self.dbCon.insert(sql_command)

        self.dbCon.commit()

    def close(self):
        self.dbCon.commit()
        self.dbCon.close()

    #TODO: Improve security here for possible injections?
    def createSummaryTable(self):
        schema = self.db_config['schema']
        table = schema + "." + self.db_config['table_change_summary']
        user = self.db_config['user']

        sql_command = "CREATE TABLE IF NOT EXISTS " + table + " (project character varying(500) NOT NULL," + \
            " sha text NOT NULL, author character varying(500), author_email character varying(500)," + \
            " commit_date date, is_bug boolean,"+ \
            " CONSTRAINT change_summary_pkey PRIMARY KEY (project, sha)) WITH (OIDS=FALSE);"
        self.dbCon.create(sql_command)
        #self.dbCon.create("ALTER TABLE " + table + " OWNER TO " + user + ";")
        #self.dbCon.create("GRANT ALL ON TABLE " + table + " TO " + user + ";")

    def createMethodChangesTable(self, titleString):
        schema = self.db_config['schema']
        table = schema + "." + self.db_config['table_method_detail']
        user = self.db_config['user']

        sql_command = "CREATE TABLE IF NOT EXISTS " + table + titleString + " WITH (OIDS=FALSE);"
        self.dbCon.create(sql_command)
        #self.dbCon.create("ALTER TABLE " + table + " OWNER TO " + user + ";")
        #self.dbCon.create("GRANT ALL ON TABLE " + table + " TO " + user + ";")

    def dumpSummary(self, summaryStr):

        schema = self.db_config['schema']
        table = schema + "." + self.db_config['table_change_summary']

        sql_command = "INSERT INTO " + table + \
                      "(project, sha, author, author_email, commit_date, is_bug)" + \
                      " VALUES (" + summaryStr + ")"

        #print sql_command
        self.dbCon.insert(sql_command)
        #self.dbCon.commit()

    def dumpMethodChanges(self, methodChange, titleString):

        schema = self.db_config['schema']
        table = schema + "." + self.db_config['table_method_detail']

        #sql_command = "INSERT INTO " + table + \
        #            "(project, sha, language, file_name, is_test, method_name, assertion_add, " + \
        #            "assertion_del, total_add, total_del)" + \
        #            "VALUES (" + methodChange + ")"

        sql_command = "INSERT INTO " + table + titleString + " VALUES (" + methodChange + ")"

        if (self.config_info.DEBUG):
            print(sql_command)

        self.dbCon.insert(sql_command)
Example #9
0
    def connectDb(self, db, dbUser, dbHost, dbPort):

        self.dbCon = DatabaseCon(db, dbUser, dbHost, dbPort)
Example #10
0
	def connectDb(self, db, dbUser, dbHost, dbPort):

		self.dbCon = DatabaseCon(db, dbUser, dbHost, dbPort)
Example #11
0
class dumpLogs:

    def __init__(self, configFile=Util.CONFIG):

        self.cfg = Config(configFile)
        self.connectDb()
        #self.cleanDb()


    def connectDb(self):

        self.db_config = self.cfg.ConfigSectionMap("Database")
        logging.debug("Database configuration = %r\n", self.db_config)
        self.dbCon = DatabaseCon(self.db_config['database'], self.db_config['user'], \
                                 self.db_config['host'], self.db_config['port'], \
                                 self.db_config['password'])


    def cleanDb(self):

        schema = self.db_config['schema']
        response = 'y' # raw_input("Deleting database %s ?" % (self.db_config['schema']))

        schema = self.db_config['schema']
        tables = []
        tables.append(schema + "." + self.db_config['table_method_detail'])
        tables.append(schema + "." + self.db_config['table_change_summary'])

        if response.lower().startswith('y'):
            for table in tables:
                print("Deleting table %r \n" % table)
                sql_command = "DELETE FROM " + table
                self.dbCon.insert(sql_command)

        self.dbCon.commit()


    def close(self):
        self.dbCon.commit()
        self.dbCon.close()

    def dumpSummary(self, summaryStr):

        schema = self.db_config['schema']
        table = schema + "." + self.db_config['table_change_summary']

        sql_command = "INSERT INTO " + table + \
                      "(project, sha, author, commit_date, is_bug)" + \
                      " VALUES (" + summaryStr + ")"

        #print sql_command
        self.dbCon.insert(sql_command)
        self.dbCon.commit()

    def dumpMethodChanges(self, methodChange, titleString):

        schema = self.db_config['schema']
        table = schema + "." + self.db_config['table_method_detail']

        #sql_command = "INSERT INTO " + table + \
        #            "(project, sha, language, file_name, is_test, method_name, assertion_add, " + \
        #            "assertion_del, total_add, total_del)" + \
        #            "VALUES (" + methodChange + ")"

        sql_command = "INSERT INTO " + table + titleString + " VALUES (" + methodChange + ")"

        if(Util.DEBUG):
                print(sql_command)

        self.dbCon.insert(sql_command)
        self.dbCon.commit()
Example #12
0
class DbChange:
    def __init__(self, config):

        self.cfg = config

        self.connect_db()
        #self.clean_db()

    def connect_db(self):
        self.db_config = self.cfg.ConfigSectionMap("Database")
        logging.debug("Database configuration = %r\n", self.db_config)
        self.dbCon = DatabaseCon(self.db_config['database'], self.db_config['user'], \
                                 self.db_config['host'], self.db_config['port'])

    def clean_db(self):
        schema = self.db_config['schema']
        response = raw_input("Deleting database %s ?" % (self.db_config['schema'] + '.' \
          + self.db_config['table']))
        #response = 'y'
        if response.lower().startswith('y'):
            for table in [self.db_config['table']]:
                tab = schema + "." + table
                print("Deleting from table %r \n" % table)
                sql_command = "DELETE FROM " + tab
                self.dbCon.insert(sql_command)

        self.dbCon.commit()

    def commit_db(self):
        self.dbCon.commit()

    def insert_change_table(self, valueStr):

        schema = self.db_config['schema']
        table = schema + "." + self.db_config['table']

        #print table

        #logging.debug("table = %r" % table)

        sql_command = "INSERT INTO " + table + \
                    "(language, project, file_name, sha, author, author_date, is_bug, " + \
                      "insertion, deletion)" + \
                      "VALUES (" + valueStr + ")"

        #print sql_command
        #logging.debug(sql_command)
        self.dbCon.insert(sql_command)

    def close(self):
        self.dbCon.close()

    @staticmethod
    def toStr(text):
        try:
            text1 = str(text).encode('iso-8859-1')
            temp_text = text1.replace("\'", "\"")
            return "\'" + str(temp_text) + "\'"
        except:
            print type(text)
            return None
        #text = str(text).encode('utf-8')

    def dump_change(self, this_commit):

        author_date = this_commit.author_date.split(" ")[0]

        for c in this_commit.changes:
            insert_str = (',').join(
                (self.toStr(c.tag), self.toStr(this_commit.project),
                 self.toStr(c.file_name), self.toStr(this_commit.sha),
                 self.toStr(this_commit.author), self.toStr(author_date),
                 self.toStr(this_commit.isbug), self.toStr(c.add),
                 self.toStr(c.delete)))

            self.insert_change_table(insert_str)
Example #13
0
class dumpLogs:

  def __init__(self, configFile='config.ini'):

    self.cfg = Config(configFile)
    self.connectDb()
    #self.cleanDb()


  def connectDb(self):

    self.db_config = self.cfg.ConfigSectionMap("Database")
    logging.debug("Database configuration = %r\n", self.db_config)
    self.dbCon = DatabaseCon(self.db_config['database'], self.db_config['user'], \
                             self.db_config['host'], self.db_config['port'])


  def cleanDb(self):

    schema = self.db_config['schema']
    response = 'y' # raw_input("Deleting database %s ?" % (self.db_config['schema']))

    schema = self.db_config['schema']
    tables = []
    tables.append(schema + "." + self.db_config['table_method_detail'])
    tables.append(schema + "." + self.db_config['table_change_summary'])

    if response.lower().startswith('y'):
       for table in tables:
         print("Deleting table %r \n" % table)
         sql_command = "DELETE FROM " + table
         self.dbCon.insert(sql_command)

    self.dbCon.commit()


  def close(self):
    self.dbCon.commit()
    self.dbCon.close()

  def dumpSummary(self, summaryStr):

    schema = self.db_config['schema']
    table = schema + "." + self.db_config['table_change_summary']

    sql_command = "INSERT INTO " + table + \
                "(project, sha, author, commit_date, is_bug)" + \
                "VALUES (" + summaryStr + ")"

    #print sql_command
    self.dbCon.insert(sql_command)
    #self.dbCon.commit()

  def dumpMethodChanges(self, methodChange):

    schema = self.db_config['schema']
    table = schema + "." + self.db_config['table_method_detail']

    sql_command = "INSERT INTO " + table + \
                "(project, sha, language, file_name, is_test, method_name, assertion_add, " + \
                "assertion_del, total_add, total_del)" + \
                "VALUES (" + methodChange + ")"

    #print sql_command
    self.dbCon.insert(sql_command)
Example #14
0
class dumpLogs:

    def __init__(self, password, c_info):
        self.config_info = c_info
        self.cfg = Config(self.config_info.CONFIG)
        self.dbPass = password
        self.connectDb()
        #self.cleanDb()

    @staticmethod
    def getFullTitleString(keywordDictionary):
        '''
        Create a string specifying not only the database column names
        but also their types.  This is used when automatically creating
        the database table.
        '''

        dictStr = "(project character varying(500), sha text, language character varying(500)," + \
            " file_name text, is_test boolean, method_name text"
        for key, value in keywordDictionary.iteritems():
            dictStr= dictStr+", "+ str(key).replace(" ", "_").lower() + " integer" #ToStr will add ' around the strings...

        dictStr += ", total_adds integer, total_dels integer, warning_alert boolean)"

        return dictStr

    def connectDb(self):
        self.db_config = self.cfg.ConfigSectionMap("Database")
        logging.debug("Database configuration = %r\n", self.db_config)
        self.dbCon = DatabaseCon(self.db_config['database'], self.db_config['user'], \
                                 self.db_config['host'], self.db_config['port'], \
                                 self.dbPass)


    def cleanDb(self):

        schema = self.db_config['schema']
        response = 'y' # raw_input("Deleting database %s ?" % (self.db_config['schema']))

        schema = self.db_config['schema']
        tables = []
        tables.append(schema + "." + self.db_config['table_method_detail'])
        tables.append(schema + "." + self.db_config['table_change_summary'])

        if response.lower().startswith('y'):
            for table in tables:
                print("Deleting table %r \n" % table)
                sql_command = "DELETE FROM " + table
                self.dbCon.insert(sql_command)

        self.dbCon.commit()


    def close(self):
        self.dbCon.commit()
        self.dbCon.close()

     #TODO: Improve security here for possible injections?
    def createSummaryTable(self):
        schema = self.db_config['schema']
        table = schema + "." + self.db_config['table_change_summary']
        user = self.db_config['user']

        sql_command = "CREATE TABLE IF NOT EXISTS " + table + " (project character varying(500) NOT NULL," + \
            " sha text NOT NULL, author character varying(500), commit_date date, is_bug boolean,"+ \
            " CONSTRAINT change_summary_pkey PRIMARY KEY (project, sha)) WITH (OIDS=FALSE);"
        self.dbCon.create(sql_command)
        #self.dbCon.create("ALTER TABLE " + table + " OWNER TO " + user + ";")
        #self.dbCon.create("GRANT ALL ON TABLE " + table + " TO " + user + ";")

    def createMethodChangesTable(self, titleString):
        schema = self.db_config['schema']
        table = schema + "." + self.db_config['table_method_detail']
        user = self.db_config['user']

        sql_command = "CREATE TABLE IF NOT EXISTS " + table + titleString + " WITH (OIDS=FALSE);"
        self.dbCon.create(sql_command)
        #self.dbCon.create("ALTER TABLE " + table + " OWNER TO " + user + ";")
        #self.dbCon.create("GRANT ALL ON TABLE " + table + " TO " + user + ";")


    def dumpSummary(self, summaryStr):

        schema = self.db_config['schema']
        table = schema + "." + self.db_config['table_change_summary']

        sql_command = "INSERT INTO " + table + \
                      "(project, sha, author, commit_date, is_bug)" + \
                      " VALUES (" + summaryStr + ")"

        #print sql_command
        self.dbCon.insert(sql_command)
        #self.dbCon.commit()

    def dumpMethodChanges(self, methodChange, titleString):

        schema = self.db_config['schema']
        table = schema + "." + self.db_config['table_method_detail']

        #sql_command = "INSERT INTO " + table + \
        #            "(project, sha, language, file_name, is_test, method_name, assertion_add, " + \
        #            "assertion_del, total_add, total_del)" + \
        #            "VALUES (" + methodChange + ")"

        sql_command = "INSERT INTO " + table + titleString + " VALUES (" + methodChange + ")"

        if(self.config_info.DEBUG):
            print(sql_command)

        self.dbCon.insert(sql_command)
Example #15
0
class dumpLogs:

  def __init__(self, configFile='config.ini'):

    self.cfg = Config(configFile)
    self.connectDb()
    #self.clean_db()


  def connectDb(self):

    self.db_config = self.cfg.ConfigSectionMap("Database")
    logging.debug("Database configuration = %r\n", self.db_config)
    self.dbCon = DatabaseCon(self.db_config['database'], self.db_config['user'], \
                             self.db_config['host'], self.db_config['port'])


  def cleanDb(self):

    schema = self.db_config['schema']
    response = raw_input("Deleting database %s ?" % (self.db_config['schema']))

    if response.lower().startswith('y'):
      pass
      # for table in [self.db_config['table_entropy']]:
      #   tab = schema + "."  + table
      #   print("Deleting table %r \n" % table)
      #   sql_command = "DELETE FROM " + tab
      #   self.dbCon.insert(sql_command)

    self.dbCon.commit()


  # def insert_change_table(self, valueStr):

  #   schema = self.project #self.db_config['schema']
  #   table = schema + "." + self.db_config['table_entropy']

  #   #logging.debug("table = %r" % table)

  #   sql_command = "INSERT INTO " + table + \
  #               "(language, project, snapshot, file_name, line_no, prefix, " + \
  #                 "suffix, is_cache, cache_min_order, cache_backoff_weight, train_type)" + \
  #                 "VALUES (" + valueStr + ")"

  #   print sql_command
  #   #logging.debug(sql_command)
  #   self.dbCon.insert(sql_command)

  def close(self):
    self.dbCon.commit()
    self.dbCon.close()

  def dumpSummary(self, summaryStr):

    schema = self.db_config['schema']
    table = schema + "." + self.db_config['table_change_summary']

    sql_command = "INSERT INTO " + table + \
                "(project, sha, author, commit_date, is_bug)" + \
                "VALUES (" + summaryStr + ")"

    print sql_command
    self.dbCon.insert(sql_command)
    #self.dbCon.commit()

  def dumpMethodChanges(self, methodChange):

    schema = self.db_config['schema']
    table = schema + "." + self.db_config['table_method_detail']

    sql_command = "INSERT INTO " + table + \
                "(project, sha, language, file_name, is_test, method_name, assertion_add, " + \
                "assertion_del, total_add, total_del)" + \
                "VALUES (" + methodChange + ")"

    print sql_command
    self.dbCon.insert(sql_command)