Skip to content

Commit

Permalink
Fix whitespace errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragos GALALAE committed Nov 28, 2024
1 parent ff819c0 commit f09f6a3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/Config_Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -4535,7 +4535,7 @@ information on menu attributes available during template rendering.
# Reverse order of sorting.
# When sort_by_date is True, files will be sorted from new to old.
# When sort_by_date is False, files will be sorted in alphabetical
# descending order, else they will be sorted in alphabetical
# descending order, else they will be sorted in alphabetical
# ascending order.
#[menu some_list]
Expand Down
9 changes: 6 additions & 3 deletions klippy/extras/display/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,12 +665,14 @@ def __init__(self, manager, config, **kwargs):
self._sort_by_date = kwargs.get('sort_by_date', False)
super(MenuVSDList, self).__init__(manager, config, **kwargs)
try:
self._sort_reverse = config.getboolean('sort_reverse', self._sort_reverse)
self._sort_reverse = config.getboolean('sort_reverse',
self._sort_reverse)
except config.error:
logging.debug("Failed to get sort_reverse from config file")
pass
try:
self._sort_by_date = config.getboolean('sort_by_date', self._sort_by_date)
self._sort_by_date = config.getboolean('sort_by_date',
self._sort_by_date)
except config.error:
logging.debug("Failed to get sort_by_date from config file")
pass
Expand All @@ -679,7 +681,8 @@ def _populate(self):
super(MenuVSDList, self)._populate()
sdcard = self.manager.printer.lookup_object('virtual_sdcard', None)
if sdcard is not None:
files = sdcard.get_file_list(sortByDate=self._sort_by_date, sortReverse=self._sort_reverse)
files = sdcard.get_file_list(sortByDate=self._sort_by_date,
sortReverse=self._sort_reverse)
for fname, fsize in files:
self.insert_item(self.manager.menuitem_from(
'command', name=repr(fname), gcode='M23 /%s' % str(fname)))
Expand Down
22 changes: 16 additions & 6 deletions klippy/extras/virtual_sdcard.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def stats(self, eventtime):
if self.work_timer is None:
return False, ""
return True, "sd_pos=%d" % (self.file_position,)
def get_file_list(self, check_subdirs=False, sortByDate=False, sortReverse=False):
def get_file_list(self, check_subdirs=False,
sortByDate=False, sortReverse=False):
if check_subdirs:
flist = []
for root, dirs, files in os.walk(
Expand All @@ -79,7 +80,9 @@ def get_file_list(self, check_subdirs=False, sortByDate=False, sortReverse=False
flist.append((r_path, size))
if sortByDate:
if sortReverse:
return sorted(flist, key=lambda f: os.path.getmtime(f[0], reverse=True))
return sorted(flist,
key=lambda f: os.path.getmtime(f[0],
reverse=True))
return sorted(flist, key=lambda f: os.path.getmtime(f[0]))
if sortReverse:
return sorted(flist, key=lambda f: f[0].lower(), reverse=True)
Expand All @@ -90,17 +93,24 @@ def get_file_list(self, check_subdirs=False, sortByDate=False, sortReverse=False
filenames = os.listdir(self.sdcard_dirname)
if sortByDate:
if sortReverse:
return [(fname, os.path.getsize(os.path.join(dname, fname)))
for fname in sorted(filenames, key=lambda f: os.path.getmtime(os.path.join(dname, f)), reverse=True)
return [(fname,
os.path.getsize(os.path.join(dname, fname)))
for fname in sorted(filenames,
key=lambda f: os.path.getmtime(
os.path.join(dname, f)),
reverse=True)
if not fname.startswith('.')
and os.path.isfile((os.path.join(dname, fname)))]
return [(fname, os.path.getsize(os.path.join(dname, fname)))
for fname in sorted(filenames, key=lambda f: os.path.getmtime(os.path.join(dname, f)))
for fname in sorted(filenames,
key=lambda f: os.path.getmtime(
os.path.join(dname, f)))
if not fname.startswith('.')
and os.path.isfile((os.path.join(dname, fname)))]
if sortReverse:
return [(fname, os.path.getsize(os.path.join(dname, fname)))
for fname in sorted(filenames, key=str.lower, reverse=True)
for fname in sorted(filenames, key=str.lower,
reverse=True)
if not fname.startswith('.')
and os.path.isfile((os.path.join(dname, fname)))]
return [(fname, os.path.getsize(os.path.join(dname, fname)))
Expand Down

0 comments on commit f09f6a3

Please sign in to comment.