コード例 #1
0
ファイル: gcard_handler.py プロジェクト: dmriser/client
def gcard_handler(args, UserSubmissionID, timestamp, scard_fields):
    #The below two lines are commented out because we are not currently using interactive gcard selection
    #print("You have not specified a custom gcard, please use one of the common CLAS12 gcards listed below \n")
    #scard_fields.data['gcards'] = gcard_selector.select_gcard(args)

    utils.printer("Writing GCards to Database")
    gcard_helper.GCard_Entry(UserSubmissionID, timestamp,
                             scard_fields.data['gcards'])
    print("Successfully added gcards to database")

    return scard_fields
コード例 #2
0
ファイル: scard_handler.py プロジェクト: dmriser/client
def scard_handler(args, UserSubmissionID, timestamp):
    scard_file = args.scard

    #Write the text contained in scard.txt to a field in the UserSubmissions table
    with open(scard_file, 'r') as file:
        scard = file.read()
    strn = """UPDATE UserSubmissions SET {0} = '{1}' WHERE UserSubmissionID = "{2}";""".format(
        'scard', scard, UserSubmissionID)
    utils.db_write(strn)
    utils.printer(
        "UserSubmission specifications written to database with UserSubmissionID {0}"
        .format(UserSubmissionID))

    #See if user exists already in database; if not, add them
    with open(scard_file, 'r') as file:
        scard_text = file.read()
    scard_fields = scard_helper.scard_class(scard_text)

    #Write scard into scard table fields (This will not be needed in the future)
    print("\nReading in information from {0}".format(scard_file))
    utils.printer("Writing SCard to Database")
    scard_fields.data['group_name'] = scard_fields.data.pop(
        'group'
    )  #'group' is a protected word in SQL so we can't use the field title "group"
    # For more information on protected words in SQL, see https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls?KEY=RSQL_reservedwords

    if 'http' in scard_fields.data.get('generator'):
        print(
            "Online repository for generator files specified. On server will download LUND files from:"
        )
        print("{0}".format(scard_fields.data.get('generator')))
        scard_fields.data['genExecutable'] = "Null"
        scard_fields.data['genOutput'] = "Null"
        scard_fields.data['genOptions'] = "Null"
        scard_fields.data['nevents'] = "User Lund File Driven"
        scard_fields.data['jobs'] = "One per User Lund File"
    else:
        scard_fields.data['genExecutable'] = fs.genExecutable.get(
            scard_fields.data.get('generator'))
        scard_fields.data['genOutput'] = fs.genOutput.get(
            scard_fields.data.get('generator'))

    scard_helper.SCard_Entry(UserSubmissionID, timestamp, scard_fields.data)
    print(
        '\t Your scard has been read into the database with UserSubmissionID = {0} at {1} \n'
        .format(UserSubmissionID, timestamp))

    return scard_fields
コード例 #3
0
def write_files(sub_file_obj,params):
  sf = sub_file_obj
  p = params
  if sf.name != file_struct.run_job_obj.name:
    old_vals, new_vals = utils.grab_DB_data(p['table'],sf.overwrite_vals,p['BatchID'])
  else:
    old_vals, new_vals = sf.overwrite_vals.keys(), (file_struct.run_job_obj.overwrite_vals['runscript.overwrite'],)
  utils.printer("\tWriting submission file '{0}' based off of specifications of BatchID = {1}, GcardID = {2}".format(sf.file_base,
        p['BatchID'],p['GcardID']))
  extension = "_gcard_{}_batch_{}".format(p['GcardID'],p['BatchID'])
  newfile = sf.file_path+sf.file_base+extension+sf.file_end
  out_strn = utils.overwrite_file(p['temp_location']+sf.file_base+sf.file_end+".template",newfile,old_vals,new_vals)
  if sf.file_base == 'runscript':
    out_strn = utils.overwrite_file(newfile,newfile,['gcards_gcard',],[p['gfile'],])#Need to pass arrays to overwrite_file function
    file_struct.run_job_obj.overwrite_vals['runscript.overwrite'] = newfile #this is needed for run_job.sh since we do not go through the database
  str_script_db = out_strn.replace('"',"'") #I can't figure out a way to write "" into a sqlite field without errors
  #For now, we can replace " with ', which works ok, but IDK how it will run if the scripts were submitted to HTCondor
  #for field, value in (sf.file_text_fieldname,str_script_db):
  strn = 'UPDATE Submissions SET {0} = "{1}" WHERE GcardID = {2};'.format(sf.file_text_fieldname,str_script_db,p['GcardID'])
  utils.sql3_exec(strn)
コード例 #4
0
def Batch_Entry(scard_file):
    timestamp = utils.gettime(
    )  # Can modify this if need 10ths of seconds or more resolution
    #Assign a user and a timestamp for a given batch
    strn = """INSERT INTO Batches(timestamp) VALUES ("{0}");""".format(
        timestamp)
    BatchID = utils.sql3_exec(strn)

    #Write the text contained in scard.txt to a field in the Batches table
    with open(scard_file, 'r') as file:
        scard = file.read()
    strn = """UPDATE Batches SET {0} = '{1}' WHERE BatchID = "{2}";""".format(
        'scard', scard, BatchID)
    utils.sql3_exec(strn)
    utils.printer(
        "Batch specifications written to database with BatchID {0}".format(
            BatchID))

    #See if user exists already in database; if not, add them
    with open(scard_file, 'r') as file:
        scard_text = file.read()
    scard_fields = scard_helper.scard_class(scard_text)
    username = user_validation.user_validation()

    #Write scard into scard table fields (This will not be needed in the future)
    print("\nReading in information from {0}".format(scard_file))
    utils.printer("Writing SCard to Database")
    scard_fields.data['group_name'] = scard_fields.data.pop(
        'group'
    )  #'group' is a protected word in SQL so we can't use the field title "group"
    # For more information on protected words in SQL, see https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls?KEY=RSQL_reservedwords
    scard_fields.data['genExecutable'] = file_struct.genExecutable.get(
        scard_fields.data.get('generator'))
    scard_fields.data['genOutput'] = file_struct.genOutput.get(
        scard_fields.data.get('generator'))
    scard_helper.SCard_Entry(BatchID, timestamp, scard_fields.data)
    print(
        '\t Your scard has been read into the database with BatchID = {0} at {1} \n'
        .format(BatchID, timestamp))

    #Write gcards into gcards table
    utils.printer("Writing GCards to Database")
    gcard_helper.GCard_Entry(BatchID, timestamp, scard_fields.data['gcards'])
    print("Successfully added gcards to database")
    strn = "UPDATE Batches SET {0} = '{1}' WHERE BatchID = {2};".format(
        'User', username, BatchID)
    utils.sql3_exec(strn)

    return 0
コード例 #5
0

#The code will try to submit a defualt user to the DB. If the default user already exists,
#then the prompt will come up at the command line asking for a new user
# IF the username that is returned already exists in the command line, another error will be returned and program will quit.
if __name__ == "__main__":
    try:
        conn = sqlite3.connect(file_struct.DB_path + file_struct.DBname)
        c = conn.cursor()
        c.execute('PRAGMA foreign_keys = ON;')
        strn = command_writer(file_struct.default_user,
                              file_struct.default_hostname)
        c.execute(strn)
        if int(file_struct.DEBUG) == 2:
            utils.printer(
                'Executing SQL Command: {}'.format(strn)
            )  #Turn this on for explict printing of all DB write commands
        conn.commit()
        c.close()
        conn.close()
        utils.printer("Record added to DB for User")
    except sqlite3.IntegrityError:
        try:
            c.close()
            conn.close()
            utils.printer(
                "Default user '{0}' is already in Users table. Please enter a new, unique user"
                .format(file_struct.default_user))
            user, hostname = manual_data()
            strn = command_writer(user, hostname)
            utils.sql3_exec(strn)