Skip to content

Commit 2176cb4

Browse files
Initial commit
0 parents  commit 2176cb4

File tree

4 files changed

+425
-0
lines changed

4 files changed

+425
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist
2+
build
3+
__pycache__
4+
__main__.spec

__main__.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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("\nFiles 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("\nFiles 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("\nCommon 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()

configReader.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import json
2+
import os
3+
import os.path as path
4+
5+
6+
class ConfigReader:
7+
def __init__(self):
8+
self.config_path = path.expanduser("~/.kst-git/config.json")
9+
self.config = None
10+
if os.path.exists(self.config_path):
11+
with open(self.config_path, "r") as f:
12+
self.config = json.load(f)
13+
else:
14+
self.config = {
15+
"username": "",
16+
"password": "",
17+
"server": "",
18+
"firstConfig": False
19+
}
20+
with open(self.config_path, "w") as f:
21+
json.dump(self.config, f)
22+
23+
self.configVersion = "1.0.0"
24+
def getConfig(self):
25+
return self.config
26+
27+
def getConfigVersion(self):
28+
return self.configVersion
29+
30+
def saveConfig(self):
31+
with open(self.config_path, "w") as f:
32+
json.dump(self.config, f)
33+
34+
def updateConfig(self, config):
35+
self.config = config

0 commit comments

Comments
 (0)