diff options
author | joelostblom <joel.ostblom@gmail.com> | 2018-12-18 01:26:20 +0100 |
---|---|---|
committer | joelostblom <joel.ostblom@gmail.com> | 2018-12-18 01:26:20 +0100 |
commit | 6f3dd655f72ac260197a680e6f66245c7d2902ff (patch) | |
tree | 260ff0b005d43386deaa01d9e660efee39b2a486 /ranger | |
parent | bae44ae3c7440c00acf65ba4c26a0fd2a0f78c3a (diff) | |
download | ranger-6f3dd655f72ac260197a680e6f66245c7d2902ff.tar.gz |
Add new linemode classes
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/container/fsobject.py | 4 | ||||
-rw-r--r-- | ranger/core/linemode.py | 43 |
2 files changed, 46 insertions, 1 deletions
diff --git a/ranger/container/fsobject.py b/ranger/container/fsobject.py index 37151ecf..33633bcf 100644 --- a/ranger/container/fsobject.py +++ b/ranger/container/fsobject.py @@ -13,6 +13,7 @@ from time import time from ranger.core.linemode import ( DEFAULT_LINEMODE, DefaultLinemode, TitleLinemode, PermissionsLinemode, FileInfoLinemode, MtimeLinemode, SizeMtimeLinemode, + HumanMtimeLinemode, SizeHumanMtimeLinemode ) from ranger.core.shared import FileManagerAware, SettingsAware from ranger.ext.shell_escape import shell_escape @@ -91,7 +92,8 @@ class FileSystemObject( # pylint: disable=too-many-instance-attributes,too-many linemode_dict = dict( (linemode.name, linemode()) for linemode in [DefaultLinemode, TitleLinemode, PermissionsLinemode, FileInfoLinemode, - MtimeLinemode, SizeMtimeLinemode] + MtimeLinemode, SizeMtimeLinemode, HumanMtimeLinemode, + SizeHumanMtimeLinemode] ) def __init__(self, path, preload=None, path_is_abs=False, basename_is_rel_to=None): diff --git a/ranger/core/linemode.py b/ranger/core/linemode.py index 3a29b552..b98d50e2 100644 --- a/ranger/core/linemode.py +++ b/ranger/core/linemode.py @@ -131,3 +131,46 @@ class SizeMtimeLinemode(LinemodeBase): return '?' return "%s %s" % (human_readable(fobj.size), datetime.fromtimestamp(fobj.stat.st_mtime).strftime("%Y-%m-%d %H:%M")) + + +class HumanMtimeLinemode(LinemodeBase): + name = "humanmtime" + + def filetitle(self, fobj, metadata): + return fobj.relative_path + + def infostring(self, fobj, metadata): + if fobj.stat is None: + return '?' + file_date = datetime.fromtimestamp(fobj.stat.st_mtime) + time_diff = datetime.now().date() - file_date.date() + if time_diff.days > 364: + return file_date.strftime("%-d %b %Y") + elif time_diff.days > 6: + return file_date.strftime("%-d %b") + elif time_diff.days >= 1: + return file_date.strftime("%a") + else: + return file_date.strftime("%H:%M") + + +class SizeHumanMtimeLinemode(LinemodeBase): + name = "sizehumanmtime" + + def filetitle(self, fobj, metadata): + return fobj.relative_path + + def infostring(self, fobj, metadata): + if fobj.stat is None: + return '?' + size = human_readable(fobj.size) + file_date = datetime.fromtimestamp(fobj.stat.st_mtime) + time_diff = datetime.now().date() - file_date.date() + if time_diff.days > 364: + return "%s %11s" % (size, file_date.strftime("%-d %b %Y")) + if time_diff.days > 6: + return "%s %11s" % (size, file_date.strftime("%-d %b")) + elif time_diff.days >= 1: + return "%s %11s" % (size, file_date.strftime("%a")) + else: + return "%s %11s" % (size, file_date.strftime("%H:%M")) |