mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-08-10 22:41:51 +02:00
fix for crontab files with only shortcut entries
This commit is contained in:
@@ -174,7 +174,7 @@ import jc.parsers.universal
|
|||||||
|
|
||||||
class info():
|
class info():
|
||||||
"""Provides parser metadata (version, author, etc.)"""
|
"""Provides parser metadata (version, author, etc.)"""
|
||||||
version = '1.6'
|
version = '1.7'
|
||||||
description = '`crontab` command and file parser'
|
description = '`crontab` command and file parser'
|
||||||
author = 'Kelly Brazil'
|
author = 'Kelly Brazil'
|
||||||
author_email = 'kellyjonbrazil@gmail.com'
|
author_email = 'kellyjonbrazil@gmail.com'
|
||||||
@@ -273,6 +273,9 @@ def parse(data, raw=False, quiet=False):
|
|||||||
raw_output['schedule'] = cron_list
|
raw_output['schedule'] = cron_list
|
||||||
|
|
||||||
# Add shortcut entries back in
|
# Add shortcut entries back in
|
||||||
|
if 'schedule' not in raw_output:
|
||||||
|
raw_output['schedule'] = []
|
||||||
|
|
||||||
for item in shortcut_list:
|
for item in shortcut_list:
|
||||||
raw_output['schedule'].append(item)
|
raw_output['schedule'].append(item)
|
||||||
|
|
||||||
|
@@ -171,7 +171,7 @@ import jc.parsers.universal
|
|||||||
|
|
||||||
class info():
|
class info():
|
||||||
"""Provides parser metadata (version, author, etc.)"""
|
"""Provides parser metadata (version, author, etc.)"""
|
||||||
version = '1.7'
|
version = '1.8'
|
||||||
description = '`crontab` file parser with user support'
|
description = '`crontab` file parser with user support'
|
||||||
author = 'Kelly Brazil'
|
author = 'Kelly Brazil'
|
||||||
author_email = 'kellyjonbrazil@gmail.com'
|
author_email = 'kellyjonbrazil@gmail.com'
|
||||||
@@ -271,6 +271,9 @@ def parse(data, raw=False, quiet=False):
|
|||||||
raw_output['schedule'] = cron_list
|
raw_output['schedule'] = cron_list
|
||||||
|
|
||||||
# Add shortcut entries back in
|
# Add shortcut entries back in
|
||||||
|
if 'schedule' not in raw_output:
|
||||||
|
raw_output['schedule'] = []
|
||||||
|
|
||||||
for item in shortcut_list:
|
for item in shortcut_list:
|
||||||
raw_output['schedule'].append(item)
|
raw_output['schedule'].append(item)
|
||||||
|
|
||||||
|
1
tests/fixtures/generic/crontab-no-normal-entries.json
vendored
Normal file
1
tests/fixtures/generic/crontab-no-normal-entries.json
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"variables":[],"schedule":[{"occurrence":"daily","command":"/bin/sh do_the_thing"}]}
|
2
tests/fixtures/generic/crontab-no-normal-entries.out
vendored
Normal file
2
tests/fixtures/generic/crontab-no-normal-entries.out
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
#this is a test for the jc module
|
||||||
|
@daily /bin/sh do_the_thing
|
1
tests/fixtures/generic/crontab-u-no-normal-entries.json
vendored
Normal file
1
tests/fixtures/generic/crontab-u-no-normal-entries.json
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"variables":[],"schedule":[{"occurrence":"daily","user":"root","command":"/bin/sh do_the_thing"}]}
|
2
tests/fixtures/generic/crontab-u-no-normal-entries.out
vendored
Normal file
2
tests/fixtures/generic/crontab-u-no-normal-entries.out
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
#this is a test for the jc module
|
||||||
|
@daily root /bin/sh do_the_thing
|
@@ -12,10 +12,16 @@ class MyTests(unittest.TestCase):
|
|||||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/crontab.out'), 'r', encoding='utf-8') as f:
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/crontab.out'), 'r', encoding='utf-8') as f:
|
||||||
centos_7_7_crontab = f.read()
|
centos_7_7_crontab = f.read()
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/crontab-no-normal-entries.out'), 'r', encoding='utf-8') as f:
|
||||||
|
generic_crontab_no_normal_entries = f.read()
|
||||||
|
|
||||||
# output
|
# output
|
||||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/crontab.json'), 'r', encoding='utf-8') as f:
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/crontab.json'), 'r', encoding='utf-8') as f:
|
||||||
centos_7_7_crontab_json = json.loads(f.read())
|
centos_7_7_crontab_json = json.loads(f.read())
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/crontab-no-normal-entries.json'), 'r', encoding='utf-8') as f:
|
||||||
|
generic_crontab_no_normal_entries_json = json.loads(f.read())
|
||||||
|
|
||||||
|
|
||||||
def test_crontab_nodata(self):
|
def test_crontab_nodata(self):
|
||||||
"""
|
"""
|
||||||
@@ -29,6 +35,12 @@ class MyTests(unittest.TestCase):
|
|||||||
"""
|
"""
|
||||||
self.assertEqual(jc.parsers.crontab.parse(self.centos_7_7_crontab, quiet=True), self.centos_7_7_crontab_json)
|
self.assertEqual(jc.parsers.crontab.parse(self.centos_7_7_crontab, quiet=True), self.centos_7_7_crontab_json)
|
||||||
|
|
||||||
|
def test_crontab_no_normal_entries(self):
|
||||||
|
"""
|
||||||
|
Test 'crontab' with no normal entries - only shortcuts
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.crontab.parse(self.generic_crontab_no_normal_entries, quiet=True), self.generic_crontab_no_normal_entries_json)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@@ -18,6 +18,9 @@ class MyTests(unittest.TestCase):
|
|||||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/debian10/crontab-u.out'), 'r', encoding='utf-8') as f:
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/debian10/crontab-u.out'), 'r', encoding='utf-8') as f:
|
||||||
debian10_crontab_u = f.read()
|
debian10_crontab_u = f.read()
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/crontab-u-no-normal-entries.out'), 'r', encoding='utf-8') as f:
|
||||||
|
generic_crontab_u_no_normal_entries = f.read()
|
||||||
|
|
||||||
# output
|
# output
|
||||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/crontab-u.json'), 'r', encoding='utf-8') as f:
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/crontab-u.json'), 'r', encoding='utf-8') as f:
|
||||||
ubuntu_18_4_crontab_u_json = json.loads(f.read())
|
ubuntu_18_4_crontab_u_json = json.loads(f.read())
|
||||||
@@ -28,6 +31,9 @@ class MyTests(unittest.TestCase):
|
|||||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/debian10/crontab-u.json'), 'r', encoding='utf-8') as f:
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/debian10/crontab-u.json'), 'r', encoding='utf-8') as f:
|
||||||
debian10_crontab_u_json = json.loads(f.read())
|
debian10_crontab_u_json = json.loads(f.read())
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/crontab-u-no-normal-entries.json'), 'r', encoding='utf-8') as f:
|
||||||
|
generic_crontab_u_no_normal_entries_json = json.loads(f.read())
|
||||||
|
|
||||||
|
|
||||||
def test_crontab_u_nodata(self):
|
def test_crontab_u_nodata(self):
|
||||||
"""
|
"""
|
||||||
@@ -53,6 +59,11 @@ class MyTests(unittest.TestCase):
|
|||||||
"""
|
"""
|
||||||
self.assertEqual(jc.parsers.crontab_u.parse(self.debian10_crontab_u, quiet=True), self.debian10_crontab_u_json)
|
self.assertEqual(jc.parsers.crontab_u.parse(self.debian10_crontab_u, quiet=True), self.debian10_crontab_u_json)
|
||||||
|
|
||||||
|
def test_crontab_u_no_normal_entries(self):
|
||||||
|
"""
|
||||||
|
Test 'crontab' with no normal entries - only shortcut entries (has a user field)
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.crontab_u.parse(self.generic_crontab_u_no_normal_entries, quiet=True), self.generic_crontab_u_no_normal_entries_json)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Reference in New Issue
Block a user