-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpush.py
46 lines (36 loc) · 1.36 KB
/
push.py
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
import sys
import os
import subprocess
import config
import datetime
class RSyncPush:
def sync_file_command(self, file_path):
remote_path_base = config.remote_server_note_path
just_file_name = os.path.basename(file_path)
return ["rsync", file_path, remote_path_base + just_file_name]
def _perform(self, command):
subprocess.run(command)
def sync_file(self, file_path):
command = self.sync_file_command(file_path)
self._perform(command)
class GitPush:
def sync_file(self, file_path):
curdir = os.path.dirname(file_path)
subprocess.call(["cd", curdir])
if os.path.isdir(os.path.join(os.getcwd(), ".git")):
subprocess.call(["git", "add", file_path])
curdatetime = str(datetime.datetime.now())
filename = os.path.basename(file_path)
commit_msg = "SyncOnSave @" + curdatetime + " @ " + filename
subprocess.call(["git", "commit", "-m", commit_msg])
subprocess.call(["git", "push", "origin", "master"])
else:
RSyncPush().sync_file(file_path)
if __name__ == "__main__":
if len(sys.argv) == 3:
strategy = sys.argv[1]
file_path = sys.argv[2]
if strategy == "rsync":
RSyncPush().sync_file(file_path)
elif strategy == "git":
GitPush().sync_file(file_path)