-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwit.py
More file actions
67 lines (61 loc) · 2.35 KB
/
wit.py
File metadata and controls
67 lines (61 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os
import click
from file_handler import FileHandler
from pathlib import Path
from logging_handler import logger
from wit_exception import WitException
class Wit:
base_path = None
working_directory = None
@staticmethod
def validate_is_wit_repo():
path = os.getcwd()
path = Path(path).resolve()
root = Path("\\").resolve()
FileHandler.working_directory = str(path).split("\\")[-1]
while path != root:
if FileHandler.is_wit_exist_in_path(path):
Wit.base_path = path
return True
path = path.parent
return False
@staticmethod
def init():
if Wit.validate_is_wit_repo():
click.secho('Wit already exist', fg="red", bold=True)
else:
FileHandler.create_dir(".wit")
FileHandler.create_dir(".wit/images")
FileHandler.create_dir(".wit/staging_area")
logger.info(f"init wit in {os.getcwd()}")
@staticmethod
def move_to_staging(full_path):
target_path = os.path.join(Wit.base_path, ".wit\\staging_area")
# A list containing the folder names in the path of the item to be added
dirs = full_path[len(str(Wit.base_path))::]
dirs = dirs.split("\\")
for item in dirs[:-1]:
target_path = os.path.join(target_path, item)
# if the folder (item) not exists we will create the dir
if not os.path.exists(target_path):
os.mkdir(target_path)
# When we have reached the lowest layer,
# only then will we copy the requested files to the path we chained
FileHandler.copy_items(full_path, target_path)
@staticmethod
def add(arg):
if Wit.validate_is_wit_repo():
try:
full_path = FileHandler.get_source_path(arg)
Wit.move_to_staging(full_path)
logger.info(f"{arg} was successfully added to staging_area")
except WitException:
click.secho('file is not exist', fg="red", bold=True)
logger.error("Attempt to add a file that does not exist")
else:
click.secho('Wit is not exist', fg="red", bold=True)
logger.error("Try to do Wit command without init wit")
@staticmethod
def commit(msg):
if Wit.validate_is_wit_repo():
pass