1+ from webdav3 .client import Client
2+ from os import path
3+ import os
4+ import configReader
5+ import getpass
6+ import click
7+ import json
8+ import directory_diff
9+ import shutil
10+
11+ os .makedirs (path .expanduser ("~/.kst-git" ), exist_ok = True )
12+
13+ config = configReader .ConfigReader ()
14+
15+ if config .getConfig ()["firstConfig" ] == False :
16+ server = input ("Server URL: " )
17+ username = input ("Username: " )
18+ password = getpass .getpass ("Password: " )
19+ config .updateConfig ({"username" : username , "password" : password , "server" : server , "firstConfig" : True })
20+ config .saveConfig ()
21+
22+ options = {
23+ 'webdav_hostname' : config .getConfig ()["server" ],
24+ 'webdav_login' : config .getConfig ()["username" ],
25+ 'webdav_password' : config .getConfig ()["password" ]
26+ }
27+ client = Client (options )
28+
29+ @click .group ()
30+ def cli ():
31+ pass
32+
33+ @cli .command ()
34+ def init ():
35+ cwd = os .getcwd ()
36+ print (cwd )
37+ os .makedirs (path .join (cwd , ".kst-git" ), exist_ok = True )
38+ p = input ("Webdav Path: " )
39+ c = True if input ("Create new Path (y/n): " ) == "y" else False
40+ if c :
41+ project_name = input ("Project Name: " )
42+ if not client .is_dir (path .join (p , project_name )):
43+ client .mkdir (path .join (p , project_name ))
44+ p = path .join (p , project_name )
45+ with open (path .join (cwd , ".kst-git/config.json" ), "w" ) as f :
46+ standard = {
47+ "changes" : [],
48+ "path" : p ,
49+ }
50+ json .dump (standard , f )
51+ click .echo ("Created empty repo" )
52+ @cli .command ()
53+ def push ():
54+ cwd = os .getcwd ()
55+ click .echo ("Push command not implemented yet." )
56+
57+ @cli .command ()
58+ def diff ():
59+ cwd = os .getcwd ()
60+ with open (path .join (cwd , ".kst-git/config.json" ), "r" ) as f :
61+ config = json .load (f )
62+ if path .exists (path .join (cwd , ".kst-git" , "copy" )):
63+ shutil .rmtree (path .join (cwd , ".kst-git" , "copy" ), ignore_errors = True )
64+ # pull from server
65+ click .echo ("Downloading remote state..." )
66+ client .download_directory (config ["path" ], path .join (cwd , ".kst-git" , "copy" ))
67+ click .echo ("Comparing directories..." )
68+ # Example using basic comparison:
69+ basic_diff = directory_diff .compare_directories_basic (cwd , path .join (cwd , ".kst-git" , "copy" ), [".kst-git" , ".kst-git/copy" ])
70+ if basic_diff :
71+ only_in_dir1 , only_in_dir2 , common = basic_diff
72+ if only_in_dir1 :
73+ click .echo ("\n Files only in local directory (New files):" )
74+ for item in only_in_dir1 :
75+ click .echo (f" + { item } " )
76+ if only_in_dir2 :
77+ click .echo ("\n Files only in remote directory (Potentially deleted locally or new remote files):" )
78+ for item in only_in_dir2 :
79+ click .echo (f" - { item } " )
80+ if common :
81+ click .echo ("\n Common files:" )
82+ # For a basic diff, we are not checking content differences in common files.
83+ # If you want to check content differences, you would need a more detailed comparison.
84+ click .echo (" (Content comparison for common files is not implemented in this basic diff.)" )
85+ else :
86+ click .echo ("No differences found between local and remote directories." )
87+ click .echo ("Diff complete." )
88+
89+
90+ if __name__ == '__main__' :
91+ cli ()
0 commit comments