-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdate_sort.py
executable file
·60 lines (45 loc) · 2.01 KB
/
date_sort.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python
import pandas as pd
import sys
from os.path import isdir
def usage():
print('''Organize directories according to last access date.
Usage:
# for all subdirectories in dir
./date_sort.py infoFile.csv outSummary.csv `ls -d /abs/path/of/parent/dir/*/`
# for all files in dir
./date_sort.py infoFile.csv outSummary.csv `ls -d /abs/path/of/parent/dir/*`''')
exit()
def main():
if len(sys.argv)==1 or sys.argv[1]=='-h' or sys.argv[1]=='--help':
usage()
infoFile= sys.argv[1]
outSummary = sys.argv[2]
dirs = sys.argv[3:]
# sanity check
if not (infoFile.endswith('.csv') and outSummary.endswith('.csv')):
print('infoFile and outSummary must be .csv files')
usage()
if len(dirs)<2:
print('provide a list of directories, not the parent directory only, may be you forgot an */ at the end?')
usage()
# checking for directories will fail for remote servers
# dirs= [dir for dir in dirs if isdir(dir)]
df= pd.read_csv(infoFile)
df_parent= pd.DataFrame(columns= ['Directory', 'SizeG', 'Last Modified'])
for j,dir in enumerate(dirs):
for i,name in enumerate(df[' Directory']):
if dir==name+'/':
df_parent.loc[j]= [dir,df[' SizeG'][i],df[' Last Modified'][i]]
df_parent.sort_values(by=['Last Modified'], ascending=False, inplace=True)
df_parent.set_index('Directory', inplace=True)
df_parent.to_csv(outSummary)
print(df_parent)
if __name__=='__main__':
main()
'''
./date_sort.py _data/logdirsizes/rfanfs_pnl-zorro-dirsizes-3-20190506.csv Collaborators.csv `ls -d /rfanfs/pnl-zorro/Collaborators/*/`
./date_sort.py _data/logdirsizes/rfanfs_pnl-zorro-dirsizes-3-20190506.csv projects.csv `ls -d /rfanfs/pnl-zorro/projects/*/`
./date_sort.py _data/logdirsizes/rfanfs_pnl-zorro-dirsizes-3-20190506.csv home.csv `ls -d /rfanfs/pnl-zorro/home/*/`
./date_sort.py _data/logdirsizes/data_pnl-dirsizes-3-20190615.csv data_pnl.csv `ssh eris1n2.research.partners.org "ls -d /data/pnl/*/"`
'''