Skip to content

Commit

Permalink
Merge pull request #18 from maks-a/development
Browse files Browse the repository at this point in the history
v1.0.1
  • Loading branch information
maks-a authored Apr 16, 2017
2 parents 263b4b9 + 73e0c8d commit 179575d
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
38 changes: 38 additions & 0 deletions batterym/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"theme": "dark",
"smoothing": true,
"log_capacity_lines_limit": 1500,
"version": "1.0.0"
"version": "1.0.1"
}
2 changes: 2 additions & 0 deletions release-notes.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 5 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

0 comments on commit 179575d

Please sign in to comment.