1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-10-05 18:50:09 +02:00

server init: replace ssh subprocess with paramiko

It is easier to handle programming with python rather than subprocess calls
so I replaced the subprocess call to 'ssh' with paramiko.  This also makes
fdroid more portable since it no longer relies on the local system having
ssh installed.
This commit is contained in:
Hans-Christoph Steiner 2014-07-02 20:54:52 -04:00
parent d69f93e5b2
commit c7962e7c6d

View File

@ -20,6 +20,8 @@
import sys import sys
import hashlib import hashlib
import os import os
import paramiko
import pwd
import subprocess import subprocess
from optparse import OptionParser from optparse import OptionParser
import logging import logging
@ -255,17 +257,26 @@ def main():
if args[0] == 'init': if args[0] == 'init':
if config.get('serverwebroot'): if config.get('serverwebroot'):
sshargs = ['ssh'] ssh = paramiko.SSHClient()
if options.quiet: ssh.load_system_host_keys()
sshargs += ['-q'] sshstr, remotepath = config['serverwebroot'].rstrip('/').split(':')
if sshstr.find('@') >= 0:
username, hostname = sshstr.split('@')
else:
username = pwd.getpwuid(os.getuid())[0] # get effective uid
hostname = sshstr
ssh.connect(hostname, username=username)
sftp = ssh.open_sftp()
if os.path.basename(remotepath) \
not in sftp.listdir(os.path.dirname(remotepath)):
sftp.mkdir(remotepath, mode=0755)
for repo_section in repo_sections: for repo_section in repo_sections:
cmd = sshargs + [host, 'mkdir -p', fdroiddir + '/' + repo_section] repo_path = os.path.join(remotepath, repo_section)
if options.verbose: if os.path.basename(repo_path) \
# ssh -v produces different output than rsync -v, so this not in sftp.listdir(remotepath):
# simulates rsync -v sftp.mkdir(repo_path, mode=0755)
logging.info(' '.join(cmd)) sftp.close()
if subprocess.call(cmd) != 0: ssh.close()
sys.exit(1)
elif args[0] == 'update': elif args[0] == 'update':
for repo_section in repo_sections: for repo_section in repo_sections:
if local_copy_dir is not None: if local_copy_dir is not None: