From c8e72805cf9def478b56c925f4afcc0ece1daac0 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Wed, 10 Jun 2020 05:51:12 -0700 Subject: [PATCH 1/3] fix error on empty directory --- jc/parsers/ls.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/jc/parsers/ls.py b/jc/parsers/ls.py index ce5e7fb6..e8c7a055 100644 --- a/jc/parsers/ls.py +++ b/jc/parsers/ls.py @@ -149,7 +149,7 @@ import jc.utils class info(): - version = '1.4' + version = '1.5' description = 'ls command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -226,20 +226,19 @@ def parse(data, raw=False, quiet=False): linedata = data.splitlines() - # Delete first line if it starts with 'total 1234' if linedata: + # Delete first line if it starts with 'total 1234' if re.match(r'total [0-9]+', linedata[0]): linedata.pop(0) - # Look for parent line if glob or -R is used - if not re.match(r'[-dclpsbDCMnP?]([-r][-w][-xsS]){2}([-r][-w][-xtT])[+]?', linedata[0]) \ - and linedata[0].endswith(':'): - parent = linedata.pop(0)[:-1] - # Pop following total line if it exists - if re.match(r'total [0-9]+', linedata[0]): - linedata.pop(0) + # Look for parent line if glob or -R is used + if not re.match(r'[-dclpsbDCMnP?]([-r][-w][-xsS]){2}([-r][-w][-xtT])[+]?', linedata[0]) \ + and linedata[0].endswith(':'): + parent = linedata.pop(0)[:-1] + # Pop following total line if it exists + if re.match(r'total [0-9]+', linedata[0]): + linedata.pop(0) - if linedata: # Check if -l was used to parse extra data if re.match(r'[-dclpsbDCMnP?]([-r][-w][-xsS]){2}([-r][-w][-xtT])[+]?', linedata[0]): for entry in linedata: From 3e052d18102e98a09cbba21866855691eaccc216 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Wed, 10 Jun 2020 05:53:20 -0700 Subject: [PATCH 2/3] version bump --- changelog.txt | 3 +++ jc/cli.py | 2 +- setup.py | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/changelog.txt b/changelog.txt index 4098b4d7..8102a17e 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,8 @@ jc changelog +20200610 v1.11.4 +- Update ls parser to fix error on parsing an empty directory + 20200609 v1.11.3 - Add local parser plugin feature (contributed by Dean Serenevy) diff --git a/jc/cli.py b/jc/cli.py index aed938fa..6f55ae40 100644 --- a/jc/cli.py +++ b/jc/cli.py @@ -21,7 +21,7 @@ import jc.appdirs as appdirs class info(): - version = '1.11.3' + version = '1.11.4' description = 'jc cli output JSON conversion tool' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' diff --git a/setup.py b/setup.py index 0ca52eae..0d83a07b 100755 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ with open('README.md', 'r') as f: setuptools.setup( name='jc', - version='1.11.3', + version='1.11.4', author='Kelly Brazil', author_email='kellyjonbrazil@gmail.com', description='Converts the output of popular command-line tools and file-types to JSON.', From 054422d8373e7b8def18ddabd447062cb9cc3137 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Wed, 10 Jun 2020 06:04:50 -0700 Subject: [PATCH 3/3] add test for empty directory --- tests/test_ls.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/test_ls.py b/tests/test_ls.py index 6a643a3d..9383c577 100644 --- a/tests/test_ls.py +++ b/tests/test_ls.py @@ -215,6 +215,12 @@ class MyTests(unittest.TestCase): with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/ls-lR-empty-folder.json'), 'r', encoding='utf-8') as f: self.osx_10_14_6_ls_lR_empty_folder_json = json.loads(f.read()) + def test_ls_empty_dir(self): + """ + Test plain 'ls' on an empty directory + """ + self.assertEqual(jc.parsers.ls.parse('', quiet=True), []) + def test_ls_centos_7_7(self): """ Test plain 'ls /' on Centos 7.7