Skip to content

Commit e69776e

Browse files
committed
Add timestampt for upload and wrap upload in try except
1 parent fd0f843 commit e69776e

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/viur_cli/scriptor/cli.py

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import datetime
12
import click
23
import json
34
import requests
@@ -233,7 +234,8 @@ async def main(file_path: str=None):
233234
can_push = click.confirm(f"Content of {file} changed. Overwrite?")
234235

235236
if can_push:
236-
click.echo(f"Push {_real_file}")
237+
date = datetime.datetime.now().strftime("%H:%M:%S")
238+
click.echo(f"{date if watch else ""} Push {_real_file}")
237239
await tree.edit(_type, entry["key"], {
238240
"script": file_content
239241
})
@@ -299,15 +301,18 @@ def watch_loop():
299301
import time
300302
modified_files = {}
301303
def on_modified(event):
302-
# check for tmp file
303-
if event.src_path.endswith("~"):
304-
return
305-
if event.src_path not in modified_files:
304+
try:
305+
# check for tmp file
306+
if event.src_path.endswith("~"):
307+
return
308+
if event.src_path not in modified_files:
309+
modified_files[event.src_path] = os.path.getmtime(event.src_path)
310+
elif os.path.getmtime(event.src_path) == modified_files[event.src_path]:
311+
return
306312
modified_files[event.src_path] = os.path.getmtime(event.src_path)
307-
elif os.path.getmtime(event.src_path) == modified_files[event.src_path]:
308-
return
309-
modified_files[event.src_path] = os.path.getmtime(event.src_path)
310-
asyncio.new_event_loop().run_until_complete(main(event.src_path))
313+
asyncio.new_event_loop().run_until_complete(main(event.src_path))
314+
except Exception as e:
315+
print(f"Error: on file {event.src_path} {e}")
311316

312317

313318
regexes = [r".*\.py"]

0 commit comments

Comments
 (0)