Python ClearCase Download Vobs Popen Password BASH

2019-01-20 06:01发布

问题:

I coded this program yesterday and it was actually working except for when run by CRON. Today, I ran the same script and it does not work. The script will run without any Tracebacks Errors, and it will copy the top folder (vob) from the ClearCase view, but none of the actual important data in the folders and files below the target folder.

Here is my Python script.

def obtainCode(view="My_VIEW", folder="/my_folder"):
    """Download code from ClearCase's File System and put it on the hard-drive"""

    dest = '/etc/foo'
    password = 'passwords'

    v1 = subprocess.Popen(['cleartool', 'setview', view], shell=True, stdout=subprocess.PIPE)
    print "v1 = ", v1
    print "view maybe set :/"

    c1 = subprocess.Popen(['sudo', '-p', '', '-S', 'cp', '-r', folder, dest], stdin=subprocess.PIPE)
    c1.stdin.write(password + '\n')
    c1.stdin.close()
    c1.wait()

    #### Close View and Stop Processes ####
    v2 = subprocess.Popen(['cleartool', 'endview', view], shell=True, stdin=v1.stdout, stdout=subprocess.PIPE)


    v2.kill()
    v1.kill()

Does anyone know: 1) what is going wrong 2) why it would work yesterday but not today 3) a better way to do this?

Thank-you for your time and attention.

回答1:

Try and not use setview.
You do not need it and you can use the full path of the view instead.

cleartool startview yourDynamicView
cd /view/yourDynamicView/vobs/yourVob

I have mentioned before the danger of using setview ("Python and ClearCase setview").
It creates a subprocess within your subprocess, which is not needed here.