<commit_before>#!C:\Python26\python.exe -u

#  pow model generator.
#
# options are: 
#   see: python generate_migration.py --help


import os, datetime, time
from optparse import OptionParser
import sqlite3
import sys
import datetime
from sqlalchemy.orm import mapper
from sqlalchemy import *

sys.path.append( os.path.abspath(os.path.join( os.path.dirname(os.path.abspath(__file__)), "./lib" )))
sys.path.append( os.path.abspath(os.path.join( os.path.dirname(os.path.abspath(__file__)), "./models" )))

import powlib
import App

# setting the right defaults
MODE_CREATE = 1
MODE_REMOVE = 0
PARTS_DIR = powlib.PARTS_DIR
def main():
    parser = OptionParser()
    mode= MODE_CREATE
    parser.add_option("-n", "--name",  action="store", type="string", dest="name", help="creates migration with name = <name>. Only for jobs", default ="None")
    parser.add_option("-m", "--model",  action="store", type="string", dest="model", help="defines the model for this migration.", default ="None")
    parser.add_option("-c", "--comment",  action="store", type="string", dest="comment", help="defines a comment for this migration.", default ="No Comment")
    parser.add_option("-j", "--job",  action="store", type="string", dest="job", help="creates migration job, e.g for backups, restores etc.",default="None")
    parser.add_option("-d", "--column-definitions",  action="store", 
                        type="string", dest="col_defs", 
                        help="Pre define the column definitions. Name, type, options (all SQLAlchemy style).",default="None")

    (options, args) = parser.parse_args()
    #print options
    if options.model == "None" and options.job == "None":
        if len(args) > 0:
            # if no option flag (like -m) is given, it is assumed that the first argument is the model. (representing -m arg1)
            options.model = args[0]
            migration_name = options.model
            migration_model = options.model
        else:
            parser.error("You must at least specify an appname by giving -n <name>.")
            return
    else:
        if options.name == "None":
            migration_name = options.model
        else:
            migration_name = options.name
            #migration_name = options.name
        migration_model = options.model
    
    start = None
    end = None
    start = datetime.datetime.now()
    
    if options.job != "None":
        render_migration_job(options.job)
    else:
        render_migration(migration_name, migration_model,options.comment)
    
    end = datetime.datetime.now()
    duration = None
    duration = end - start 
    
    print "generated_migration in("+ str(duration) +")"
    return
    
def render_migration(name, model, comment):
    # 
    
    #print "generate_migration: " + name + "  for model: " + model
    
    # add the auto generated warning to the outputfile
    infile = open (os.path.normpath(PARTS_DIR + "/can_be_edited.txt"), "r")
    ostr = infile.read()
    infile.close()
    
    # add a creation date
    ostr = ostr + os.linesep
    ostr = ostr + "# date created: \t" + str(datetime.date.today())
    ostr = ostr + os.linesep
    
    # Add the model_stub part1 content to the newly generated file. 
    infile = open (os.path.normpath( PARTS_DIR + "db_migration_stub2_part1.py"), "r")
    ostr = ostr + infile.read()
    infile.close()
    
    pluralname = powlib.plural(model)
    ostr += powlib.tab +  "table_name=\"" + pluralname + "\""
    ostr += powlib.linesep
    #print "modelname was: " + model + "  pluralized table_name is:" + pluralname
    <commit_msg>small changes to generate_migration<commit_after>#!C:\Python26\python.exe -u

#  pow model generator.
#
# options are: 
#   see: python generate_migration.py --help


import os, datetime, time
from optparse import OptionParser
import sqlite3
import sys
import datetime
from sqlalchemy.orm import mapper
from sqlalchemy import *

sys.path.append( os.path.abspath(os.path.join( os.path.dirname(os.path.abspath(__file__)), "./lib" )))
sys.path.append( os.path.abspath(os.path.join( os.path.dirname(os.path.abspath(__file__)), "./models" )))

import powlib
import App

# setting the right defaults
MODE_CREATE = 1
MODE_REMOVE = 0
PARTS_DIR = powlib.PARTS_DIR
def main():
    parser = OptionParser()
    mode= MODE_CREATE
    parser.add_option("-n", "--name",  action="store", type="string", dest="name", help="creates migration with name = <name>. Only for jobs", default ="None")
    parser.add_option("-m", "--model",  action="store", type="string", dest="model", help="defines the model for this migration.", default ="None")
    parser.add_option("-c", "--comment",  action="store", type="string", dest="comment", help="defines a comment for this migration.", default ="No Comment")
    parser.add_option("-j", "--job",  action="store", type="string", dest="job", help="creates migration job, e.g for backups, restores etc.",default="None")
    parser.add_option("-d", "--column-definitions",  action="store", 
                        type="string", dest="col_defs", 
                        help="Pre define the column definitions. Name, type, options (all SQLAlchemy style).",
                        default="None")

    (options, args) = parser.parse_args()
    #print options
    if options.model == "None" and options.job == "None":
        if len(args) > 0:
            # if no option flag (like -m) is given, it is assumed that the first argument is the model. (representing -m arg1)
            options.model = args[0]
            migration_name = options.model
            migration_model = options.model
        else:
            parser.error("You must at least specify an migration name by giving -n <name>.")
            return
    else:
        if options.name == "None":
            migration_name = options.model
        else:
            migration_name = options.name
            #migration_name = options.name
        migration_model = options.model
    
    
    start = None
    end = None
    start = datetime.datetime.now()
    
    if options.job != "None":
        render_migration_job(options.job)
    else:
        render_migration(migration_name, migration_model,options.comment, options.col_defs)
    
    end = datetime.datetime.now()
    duration = None
    duration = end - start 
    
    print "generated_migration in("+ str(duration) +")"
    return
    
def render_migration(name, model, comment, col_defs):
    # 
    #print "generate_migration: " + name + "  for model: " + model
    #
    
    # add the auto generated warning to the outputfile
    infile = open (os.path.normpath(PARTS_DIR + "/can_be_edited.txt"), "r")
    ostr = infile.read()
    infile.close()
    
    # add a creation date
    ostr = ostr + os.linesep
    ostr = ostr + "# date created: \t" + str(datetime.date.today())
    ostr = ostr + os.linesep
    
    # Add the model_stub part1 content to the newly generated file. 
    infile = open (os.path.normpath( PARTS_DIR + "db_migration_stub2_part1.py"), "r")
    ostr = ostr + infile.read()
    infile.close()
    
    pluralname = powlib.plural(model)
    ostr += powlib.tab +  "table_name=\"" + pluralname + "\""
    ostr += powlib.linesep
    #print "modelname was: " + model + "  pluralized table_name is:" + pluralname
    
{'fraction_non_alphanumeric': 0.1325102880658436, 'fraction_numerical': 0.003017832647462277, 'mean_word_length': 2.8495248152059136, 'pattern_counts': {'":': 6, '<': 7, '<?xml version=': 0, '>': 9, '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': '3354749', 'n_tokens_mistral': 2269, 'n_tokens_neox': 2251, 'n_words': 609}