def test2_4(): try: for i in range(1,10): s="file" s+=str(i) os.remove("/mnt/ganesha-mnt/%s"%s) except OSError as ex : print (ex) print "Test 2.4:FAIL" else: success("2.4") global count count = count + 1
def test1_4(): #message.header2("1.4") try: for i in range(1, 10): s = "dir" s += str(i) shutil.rmtree('/mnt/ganesha-mnt/%s' % s) except OSError as ex: print(ex) print "Test 1.4 : FAIL" else: success("1.4") global count count = count + 1
def test1_4 (): #message.header2("1.4") try: for i in range(1,10): s="dir" s+=str(i) shutil.rmtree('/mnt/ganesha-mnt/%s'%s) except OSError as ex: print (ex) print "Test 1.4 : FAIL" else: success("1.4") global count count = count + 1
def test1_1(): #message.header2("1.1",log_file) try: for i in range(1, 10): s = "dir" s += str(i) #printf1("os.mkdir('/mnt/ganesha-mnt/",s) os.mkdir('/mnt/ganesha-mnt/%s' % s) except OSError as ex: print(ex) print " Test 1.1: FAIL" else: success("1.1") global count count = count + 1
def test1_1 (): #message.header2("1.1",log_file) try: for i in range(1,10): s="dir" s+=str(i) #printf1("os.mkdir('/mnt/ganesha-mnt/",s) os.mkdir('/mnt/ganesha-mnt/%s'%s) except OSError as ex: print(ex) print " Test 1.1: FAIL" else: success("1.1") global count count = count + 1
def test2_3(): try: for i in range(1,10): s="file" s+=str(i) #printf1("os.mkdir('/mnt/ganesha-mnt/",s) fo=open('/mnt/ganesha-mnt/%s'%s,'r') fo.read(10) fo.close except IOError as ex: print(ex) print "Test 2.3:FAIL" else: success("2.3") global count count = count + 1
def test2_1 (): #message.header2("2.1") try: for i in range(1,10): s="file" s+=str(i) #printf1("os.mkdir('/mnt/ganesha-mnt/",s) fo=open('/mnt/ganesha-mnt/%s'%s,'w') fo.close() except OSError as ex: print(ex) print " Test 2.1: FAIL" else: success("2.1") global count count = count + 1
def test2_2(): # message.header2("2.1") try: for i in range(1,10): s="file" s+=str(i) #printf1("os.mkdir('/mnt/ganesha-mnt/",s) fo=open('/mnt/ganesha-mnt/%s'%s,'w') fo.write("This is a test to check if the file is written") fo.close except IOError as ex: print (ex) print "Test 2.2:FAIL" else: success("2.2") global count count = count + 1
def test1_2(): #message.header2("1.2") try: for i in range(1, 10): s = "dir" s += str(i) for j in range(1, 3): k = "dir" k += str(j) # print "os.mkdir('/mnt/ganesha-mnt/%s/%s')" %(s,k) os.mkdir('/mnt/ganesha-mnt/%s/%s' % (s, k)) except OSError as ex: print(ex) print "Test 1.2 : FAIL " else: success("1.2") global count count = count + 1
def test1_2 (): #message.header2("1.2") try: for i in range(1,10): s="dir" s+=str(i) for j in range(1,3): k="dir" k+=str(j) # print "os.mkdir('/mnt/ganesha-mnt/%s/%s')" %(s,k) os.mkdir('/mnt/ganesha-mnt/%s/%s' %(s,k)) except OSError as ex: print (ex) print "Test 1.2 : FAIL " else: success("1.2") global count count = count + 1
def test1_3(): #message.header2("1.3") try: for i in range(1, 10): s = "dir" s += str(i) for j in range(1, 10): k = "file" k += str(j) # print"open('/mnt/ganesha-mnt/%s/%s' %(s,k),'w')" fo1 = open('/mnt/ganesha-mnt/%s/%s' % (s, k), 'w') fo1.close() except IOError as ex: print(ex) print "Test 1.3 : FAIL" else: success("1.3") global count count = count + 1
def test1_3 (): #message.header2("1.3") try: for i in range(1,10): s="dir" s+=str(i) for j in range(1,10): k="file" k+=str(j) # print"open('/mnt/ganesha-mnt/%s/%s' %(s,k),'w')" fo1 = open('/mnt/ganesha-mnt/%s/%s' %(s,k),'w') fo1.close() except IOError as ex: print (ex) print "Test 1.3 : FAIL" else: success("1.3") global count count = count + 1
def do_permissions(): accept = request.forms.get('Accept') userid = request.get_cookie("userid", secret='teamfin') db = sqlite3.connect('database/jogrx.db') c = db.cursor() if accept: c.execute("UPDATE user SET accept_terms=? WHERE id=?", (1, int(userid))) db.commit() c.close() return success() else: c.execute("UPDATE user SET accept_terms=? WHERE id=?", (0, int(userid))) db.commit() c.close() return home()
def do_belief_report(): global args precisionconn = None precisioncur = None if args.precision_db: precisionconn = sqlite3.connect(args.precision_db) #Don't lock db precisionconn.row_factory = sqlite3.Row precisioncur = precisionconn.cursor() #Start assembling locations if success.success(os.path.join(args.output_directory, "analyze_cookie_files.sh.status.log")): inconn = sqlite3.connect(os.path.join(args.output_directory, "analyze_cookie_files.sh", "cookie_files_votes.db")) #Don't lock db inconn.row_factory = sqlite3.Row incur = inconn.cursor() for row in incur.execute("SELECT * FROM cookie_files_votes;"): break #TODO inconn.close() print(""" <h2><a name="location_beliefs">Location beliefs</a></h2> <p>This location has artifacts that indicate it was in the following locations:</p> <table> <thead> <tr> <th>Location name</th> <th>Latitude</th> <th>Longitude</th> <th>Shurity</th> </tr> </thead> <tfoot></tfoot> <tbody>""") for x in [{ "location":"(Ranked implementation pending)", "latitude":1.1, "longitude":2.2, "shurity":1.0 }]: print(" <tr><td>%(location)s</td><td>%(latitude)f</td><td>%(longitude)f</td><td>%(shurity)f</td></tr>" % x) print(""" </tbody> </table>""")
def ingest_table(outcur, lookupcur, gtcur, results_dir, scriptname, dbname, tablename): global args global lookup_memoizer if success.success(os.path.join(results_dir, scriptname + ".status.log")): image_id = os.path.basename(results_dir) dprint("Debug: image_id: %r" % image_id) dprint("Debug: results_dir: %r" % results_dir) dprint("Debug: scriptname: %r" % scriptname) dprint("Debug: dbname: %r" % dbname) try: results_conn = sqlite3.connect(os.path.join(results_dir, scriptname, dbname)) except: raise results_conn.row_factory = sqlite3.Row results_conn.isolation_level = "EXCLUSIVE" #lock database results_cur = results_conn.cursor() results_cur.execute("SELECT * FROM %s;" % tablename) #Check if we're counting ground truth for this image image_ground_truth_available = False if gtcur is not None: gtcur.execute("SELECT COUNT(*) AS tally FROM location_ground_truth WHERE image_id = ?;", (image_id,)) gtrows = [row for row in gtcur] image_ground_truth_available = gtrows[0]["tally"] > 0 for row in results_cur: outdict = {k:row[k] for k in row.keys()} outdict["image_id"] = image_id geoproc_library.insert_db(outcur, tablename, outdict) if gtcur is not None and image_ground_truth_available: list_vals = [] non_null_results_cols = [bcol for bcol in LOCATION_COLUMNS if outdict.get(bcol)] sqlite3_extra_where = "" mysql_extra_where = "" for bcol in non_null_results_cols: #This sqlite query matches in the case where ground truth is not city-granularity sqlite3_extra_where += " AND (" + bcol + " = ? OR " + bcol + " IS NULL)" mysql_extra_where += " AND " + bcol + " = %s" list_vals.append(outdict[bcol]) #Make sure the search has at least one narrowing component if len(list_vals) == 0: continue if not (sqlite3_extra_where, tuple([image_id] + list_vals)) in gt_memoizer: gtquery = "SELECT country,region,city FROM location_ground_truth WHERE image_id = ?" gtquery += sqlite3_extra_where + ";" gtcur.execute(gtquery, tuple([image_id] + list_vals)) gt_memoizer[(sqlite3_extra_where, tuple([image_id] + list_vals))] = [(row["country"], row["region"], row["city"]) for row in gtcur] if not (mysql_extra_where, tuple(list_vals)) in lookup_memoizer: lookupquery = "SELECT country,region,city FROM DistinctLocations WHERE 1=1" lookupquery += mysql_extra_where + ";" lookupcur.execute(lookupquery, tuple(list_vals)) lookup_memoizer[(mysql_extra_where, tuple(list_vals))] = [(row["country"], row["region"], row["city"]) for row in lookupcur] gtrecs = gt_memoizer[(sqlite3_extra_where, tuple([image_id] + list_vals))] lookuprecs = lookup_memoizer[(mysql_extra_where, tuple(list_vals))] #dprint("Debug: lookupquery = %r." % lookupquery) #dprint("Debug: list_vals = %r." % list_vals) #Get worldwide number of matching locations if one of the fields is missing dprint("Debug: len(lookuprecs) = %d." % len(lookuprecs)) #Mark current vote correct by counting the number of matches in the ground truth query outdict["correct_location"] = len([rec for rec in gtrecs if (outdict["country"], outdict["region"], outdict["city"]) == rec]) for (colno, col) in enumerate(LOCATION_COLUMNS): outdict["correct_" + col] = len([rec for rec in gtrecs if rec[colno] == outdict[col]]) outdict["number_possible_locations"] = len(lookuprecs) geoproc_library.insert_db(outcur, tablename + "_weighted", outdict) results_conn.close()
parser.add_argument("-a", "--anonymize", action="store_true", help="Do not print file system entries.") parser.add_argument("-p", "--precision_db", dest="precision_db", help="Database of precision for feature types.") args = parser.parse_args() if args.process_dir: dprint("Debug: Getting results databases from process_dir argument.") results_dir_list = geoproc_library.get_results_dirs(args.process_dir) if len(results_dir_list) != 1: sys.stderr.write("Error: --process_dir argument is not a singular GeoProc output directory.\n") sys.exit(1) #Do an extra test for TSK anno if not args.__dict__.get("fs_anno_dir"): if success.success(os.path.join(args.process_dir, "verify_fiwalk_versus_tsk_db.sh.status.log")): args.__dict__["fs_anno_dir"] = os.path.join(args.process_dir, "verify_fiwalk_versus_tsk_db.sh") for (args_param, analysis_dir, analysis_db) in TABLE_SCRIPT_DB: dprint("Debug: Testing %r." % ((args_param, analysis_dir, analysis_db),)) if args.__dict__.get(args_param): dprint("Argument already present.") continue status_log_path = os.path.join(args.process_dir, analysis_dir + ".status.log") if not success.success(status_log_path): dprint("Not successful (checked %r.)." % status_log_path) continue args.__dict__[args_param] = os.path.join(args.process_dir, analysis_dir, analysis_db) infiles = set([ args.cookie_files_votes,