LiveSync 0.3.2__tar.gz → 0.3.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: LiveSync
3
- Version: 0.3.2
3
+ Version: 0.3.4
4
4
  Summary: Repeatedly synchronize local workspace with a (slow) remote machine
5
5
  Home-page: https://github.com/zauberzeug/livesync
6
6
  Author: Zauberzeug GmbH
@@ -62,6 +62,8 @@ Options:
62
62
  interval in which mutex is updated (default: 10 seconds)
63
63
  - `--ignore-mutex`
64
64
  ignore mutex (use with caution) (default: False)
65
+ - `--no-watch`
66
+ don't keep watching the copied folders for changes after the sync (default: False)
65
67
 
66
68
  ### Python
67
69
 
@@ -77,6 +79,7 @@ sync(
77
79
  ```
78
80
 
79
81
  The `sync` call will block until the script is aborted.
82
+ Only if `watch=False` is used, the `sync` call will end after copying the folders to the target once.
80
83
  The `Folder` class allows to set the `port` and an `on_change` bash command which is executed after a sync has been performed.
81
84
  Via the `rsync_args` build method you can pass additional options to configure rsync.
82
85
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: LiveSync
3
- Version: 0.3.2
3
+ Version: 0.3.4
4
4
  Summary: Repeatedly synchronize local workspace with a (slow) remote machine
5
5
  Home-page: https://github.com/zauberzeug/livesync
6
6
  Author: Zauberzeug GmbH
@@ -62,6 +62,8 @@ Options:
62
62
  interval in which mutex is updated (default: 10 seconds)
63
63
  - `--ignore-mutex`
64
64
  ignore mutex (use with caution) (default: False)
65
+ - `--no-watch`
66
+ don't keep watching the copied folders for changes after the sync (default: False)
65
67
 
66
68
  ### Python
67
69
 
@@ -77,6 +79,7 @@ sync(
77
79
  ```
78
80
 
79
81
  The `sync` call will block until the script is aborted.
82
+ Only if `watch=False` is used, the `sync` call will end after copying the folders to the target once.
80
83
  The `Folder` class allows to set the `port` and an `on_change` bash command which is executed after a sync has been performed.
81
84
  Via the `rsync_args` build method you can pass additional options to configure rsync.
82
85
 
@@ -49,6 +49,8 @@ Options:
49
49
  interval in which mutex is updated (default: 10 seconds)
50
50
  - `--ignore-mutex`
51
51
  ignore mutex (use with caution) (default: False)
52
+ - `--no-watch`
53
+ don't keep watching the copied folders for changes after the sync (default: False)
52
54
 
53
55
  ### Python
54
56
 
@@ -64,6 +66,7 @@ sync(
64
66
  ```
65
67
 
66
68
  The `sync` call will block until the script is aborted.
69
+ Only if `watch=False` is used, the `sync` call will end after copying the folders to the target once.
67
70
  The `Folder` class allows to set the `port` and an `on_change` bash command which is executed after a sync has been performed.
68
71
  Via the `rsync_args` build method you can pass additional options to configure rsync.
69
72
 
@@ -55,17 +55,22 @@ class Folder:
55
55
  path = self.source_path / '.syncignore'
56
56
  if not path.is_file():
57
57
  path.write_text('\n'.join(self.DEFAULT_IGNORES))
58
- return [line.strip() for line in path.read_text().splitlines() if not line.startswith('#')]
58
+ ignores = [line.strip() for line in path.read_text().splitlines() if not line.startswith('#')]
59
+ ignores += [ignore.rstrip('/\\') for ignore in ignores if ignore.endswith('/') or ignore.endswith('\\')]
60
+ return ignores
59
61
 
60
62
  def get_summary(self) -> str:
61
63
  summary = f'{self.source_path} --> {self.target}\n'
62
64
  try:
65
+ cmd = ['git', 'rev-parse', '--is-inside-work-tree']
66
+ subprocess.run(cmd, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
67
+ except subprocess.CalledProcessError:
68
+ pass # not a git repo, git is not installed, or something else
69
+ else:
63
70
  cmd = ['git', 'log', '--pretty=format:[%h]\n', '-n', '1']
64
71
  summary += subprocess.check_output(cmd, cwd=self.source_path).decode()
65
72
  cmd = ['git', 'status', '--short', '--branch']
66
73
  summary += subprocess.check_output(cmd, cwd=self.source_path).decode().strip() + '\n'
67
- except Exception:
68
- pass # not a git repo, git is not installed, or something else
69
74
  return summary
70
75
 
71
76
  async def watch(self) -> None:
@@ -14,12 +14,13 @@ def main():
14
14
  parser.add_argument('--on-change', type=str, help='command to be executed on remote host after any file change')
15
15
  parser.add_argument('--mutex-interval', type=int, default=10, help='interval in which mutex is updated')
16
16
  parser.add_argument('--ignore-mutex', action='store_true', help='ignore mutex (use with caution)')
17
+ parser.add_argument('--no-watch', action='store_true', help='do not watch for changes')
17
18
  parser.add_argument('rsync_args', nargs=argparse.REMAINDER, help='arbitrary rsync parameters after "--"')
18
19
  args = parser.parse_args()
19
20
 
20
21
  folder = Folder(args.source, args.target, ssh_port=args.ssh_port, on_change=args.on_change)
21
22
  folder.rsync_args(' '.join(args.rsync_args))
22
- sync(folder, mutex_interval=args.mutex_interval, ignore_mutex=args.ignore_mutex)
23
+ sync(folder, mutex_interval=args.mutex_interval, ignore_mutex=args.ignore_mutex, watch=not args.no_watch)
23
24
 
24
25
 
25
26
  if __name__ == '__main__':
@@ -10,7 +10,9 @@ def get_summary(folders: Iterable[Folder]) -> str:
10
10
  return '\n'.join(folder.get_summary() for folder in folders).replace('"', '\'')
11
11
 
12
12
 
13
- async def run_folder_tasks(folders: Iterable[Folder], mutex_interval: float, ignore_mutex: bool = False) -> None:
13
+ async def run_folder_tasks(
14
+ folders: Iterable[Folder],
15
+ mutex_interval: float, ignore_mutex: bool = False, watch: bool = True) -> None:
14
16
  try:
15
17
  if not ignore_mutex:
16
18
  summary = get_summary(folders)
@@ -25,23 +27,24 @@ async def run_folder_tasks(folders: Iterable[Folder], mutex_interval: float, ign
25
27
  print(f' {folder.source_path} --> {folder.target}', flush=True)
26
28
  folder.sync()
27
29
 
28
- for folder in folders:
29
- print(f'Watch folder {folder.source_path}', flush=True)
30
- asyncio.create_task(folder.watch())
31
-
32
- while True:
33
- if not ignore_mutex:
34
- summary = get_summary(folders)
35
- for mutex in mutexes.values():
36
- if not mutex.set(summary):
37
- break
38
- await asyncio.sleep(mutex_interval)
30
+ if watch:
31
+ for folder in folders:
32
+ print(f'Watch folder {folder.source_path}', flush=True)
33
+ asyncio.create_task(folder.watch())
34
+
35
+ while True:
36
+ if not ignore_mutex:
37
+ summary = get_summary(folders)
38
+ for mutex in mutexes.values():
39
+ if not mutex.set(summary):
40
+ break
41
+ await asyncio.sleep(mutex_interval)
39
42
  except Exception as e:
40
43
  print(e)
41
44
 
42
45
 
43
- def sync(*folders: Folder, mutex_interval: float = 10, ignore_mutex: bool = False) -> None:
46
+ def sync(*folders: Folder, mutex_interval: float = 10, ignore_mutex: bool = False, watch: bool = True) -> None:
44
47
  try:
45
- asyncio.run(run_folder_tasks(folders, mutex_interval, ignore_mutex=ignore_mutex))
48
+ asyncio.run(run_folder_tasks(folders, mutex_interval, ignore_mutex=ignore_mutex, watch=watch))
46
49
  except KeyboardInterrupt:
47
50
  print('Bye!')
File without changes
File without changes
File without changes
File without changes
File without changes