Skip to content

Commit

Permalink
Added output of full log option
Browse files Browse the repository at this point in the history
  • Loading branch information
Acidham committed Jan 24, 2023
1 parent 7b52926 commit ddf9d47
Show file tree
Hide file tree
Showing 6 changed files with 294 additions and 159 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@ Usage: `rsync`

* Executes `rsync``on *all* rsync entries or the entries one by one.
* New Entries can be added in the workflow or via file action
* Delete rsync config entries.
* Edit rsync config

![](screenshot.png)
Binary file modified RSync Folders.alfredworkflow
Binary file not shown.
2 changes: 1 addition & 1 deletion src/delete_item.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

from Alfred3 import Items, Tools
from Alfred3 import Items
from Rsync import Config

rs = Config()
Expand Down
41 changes: 34 additions & 7 deletions src/exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,57 @@
from Alfred3 import Tools
from Rsync import Config

TMP_FILE = "/tmp/rsync_log.txt"

# Remove log file when exists
if os.path.exists(TMP_FILE):
os.remove(TMP_FILE)

# write stats to log files


def write_log(source, target, txt):
with open(TMP_FILE, "a") as f:
head = f"{source} -> {target}"
f.write(head)
f.write("\n")
f.write("=" * len(head))
f.write("\n")
f.write(txt)
f.write("\n")

# rsync source to target


def rsync(source: str, target: str) -> int:
cmd = f'rsync -rtvuc --delete-after --ignore-errors "{source}/" "{target}/" --stats | grep "Number of files transferred"'
cmd = f'rsync -rtvuc --delete-after --ignore-errors "{source}/" "{target}/" --stats'
res = os.popen(cmd).read()
output = re.sub("[^0-9]", "", res)
return int(output)
return (res)


uid = Tools.getArgv(1)

rs = Config()
config = rs.getConfig()
result = 0
file_count = 0
if uid == "-ALL-":
for c in config:
source = c["source"]
target = c["target"]
result = result + rsync(source, target)
result = rsync(source, target)
match = re.search("Number of files transferred (\d+)", result)
file_count += int(match.group(1))
write_log(source, target, result)
else:
for c in config:
if c["uid"] == uid:
source = c["source"]
target = c["target"]
result = int(rsync(source, target))
result = rsync(source, target)
match = re.search("Number of files transferred: (\d+)", result)
mg = int(match.group(1))
file_count += mg
write_log(source, target, result)


sys.stdout.write(str(result))
sys.stdout.write(str(file_count))
Loading

0 comments on commit ddf9d47

Please sign in to comment.