generated from maximegris/angular-electron
-
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from webosbrew/feature/file-ls-helper
Feature/file ls helper
- Loading branch information
Showing
17 changed files
with
148 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# coding: utf-8 -*- | ||
import os | ||
import stat | ||
import sys | ||
from os import path | ||
from sys import stdout | ||
|
||
|
||
class B: | ||
def __init__(self, value): | ||
self.value = value | ||
|
||
def __repr__(self): | ||
return 'true' if self.value else 'false' | ||
|
||
|
||
class S(): | ||
def __init__(self, value): | ||
self.value = value | ||
|
||
def __repr__(self): | ||
escaped = "".join(map(lambda i: S.escape_ch(self.value[i]), range(0, len(self.value)))) | ||
return '"' + escaped + '"' | ||
|
||
@staticmethod | ||
def escape_ch(ch): | ||
# type: (str) -> str | ||
if ch in '\x08\x09\x0a\x0c\x0d\x22\x2f\x5c': | ||
return '\\' + ch | ||
else: | ||
return ch | ||
|
||
|
||
def file_item(parent, name): | ||
# type: (str, str) -> dict | ||
abspath = path.join(parent, name) | ||
lstat = os.lstat(abspath) | ||
|
||
item = { | ||
S('name'): S(name), | ||
S('abspath'): S(abspath) | ||
} | ||
if stat.S_ISLNK(lstat.st_mode): | ||
target = os.readlink(abspath) | ||
broken = False | ||
try: | ||
lstat = os.stat(abspath) | ||
except OSError: | ||
broken = True | ||
item[S('link')] = { | ||
S('target'): S(target), | ||
S('broken'): B(broken) | ||
} | ||
item[S('stat')] = { | ||
S('mode'): lstat.st_mode, | ||
S('uid'): lstat.st_uid, | ||
S('gid'): lstat.st_gid, | ||
S('size'): int(lstat.st_size), | ||
S('atime'): lstat.st_atime, | ||
S('mtime'): lstat.st_mtime, | ||
S('ctime'): lstat.st_ctime, | ||
} | ||
return item | ||
|
||
|
||
if __name__ == '__main__': | ||
d = sys.argv[1] | ||
entries = list(map(lambda x: file_item(d, x), os.listdir(d))) | ||
stdout.write(str(entries)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.