diff --git a/batterym/misc.py b/batterym/misc.py index 98c3320..43b273f 100644 --- a/batterym/misc.py +++ b/batterym/misc.py @@ -56,6 +56,24 @@ def remove_front_lines_if_too_many(fname, lines_threshold=None): write_lines_to_file(lines, fname) +def get_mod(path): + return os.stat(path).st_mode & 0777 + + +def change_mod(path, mod): + print 'changing mode of {0} to {1}'.format(path, oct(mod)) + os.chmod(path, mod) + if mod != get_mod(path): + raise ValueError + + +def change_mod_files(folder, mod): + for fname in os.listdir(folder): + path = os.path.join(folder, fname) + if os.path.isfile(path): + change_mod(path, mod) + + class MyTest(unittest.TestCase): def setUp(self): @@ -67,14 +85,34 @@ def tearDown(self): if os.path.isfile(self.fname): os.remove(self.fname) + def test_chmod(self): + src = 0775 + change_mod(self.fname, src) + result = get_mod(self.fname) + self.assertEqual(src, result) + def test_write_read(self): src = [] + expected = '\n' write_lines_to_file(src, self.fname) + result = read_from_file(self.fname) + self.assertEqual(result, expected) result = read_lines_from_file(self.fname) self.assertEqual(src, result) src = ['abc'] + expected = 'abc\n' write_lines_to_file(src, self.fname) + result = read_from_file(self.fname) + self.assertEqual(result, expected) + result = read_lines_from_file(self.fname) + self.assertEqual(src, result) + + src = ['1', '2', '3'] + expected = '1\n2\n3\n' + write_lines_to_file(src, self.fname) + result = read_from_file(self.fname) + self.assertEqual(result, expected) result = read_lines_from_file(self.fname) self.assertEqual(src, result) diff --git a/config/config.json b/config/config.json index f90d907..4d5f38f 100644 --- a/config/config.json +++ b/config/config.json @@ -3,5 +3,5 @@ "theme": "dark", "smoothing": true, "log_capacity_lines_limit": 1500, - "version": "1.0.0" + "version": "1.0.1" } \ No newline at end of file diff --git a/release-notes.md b/release-notes.md index cc6b7ad..dca29b0 100644 --- a/release-notes.md +++ b/release-notes.md @@ -1,5 +1,7 @@ Release Notes ------------- +#### v1.0.1 (2017-04-16) +- Fix #16: File permission issue #### v1.0.0 (2017-04-14) - Preserve history after reinstall diff --git a/setup.py b/setup.py index b1ab470..ab8b0a9 100644 --- a/setup.py +++ b/setup.py @@ -2,6 +2,7 @@ import os from distutils.core import setup from batterym.misc import append_to_file +from batterym.misc import change_mod_files from batterym.misc import create_missing_dirs from batterym.paths import SHARE_APP_DIR @@ -51,6 +52,7 @@ def chmod(folder, mod): append_to_file('', LOG_BATTERY_FILE) append_to_file('', LOG_BATTERY_ALL_FILE) -chmod(CONFIG_DIR, 0777) -chmod(LOGS_DIR, 0777) -chmod(IMAGE_DIR, 0777) +mod = 0775 +change_mod_files(CONFIG_DIR, mod) +change_mod_files(LOGS_DIR, mod) +change_mod_files(IMAGE_DIR, mod)