Jwink3101 / syncrclone

Python-based bi-direction sync tool for rclone
MIT License
154 stars 13 forks source link

'config_tips.md': subprocess.check_call(['hostname']) returns 0 under Linux Mint 20 #8

Closed WaDoMa closed 3 years ago

WaDoMa commented 3 years ago

In line 91 of config_tips.md , you recommend to get the hostname by the command hostname = subprocess.check_call(['hostname']) . With this, $ syncrclone config.py throws an error under LinuxMint 20 (Python 3.8.10): ERROR: Unrecognized host 0 I could also reproduce this behavior in a Python console by hostname = subprocess.check_call(['hostname']) It prints the right hostname, but the variable hostname would be 0 . config.py worked for me with this fix: Substitute

import subprocess
hostname = subprocess.check_call(['hostname'])

by

import socket
hostname = socket.getfqdn()

I don't know, how portable this is and if it works in special environments such as cron. But maybe you could consider this fix. Thank you and kind regards!

Jwink3101 commented 3 years ago

Ahh, it should be check_output.

WaDoMa commented 3 years ago

If I use hostname = subprocess.check_output(['hostname']) , $ syncrclone config.pythrows an ERROR: Unrecognized host b'L460\n' . If I use hostname = subprocess.run(['hostname']) , which supersedes check_output (refer to Stackoverflow), this error is thrown: ERROR: Unrecognized host CompletedProcess(args=['hostname'], returncode=0) Both approaches work in the Python console, though...

Jwink3101 commented 3 years ago

What happens when you run with --debug? I am 99% sure this is an error with your code inside of the config and not syncrclone itself. All syncrclone wants in a name so that it can name the previous files lists and consistently call them (and for tagging, etc).

When you run with --debug in the latest version it should throw an error in something like [...]/site-packages/syncrclone/cli.py", line 75, in parse

The fact that it works in your python console but not syncrclone also makes me think they may be different versions of Python.

Put the following code in your config.py (or whatever you named it) and your console

import sys
print('\n'*10 + '='*50)
print(sys.executable)
print('-'*50)
raise ValueError()

(where it is just spaces to easily pick it out) and see if they are the same.

Finally, I changed the example snippet to

name = subprocess.check_output(['hostname']).decode().strip()

But again, the name doesn't really matter.

WaDoMa commented 3 years ago

hostname = subprocess.check_output(['hostname']).decode().strip() works now. Maybe, yesterday I just mistyped or forgot something. Sorry about that and thanks a lot for your effort!