def UpdateCustomers(): printlog("UpdateCustomers " + str(time.strftime("%a, %d %b %Y %H:%M:%S +0000"))) space = dhnio._read_dict(CustomersSpaceFile()) if space is None: printlog("UpdateCustomers ERROR space file can not read") return customers_dir = getCustomersFilesDir() if not os.path.exists(customers_dir): printlog("UpdateCustomers ERROR customers folder not exist") return remove_list = {} for customer_filename in os.listdir(customers_dir): onecustdir = os.path.join(customers_dir, customer_filename) if not os.path.isdir(onecustdir): remove_list[onecustdir] = "is not a folder" continue idurl = FilenameUrl(customer_filename) if idurl is None: remove_list[onecustdir] = "wrong folder name" continue curspace = space.get(idurl, None) if curspace is None: remove_list[onecustdir] = "is not a customer" continue for path in remove_list.keys(): if not os.path.exists(path): continue if os.path.isdir(path): try: dhnio._dir_remove(path) printlog("UpdateCustomers " + path + " folder removed (%s)" % (remove_list[path])) except: printlog("UpdateCustomers ERROR removing " + path) continue if not os.access(path, os.W_OK): os.chmod(path, 0600) try: os.remove(path) printlog("UpdateCustomers " + path + " file removed (%s)" % (remove_list[path])) except: printlog("UpdateCustomers ERROR removing " + path)
def read_total_rating_dict(idurl): return dhnio._read_dict(rating_total_file(idurl))
def read_month_rating_dict(idurl, monthstr=None): if monthstr is None: monthstr = time.strftime('%m%y') return dhnio._read_dict(rating_month_file(idurl, monthstr))
def read_shedule_dict(): dhnio.Dprint(8, 'dhnupdate.read_shedule_dict') d = dhnio._read_dict(settings.UpdateSheduleFilename()) if d is None or not check_shedule_dict_correct(d): d = make_blank_shedule() return d
def SpaceTime(): printlog("SpaceTime " + str(time.strftime("%a, %d %b %Y %H:%M:%S +0000"))) space = dhnio._read_dict(CustomersSpaceFile()) if space is None: printlog("SpaceTime ERROR can not read file " + CustomersSpaceFile()) return customers_dir = getCustomersFilesDir() if not os.path.exists(customers_dir): printlog("SpaceTime ERROR customers folder not exist") return remove_list = {} for customer_filename in os.listdir(customers_dir): onecustdir = os.path.join(customers_dir, customer_filename) if not os.path.isdir(onecustdir): remove_list[onecustdir] = "is not a folder" continue idurl = FilenameUrl(customer_filename) if idurl is None: remove_list[onecustdir] = "wrong folder name" continue curspace = space.get(idurl, None) if curspace is None: continue try: maxspaceV = int(float(curspace) * 1024 * 1024) # in bytes except: remove_list[onecustdir] = "wrong space value" continue timedict = {} sizedict = {} def cb(path, subpath, name): if not os.access(path, os.R_OK | os.W_OK): return False if not os.path.isfile(path): return True if name in [BackupIndexFileName()]: return False stats = os.stat(path) timedict[path] = stats.st_ctime sizedict[path] = stats.st_size dhnio.traverse_dir_recursive(cb, onecustdir) currentV = 0 for path in sorted(timedict.keys(), key=lambda x: timedict[x], reverse=True): currentV += sizedict.get(path, 0) if currentV < maxspaceV: continue try: os.remove(path) printlog("SpaceTime " + path + " file removed (cur:%s, max: %s)" % (str(currentV), str(maxspaceV))) except: printlog("SpaceTime ERROR removing " + path) time.sleep(0.1) timedict.clear() sizedict.clear() for path in remove_list.keys(): if not os.path.exists(path): continue if os.path.isdir(path): try: dhnio._dir_remove(path) printlog("SpaceTime " + path + " dir removed (%s)" % (remove_list[path])) except: printlog("SpaceTime ERROR removing " + path) continue if not os.access(path, os.W_OK): os.chmod(path, 0600) try: os.remove(path) printlog("SpaceTime " + path + " file removed (%s)" % (remove_list[path])) except: printlog("SpaceTime ERROR removing " + path) del remove_list