def do_push(in_value): """(push) (2 => 3) [(1, 40014149), (2, 42755279), (3, 45167012)]""" (depth, folder_file_id) = in_value # test for push of something other than just one. shouldn't happen. if prev_depth != len(in_stak): GPR.print_it1( "(push) prev_depth (%d) != len(in_stak) (%d)\n" % (prev_depth, len(in_stak)) ) GPR.print_it0( "(push) (%r" % (prev_depth,) ) in_stak.append(in_value) GPR.print_it0( "=> %r)" % ( depth) ) GPR.print_it1( "%r" % in_stak ) GPR.print_it1( "" ) tally["(push)"] +=1
def do_arg_gen(basepath, cnx, options): x_gen = files_generator(basepath, options) my_stak = stak() # contains self.RS fs_gen = partial(files_stak_gen, in_stak=my_stak, cnx=cnx) y_gen = partial(vol_id_gen, cnx) # for fs_dict in y_gen( fs_gen( x_gen ) ): for fs_dict in fs_gen( y_gen( x_gen ) ): depth = fs_dict['depth'] file_id = fs_dict['NSFileSystemFileNumber'] if is_a_directory(fs_dict, options): GPR.print_it0( "(directory)" ) if (depth < 0 ): GPR.print_it1( "(depth < 0)" ) # eol else: dir_is_up_to_date = not options.force_folder_scan and db_file_exists(cnx, fs_dict) fs_dict['directory_is_up_to_date'] = dir_is_up_to_date if (dir_is_up_to_date): GPR.print_it1( "(up_to_date)" ) # eol else: GPR.print_it0( "(to_be_scanned)" ) GPR.print_it0( "(scanning)" ) rel = db_query_folder(cnx, fs_dict) GPR.print_it0( "(len=%r)" % (len(rel),) ) GPR.print_it0( "(storing at) %r" % ( (depth+1, file_id) ,) ) # don't store those of zero length because you'll never pop them? no: # do store zero lengths because we will want to "subtract against them" in directory check. my_stak.RS[ (depth+1, file_id) ] = rel GPR.print_it1( "stak: %r" % (my_stak,) ) # eol fs_dict['sql_action'] = "update_directory" GPR.print_it0( "(update directory)" ) folder_id = fs_dict['NSFileSystemFolderNumber'] fs_dict['current_item_directory_is_being_checked'] = (depth, folder_id) in my_stak.RS if fs_dict['current_item_directory_is_being_checked']: GPR.print_it0( "(check against container directory %r)" % ((depth,folder_id ) ,) , verbose_level_threshold=3) vol_id = fs_dict['vol_id'] filename = fs_dict[NSURLNameKey] # still unicode, encode late. required_fields = ['vol_id', 'folder_id', 'file_name', 'file_id', 'file_mod_date' ] sql_dict = GetDR(fs_dict, required_fields, quote_and_escape=False, verbose_level_threshold=4) #ie, not for sql, just for values rs = ( vol_id, folder_id, filename, file_id, sql_dict['file_mod_date']) rs2 = tuple([filename if k == 'file_name' else sql_dict[k] for k in required_fields]) # unicode filename if rs != rs2: print "\n%r != %r\n" % (rs, rs2) if rs in my_stak.RS[ (depth,folder_id ) ]: my_stak.RS[ (depth,folder_id ) ] -= rs GPR.print_it0( "(ignore)" ) GPR.print_it0( "(already in database) %r" % my_stak ) else: fs_dict['to_be_inserted'] = True fs_dict['sql_action'] = "insert" GPR.print_it0( "(insert)" ) # # try: # my_stak.RS[ (depth,folder_id ) ] -= rs # my_stak.RS[ (depth,folder_id ) ]._convert_to_row(rs) , or just, tuple(in_row) # GPR.print_it0( "(ignore)" ) # GPR.print_it0( "(already in database) %r" % my_stak ) # except KeyError: # ie, the key of rs is not in the set of stak.ts[(d,fid)] # fs_dict['to_be_inserted'] = True # fs_dict['sql_action'] = "insert" # GPR.print_it0( "(insert)" ) yield fs_dict # end gen if options.verbose_level >= 3: print "end do_arg_gen. my_stak is", my_stak
def do_pop(): """ (pop) (3 => 2) [(1, 40014149), (2, 42755279)]""" # test for pop of something other than just one. can happen. is okay:) if depth+1 != len(in_stak): GPR.print_it1( " (pop) depth+1 (%d) != len(in_stak) (%d)\n" % (depth+1, len(in_stak)) ) GPR.print_it0( " (pop) (%r"% (len(in_stak), ) ) tally["(pop)"] +=1 (d,ffid) = in_stak.pop() GPR.print_it0( "=> %r) "% (len(in_stak), ) ) # this should really be a method on a subclass of stak? if hasattr(in_stak, 'RS'): if (d,ffid) in in_stak.RS: # in_stak.RS.keys(): GPR.print_it0( "key %r in stak: %r" % ((d,ffid), in_stak) ) GPR.print_it1( "(dict)") GPR.print_it1("") return in_stak.RS.pop((d,ffid)) # in_stak.RS[(d,ffid)] else: # not error, directory was up to date(?) GPR.print_it1( "key %r not in stak: %r" % ((d,ffid), in_stak) ) GPR.print_it1("") return [] else: GPR.print_it0( "in_stak has no attr 'RS'" ) GPR.print_it1( "%r" % in_stak ) GPR.print_it1("") return []