sole/aafm — Issue #6: ls parsing 
Author: psinnott
Created: 2011-10-20 01:16:52+00:00
State: open

I came across 2 problems with the parsing.

The first is that my device produces a slightly different format.

e.g. :

---xrwxr-x 1 system sdcard_r 0 Aug 4 01:50 cineworld.trace

I'm not sure if this is due to the rom (miui) or something else.

The second is that the format of the date depends on the age of the file. I think this is quite normal for ls. Relatively new files have no year but older files include a year.

I have replaced the parse_device_list as below. Obviously the date handling isn't really much of an improvement but accurate display of the date is a far second to displaying the files (for me anyway :)

def parse_device_list(self, lines):
entries = {}
pattern = re.compile(r"^(?P[drwx\-]+) (?P\w+)\W+(?P[\w_]+)\W*(?P\d+)?\W+(?P\d{4}-\d{2}-\d{2} \d{2}:\d{2}) (?P.+)$")
pattern = re.compile(r"^(?P[drwx\-]+)\s+\d+\s+(?P\w+)\W+(?P[\w_]+)\W*(?P\d+)?\W+(?P\w{3}[ :0-9]+) (?P.+)$")

for line in lines:
line = line.rstrip()
match = pattern.match(line)

if match:
permissions = match.group('permissions')
owner = match.group('owner')
group = match.group('group')
fsize = match.group('size')
if fsize is None:
fsize = 0
filename = match.group('name')

try:
timestamp = time.mktime((time.strptime("2011 " + match.group('datetime'), "%Y %b %d %H:%M")))
except:
timestamp = 0

is_directory = permissions.startswith('d')

entries[filename] = {
'is_directory': is_directory,
'size': fsize,
'timestamp': timestamp,
'permissions': permissions,
'owner': owner,
'group': group
}

else:
print line, "wasn't matched, please report to the developer!"

return entries