<commit_before>class Revisioner(): 

  def install(self):

    import argparse
    parser = argparse.ArgumentParser(description='Process Revisioner params.')
    parser.add_argument('--project', help='Project name')

    parser.add_argument('--dbhost', help='MySQL Db host', default="localhost")
    parser.add_argument('--dbuser', help='MySQL Db user')
    parser.add_argument('--dbpass', help='MySQL Db pass')
    parser.add_argument('--dbname', help='MySQL Db name to revision')

    args = parser.parse_args()

    if args.project is None:
      print "Project name cant be empty"
      return

    if args.dbhost is None:
      print "MySQL db host cant be empty"
      return

    if args.dbuser is None:
      print "MySQL db user cant be empty"
      return

    if args.dbpass is None:
      print "MySQL db pass cant be empty"
      return

    if args.dbname is None:
      print "MySQL db name cant be empty"
      return

    import MySQLdb
    try:
      self.conn = MySQLdb.connect(
        host = args.dbhost, 
        user = args.dbuser, 
        passwd = args.dbpass, 
        unix_socket = '/Applications/MAMP/tmp/mysql/mysql.sock',
      )
    except Exception as e:
      print e
      return

    import os
    if not os.path.exists(".revisions"):
      os.makedirs(".revisions")

    import json
    f = ".revisions/%s.json" % args.project
    if not os.path.exists(f):
      file = open(f, 'w+')
      data = { 
          "dbname" : args.dbname, 
          "version": 0, 
          "dbuser" : args.dbuser,
          "dbhost" : args.dbhost,
          "project": args.project
      }
      file.write(json.dumps(data))
    else:
      with open(f, 'r') as content_file:
        data = content_file.read()
      
      data = json.loads(str(data))
   
    v = ".revisions/v%d" % data['version']
    if not os.path.exists(v):
      os.makedirs(v)

    cursor = self.conn.cursor(cursorclass=MySQLdb.cursors.DictCursor)
    cursor.execute("USE "+ args.dbname)

    """ current database structure """
    cursor.execute("SHOW TABLES")
    rows = cursor.fetchall()
    tables = []
    for row in rows:
      table_name = row["Tables_in_%s" % args.dbname]
      cursor.execute("SHOW CREATE TABLE %s" %table_name)
      table_create = cursor.fetchone()
      table_create = table_create["Create Table"]
      cursor.execute("SHOW COLUMNS FROM %s" %table_name)
      columns = []
      columns_rows = cursor.fetchall()
      for column in columns_rows:
        columns.append(column)
      table_columns = columns
      from datetime import datetime
      table_date = str(datetime.today().strftime("%Y-%m-%d %H:%M:%S"))
      tables.append({
        "table_name": table_name,
        "table_columns": table_columns,
        "table_create" : table_create,
        "table_date"   : table_date
      })
    
    niurevision = []
    t = "%s/tables.json" %v
    if not os.path.exists(t):
      file = open(t, 'w+')
      file.write(json.dumps(tables))
    else:
      with open(t, 'r') as content_file:
        data = content_file.read()
      
      """ current revision database structure """
      revision = json.loads(data)
      for table in tables:
        compare = None
        for rev in revision:
          if rev["table_name"] == table["table_name"]:
            compare = rev
            break
        
        """ new table created """
        if compare is None:
          niurevision.append(table)
          break

        """ the table change its structure """
        if compare["table_create"] != table["table_create"]:
          print "table change structure"
          print table["table_columns"]


    print niurevision

def main():
  r = Revisioner()<commit_msg>find tables that has been deleted<commit_after>class Revisioner(): 

  def install(self):

    import argparse
    parser = argparse.ArgumentParser(description='Process Revisioner params.')
    parser.add_argument('--project', help='Project name')

    parser.add_argument('--dbhost', help='MySQL Db host', default="localhost")
    parser.add_argument('--dbuser', help='MySQL Db user')
    parser.add_argument('--dbpass', help='MySQL Db pass')
    parser.add_argument('--dbname', help='MySQL Db name to revision')

    args = parser.parse_args()

    if args.project is None:
      print "Project name cant be empty"
      return

    if args.dbhost is None:
      print "MySQL db host cant be empty"
      return

    if args.dbuser is None:
      print "MySQL db user cant be empty"
      return

    if args.dbpass is None:
      print "MySQL db pass cant be empty"
      return

    if args.dbname is None:
      print "MySQL db name cant be empty"
      return

    import MySQLdb
    try:
      self.conn = MySQLdb.connect(
        host = args.dbhost, 
        user = args.dbuser, 
        passwd = <PASSWORD>.dbpass, 
        unix_socket = '/Applications/MAMP/tmp/mysql/mysql.sock',
      )
    except Exception as e:
      print e
      return

    import os
    if not os.path.exists(".revisions"):
      os.makedirs(".revisions")

    import json
    f = ".revisions/%s.json" % args.project
    if not os.path.exists(f):
      file = open(f, 'w+')
      data = { 
          "dbname" : args.dbname, 
          "version": 0, 
          "dbuser" : args.dbuser,
          "dbhost" : args.dbhost,
          "project": args.project
      }
      file.write(json.dumps(data))
    else:
      with open(f, 'r') as content_file:
        data = content_file.read()
      
      data = json.loads(str(data))
   
    v = ".revisions/v%d" % data['version']
    if not os.path.exists(v):
      os.makedirs(v)

    cursor = self.conn.cursor(cursorclass=MySQLdb.cursors.DictCursor)
    cursor.execute("USE "+ args.dbname)

    """ current database structure """
    cursor.execute("SHOW TABLES")
    rows = cursor.fetchall()
    tables = []
    for row in rows:
      table_name = row["Tables_in_%s" % args.dbname]
      cursor.execute("SHOW CREATE TABLE %s" %table_name)
      table_create = cursor.fetchone()
      table_create = table_create["Create Table"]
      cursor.execute("SHOW COLUMNS FROM %s" %table_name)
      columns = []
      columns_rows = cursor.fetchall()
      for column in columns_rows:
        columns.append(column)
      table_columns = columns
      from datetime import datetime
      table_date = str(datetime.today().strftime("%Y-%m-%d %H:%M:%S"))
      tables.append({
        "table_name": table_name,
        "table_columns": table_columns,
        "table_create" : table_create,
        "table_date"   : table_date
      })
    
    niurevision = []
    t = "%s/tables.json" %v
    if not os.path.exists(t):
      file = open(t, 'w+')
      file.write(json.dumps(tables))
    
    else:
      with open(t, 'r') as content_file:
        data = content_file.read()
      
      """ current revision database structure """
      revision = json.loads(data)
      for table in tables:
        compare = None
        for rev in revision:
          if rev["table_name"] == table["table_name"]:
            compare = rev
            break
        
        """ new table created """
        if compare is None:
          niurevision.append(table)
          break

        """ the table change its structure """
        if compare["table_create"] != table["table_create"]:
          print "table change structure"
          print table["table_name"]

      
      for rev in revision:
        compare = None
        for table in tables:
          if rev["table_name"] == table["table_name"]:
            compare = rev
            break
        
        """ a table has been deleted """
        if compare is None:
          niurevision.append({
            "table_name" : rev["table_name"],
            "table_drop" : " DROP TABLE %s" % rev["table_name"]
          })

    print niurevision

def main():
  r = Revisioner()
{'fraction_non_alphanumeric': 0.12096465484241418, 'fraction_numerical': 0.00025519969376036747, 'mean_word_length': 2.166868686868687, 'pattern_counts': {'":': 8, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1247551', 'n_tokens_mistral': 2435, 'n_tokens_neox': 2362, 'n_words': 615}