Skip to content

Commit f5e9ef7

Browse files
author
melon
committed
init commit
0 parents  commit f5e9ef7

19 files changed

+1223
-0
lines changed

.idea/misc.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/siv.iml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 887 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

constants.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
monitor_name = 'Monitor directory'
2+
verification_name = 'Verification file'
3+
report_name = 'Report file'
4+
group_name = 'linux_group_permission'
5+
mode_name = 'linux_mode_permission'
6+
7+
FILE_KEY = 'files'
8+
DIR_KEY = 'dir'
9+
10+
# color constants
11+
COLOR_SUCCESS = 'green'
12+
COLOR_ERROR = 'red'
13+
COLOR_WARNING = 'yellow'
14+
COLOR_INFO = 'blue'
15+
16+
# stat constants
17+
STAT_SIZE = 'size'
18+
STAT_USER = 'user'
19+
STAT_GROUP = 'group'
20+
STAT_MODE = 'mode'
21+
STAT_MOD_DATE = 'mod_date'
22+
STAT_DIGEST = 'digest'

constants.pyc

762 Bytes
Binary file not shown.

hash.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import hashlib
2+
3+
from termcolor import cprint
4+
5+
from constants import COLOR_ERROR
6+
7+
8+
def is_hash_supported(hash_func):
9+
if hash_func.lower() == 'sha1' or hash_func.lower() == 'sha-1':
10+
return True
11+
cprint('Given hash function is not supported', COLOR_ERROR)
12+
return False
13+
14+
15+
def hashing(file_path):
16+
block_size = 65536
17+
hash_obj = hashlib.sha1()
18+
with open(file_path, 'rb') as f:
19+
buf = f.read(block_size)
20+
while len(buf) > 0:
21+
hash_obj.update(buf)
22+
buf = f.read(block_size)
23+
return hash_obj.hexdigest()

hash.pyc

982 Bytes
Binary file not shown.

helper.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import grp
2+
import os
3+
import pwd
4+
from datetime import datetime
5+
6+
from termcolor import cprint
7+
8+
from constants import *
9+
10+
11+
def check_dir_exists(directory):
12+
return os.path.isdir(directory)
13+
14+
15+
def check_file_exists(file_path):
16+
return os.path.isfile(file_path)
17+
18+
19+
def file_dir(file_path):
20+
return os.path.dirname(file_path)
21+
22+
23+
def is_asset_exists(path, is_dir, file_name):
24+
check = check_dir_exists(path) if is_dir else check_file_exists(path)
25+
if check:
26+
cprint(file_name + ' exist', COLOR_SUCCESS)
27+
return True
28+
cprint(file_name + ' does not exist', COLOR_ERROR)
29+
return False
30+
31+
32+
def is_outside_monitor(monitor, file_path, file_name):
33+
if file_dir(file_path) in monitor:
34+
cprint(file_name + ' is inside monitor', COLOR_ERROR)
35+
return False
36+
cprint(file_name + ' is outside monitor', COLOR_SUCCESS)
37+
return True
38+
39+
40+
def file_check(file_path, file_name, is_initialization):
41+
is_asset_exist = is_asset_exists(file_path, False, file_name)
42+
if is_asset_exist and is_initialization:
43+
while True:
44+
cprint('Do you want to override ' + file_name + '? ', COLOR_ERROR)
45+
input_data = str(raw_input())
46+
if input_data == 'no':
47+
exit()
48+
elif input_data == 'yes':
49+
break
50+
else:
51+
cprint('Please enter yes or no', COLOR_INFO)
52+
elif not is_initialization and not is_asset_exist:
53+
exit()
54+
return True
55+
56+
57+
def collect_info(path):
58+
stat_info = os.stat(path)
59+
info = {
60+
STAT_USER: pwd.getpwuid(stat_info.st_uid)[0],
61+
STAT_GROUP: grp.getgrgid(stat_info.st_gid)[0],
62+
STAT_MODE: oct(stat_info.st_mode & 07777),
63+
STAT_MOD_DATE: datetime.fromtimestamp(stat_info.st_mtime).date().__str__()
64+
}
65+
66+
if not os.path.isdir(path):
67+
info[STAT_SIZE] = stat_info.st_size
68+
from hash import hashing
69+
info[STAT_DIGEST] = hashing(path)
70+
71+
return info

helper.pyc

2.73 KB
Binary file not shown.

0 commit comments

Comments
 (0)