Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exe_dir = os.path.dirname(os.path.realpath(sys.executable if hasattr(sys, 'frozen') else sys.argv[0]))
config_file = os.path.join(exe_dir, 'fsnotifier.yaml')
try:
with open(config_file) as f:
config = yaml.load(f)
except FileNotFoundError:
print('Config file not found: {}'.format(config_file))
sys.exit(1)
logfile = open(config['log']['file'] if config['log']['enabled'] else os.devnull, 'w')
config['reverse_mapping'] = {v: '{}:'.format(k) for k, v in config['mapping'].items()}
# Local notifier
local_stdin = sarge.Feeder()
local_watcher = sarge.run(config['fsnotifier']['local'], stdout=sarge.Capture(), input=local_stdin, async_=True)
local_monitor = LocalMonitorThread(daemon=True)
# Remote notifier
ssh_conn = paramiko.SSHClient()
ssh_conn.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_conn.connect(config['ssh']['host'], username=config['ssh']['user'], allow_agent=True)
ssh_stdin, ssh_stdout, _ = ssh_conn.exec_command(config['fsnotifier']['remote'])
remote_monitor = RemoteMonitorThread(daemon=True)
local_monitor.start()
remote_monitor.start()
receiving_roots = False
new_roots = []
while True: