Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

ls parsing #6

Open
tslocum opened this issue Aug 24, 2014 · 0 comments
Open

ls parsing #6

tslocum opened this issue Aug 24, 2014 · 0 comments

Comments

@tslocum
Copy link
Owner

tslocum commented Aug 24, 2014

Issue by psinnott
Thursday Oct 20, 2011 at 01:16 GMT
Originally opened as sole#6


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<permissions>[drwx\-]+) (?P<owner>\w+)\W+(?P<group>[\w_]+)\W*(?P<size>\d+)?\W+(?P<datetime>\d{4}-\d{2}-\d{2} \d{2}:\d{2}) (?P<name>.+)$")
    pattern = re.compile(r"^(?P<permissions>[drwx\-]+)\s+\d+\s+(?P<owner>\w+)\W+(?P<group>[\w_]+)\W*(?P<size>\d+)?\W+(?P<datetime>\w{3}[ :0-9]+) (?P<name>.+)$")

    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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant