-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArchiveOldOutput.py
45 lines (34 loc) · 1.29 KB
/
ArchiveOldOutput.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python3
import glob
import re
import os, time, sys
import shutil
from numpy import full
input = "/user/nivanden/ewkino/_FourTopAnalysis/Output/"
target = "/pnfs/iihe/cms/store/user/nivanden/AnalysisOutput/TTTT/"
days = 7
def getTimestamp(filename):
filenameSplit = filename.split("/")[-1]
date = ""
time = ""
for part in filenameSplit.split('_'):
if bool(re.match(r"[0-9]{4}-[0-9]{2}-[0-9]{2}", part)):
date = part
if bool(re.match(r"[0-9]{2}-[0-9]{2}", part)):
time = part
return date+"_"+time
if __name__ == "__main__":
# list all files older than 7 days, take their timestamps and move them to old outputs in a folder named by their timestamp
now = time.time()
timestampsChecked = []
for f in glob.glob(input+"*"):
timestamp = getTimestamp(f)
if timestamp in timestampsChecked: continue
timestampsChecked.append(timestamp)
if os.stat(f).st_mtime > now - days * 86400: continue
allStampedFiles = glob.glob(input+"*{}*".format(timestamp))
fullTarget = target + timestamp + "/"
if not os.path.exists( fullTarget ):
os.makedirs(fullTarget)
for file in allStampedFiles:
shutil.move(file, fullTarget)