Delete *ancient* cron/cleanup_datsets.py content, but leave a nice deprecation warning and pointer for those who might actually be using it in cron jobs.

This commit is contained in:
Dannon Baker
2014-12-17 11:00:29 -05:00
parent 0a1a871fd0
commit 00f80427fe
+4 -59
View File
@@ -1,63 +1,8 @@
#!/usr/bin/env python
#This script removes deleted dataset files.
#Takes 3 arguments:
# 1: database directory to clean
# 2: postgres database name
# 3 (optional): number of days to allow as a buffer, defaults to 2
#python cleanup_datasets.py /home/universe/server-home/wsgi-postgres/database/files/ galaxy_test 2
import sys
import sys, os, tempfile, time
try:
database_dir = sys.argv[1]
database_name = sys.argv[2]
num_days = 2
try:
num_days = int(sys.argv[3])
except:
print "Using Default of 2 days buffer on delete"
except:
print "Usage: python %s path_to_files:/home/universe/server-home/wsgi-postgres/database/files/ database_name:galaxy_test [num_days_buffer:2]" % sys.argv[0]
sys.exit(0)
id_file = tempfile.NamedTemporaryFile('w')
id_filename = id_file.name
id_file.close()
ids = []
print ("This script has been deprecated, replaced by the set of scripts in <galaxy_distribution>/scripts/cleanup_datsets/."
"See https://wiki.galaxyproject.org/Admin/Config/Performance/Purge%20Histories%20and%20Datasets for more information.")
command = "psql -d %s -c \"select id from dataset;\" -o %s" % (database_name, id_filename)
print "Getting IDs:", command
id_file = os.popen(command)
id_file.close()
for line in open(id_filename,'r'):
try:
ids.append(int(line.strip()))
except:
print line.strip(),"is not a valid id, skipping."
os.unlink(id_filename)
if len(ids) < 1:
print "Less than 1 IDs have been found! Deleting proccess has been canceled."
sys.exit(0)
print "-----%i IDs Retrieved -----" % len(ids)
print "----- Checking database directory for deleted ids: %s -----" % database_dir
file_size = 0
num_delete = 0
for result in os.walk(database_dir):
this_base_dir,sub_dirs,files = result
for file in files:
if file.startswith("dataset_") and file.endswith(".dat"):
id = int(file.replace("dataset_","").replace(".dat",""))
file_name = os.path.join(this_base_dir,file)
if id not in ids:
file_time = os.path.getctime(file_name)
if time.time() > file_time + (num_days*60*60*24): #num_days (default=2) days buffer room
num_delete += 1
size = os.path.getsize(file_name)
file_size += size
os.unlink(file_name)
print file_size, "bytes"
print float(file_size) / 1024, "kilobytes"
print float(file_size) / 1024 / 1024, "Megabytes"
print float(file_size) / 1024 / 1024 / 1024, "Gigabytes"
print "%i files deleted" % num_delete
sys.exit(0)
sys.exit(1)