-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathls_parser.py
More file actions
executable file
·46 lines (39 loc) · 1.49 KB
/
Copy pathls_parser.py
File metadata and controls
executable file
·46 lines (39 loc) · 1.49 KB
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
#!/usr/bin/python3
import datetime
import time
debian_unstable1 = ['-rw-r--r--','1','wooledg','wooledg','240','2007-12-07','11:44','file1']
debian_unstable2 = ['-rw-r--r--','1','wooledg','wooledg','240','2007-12-07','11:44','file1','with','spaces']
open_bsd1 = ['-rwxr-xr-x ','1','greg','greg','80','Nov','10','2006','file1']
open_bsd2 = ['-rw-r--r--','1','greg','greg','1020','Mar','15','13:57','file2']
open_bsd3 = ['-rw-r--r--','1','greg','greg','1020','Mar','15','13:57','file2','with','spaces']
open_bsd4 = ['-rw-r--r--','1','greg','greg','1020','Jan','1','2000','file3','with','spaces']
listings = [debian_unstable1,debian_unstable2,open_bsd1,open_bsd2,open_bsd3,open_bsd4]
# looking for first appearance of datetime like object in list
# if ls timestamp format is non-standard, just assume the ftp server admin
# has a heart and doesn't create directories with spaces in the name, and take [-1]
for lst in listings:
start = time.time()
fichier = ''
index = -1
not_parsed = True
while not_parsed:
if index < -len(lst):
# non-standard timestamp, take -1
fichier = lst[-1]
not_parsed = False
else:
try:
datetime.datetime.strptime(lst[index],'%H:%M')
fichier = lst[index+1:]
not_parsed = False
except:
try:
datetime.datetime.strptime(lst[index],'%Y')
fichier = lst[index+1:]
not_parsed = False
except:
index-=1
pass
end = time.time()
fil = ' '.join(fichier)
print("listing: %s, filename: %s, time to get: %s" % (lst,fil,str(end-start)))