osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

subprocess svn checkout password issue


On Saturday, 16 March 2019 16:50:23 UTC+11, dieter  wrote:
> Martin De Kauwe <mdekauwe at gmail.com> writes:
> 
> > I'm trying to write a script that will make a checkout from a svn repo and build the result for the user. However, when I attempt to interface with the shell it asks the user for their filename and I don't know how to capture this with my implementation. 
> >
> > user = "XXX578"
> > root="https://trac.nci.org.au/svn/cable";
> > repo_name = "CMIP6-MOSRS"
> >
> > cmd = "svn checkout %s/branches/Users/%s/%s" % (root, user, repo_name)
> > p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
> >                                       stdout=subprocess.PIPE, stderr=subprocess.PIPE)
> > error = subprocess.call(cmd, shell=True)
> > if error is 1:
> >     raise("Error downloading repo"
> >
> > I tried adding .wait(timeout=60) to the subprocess.Popen command but that didn't work.
> >
> > Any advice on whether there is an augmentation to the above, or a better approach, would be much appreciated. I need to solve this with standard python libs as I'm trying to make this as simple as possible for the user.
> 
> That is non-trivial.
> 
> Read the "svn" documentation. You might be able to pass in the
> required information by other means, maybe an option, maybe
> an envvar, maybe via a configuration file.
> 
> Otherwise, you must monitor what it written to the subprocess'
> "stdout" and "stderr", recognized the interaction request
> perform the interaction with the user and send the result
> to the subprocess' stdin.

Thanks, I think this solution will work.

import subprocess
import getpass

user = "XXX578"
root="https://trac.nci.org.au/svn/cable";
repo_name = "CMIP6-MOSRS"

pswd = "'" + getpass.getpass('Password:') + "'"
cmd = "svn checkout %s/branches/Users/%s/%s --password %s" %\
             (root, user, repo_name, pswd)
error = subprocess.call(cmd, shell=True)
if error is 1:
    raise("Error checking out repo")