Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mtime to files #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ncdu_s3/directory_walker.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def __init__(self, writer):
self.writer = writer
self.current_path = []

def process_item(self, path, size):
def process_item(self, path, size, last_modified):
key_filename = path.pop()

if self.current_path != path:
Expand Down Expand Up @@ -41,4 +41,4 @@ def process_item(self, path, size):
# directory entry ends with a '/' so the key_filename will be ''.
# in that case, omit it
if key_filename != '':
self.writer.file_entry(key_filename, size)
self.writer.file_entry(key_filename, size, last_modified)
4 changes: 2 additions & 2 deletions ncdu_s3/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def main(ctx, s3_url, output):
with NcduDataWriter(output, s3_url) as ncdu:
walker = DirectoryWalker(ncdu)

for path, size in s3_directory_generator:
walker.process_item(path, size)
for path, size, last_modified in s3_directory_generator:
walker.process_item(path, size, last_modified)

if __name__ == '__main__':
main()
6 changes: 4 additions & 2 deletions ncdu_s3/ncdu_data_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,17 @@ def dir_leave(self):
self.depth -= 1
self.output.write(']')

def file_entry(self, name, size):
def file_entry(self, name, size, last_modified):
"""
:type name: str
:type size: int
:type last_modified: datetime
"""

self.output.write(",\n")

json.dump({'name': name, 'dsize': size}, self.output)
unixtime = int(time.mktime(last_modified.timetuple()))
json.dump({'name': name, 'dsize': size, 'mtime': unixtime}, self.output)

def close(self):
for i in xrange(self.depth):
Expand Down
6 changes: 3 additions & 3 deletions ncdu_s3/s3_directory_generator.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from __future__ import absolute_import

import urlparse
from urlparse import urlparse
import boto3

class S3DirectoryGenerator(object):
def __init__(self, s3_url):
parsed_s3_url = urlparse.urlparse(s3_url)
parsed_s3_url = urlparse(s3_url)
if parsed_s3_url.scheme != 's3':
raise SyntaxError('Invalid S3 scheme')

Expand Down Expand Up @@ -43,4 +43,4 @@ def generator(self):
# we assume the S3 prefix is a directory that wasn't terminated with a '/'
path.pop(0)

yield (path, o.size)
yield (path, o.size, o.last_modified)