Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.stsci.edu/spst/UnixTransition/doc/checkout.py
Дата изменения: Fri Feb 28 14:46:09 2014
Дата индексирования: Sat Mar 1 14:17:25 2014
Кодировка:

Поисковые слова: п п п п п р п р п
#
#MODULE checkout
#
#***********************************************************************
"""

**PURPOSE** --
Check out a configured file for modification.

This tool replaces CONFIGURE.COM

Requires environment variable UVM_LIBRARY. UVM_LIBRARY should be
the top level uvm library directory.

**DEVELOPER** --
Don Chance

**MODIFICATION HISTORY** --
Initial implementation 7/18/01
Modified to use uvm_server. 9/5/01
Modified to enhance robustness. 10/30/01 drc
Enhance error messages when file cannot be reserved. 3/16/02 drc
Create the checkout file to store info about who did the checkout
and when they did it. 6/5/03 drc
Fix problems caused by upgrade to python 2.4.1 9/20/05 drc
Just delete the file, rather than chmod'ing it. 2/26/09 drc
remove chmod on temp file. 4/9/09
no need to close temp file. 4/29/09
close that file after all 5/19/09
open/close file quickly. 11/3/09 drc
completely revamped to client/server architecture 10/12/11 drc
add info about who's checking out the file. 11/20/13 drc
"""
#***********************************************************************
import spss_sys_util, os, spst_getopt, shutil, socket

__version__ = "13.11.20"

def run(*args):
"""Reserve a configured file for modification.

Usage:
do checkout [-verbose]

"""
if spss_sys_util.on_vms():
raise OSError("You must be on Unix to run this command!")

options, params = spst_getopt.spst_getopt(args, ['verbose'])

if params:
file_name = params[0]
else:
print run.__doc__
return spss_sys_util.SUCCESS

if options:
verbose = 1
else:
verbose = 0

for File in spss_sys_util.glob(file_name):
try:
yn = raw_input( "Deleting local file %s. Do you want to proceed [y/n]? " % File).strip().lower()[0]
if yn == 'y':
os.remove(File)
else:
print "Unable to checkout file!"
return not spss_sys_util.SUCCESS
except:
print spss_sys_util.get_traceback_string()
print "Unable to checkout file! Unable to delete existing file", File
return not spss_sys_util.SUCCESS

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
sock.connect(("holst.sogs.stsci.edu",32333))
except:
print "ERROR -- Unable to connect to UVM server!"

sock.send("checkout %s %s" % (file_name,
os.environ.get('MYNAME', '???')))

resp = ''
while True:
data = sock.recv(1024)

if not data:
sock.close()
break

resp += data

if verbose:
print "Server said:", resp

if os.path.isfile(resp):
newpath = os.path.join(os.getcwd(), os.path.basename(resp))
shutil.copyfile(resp, newpath)
os.chmod(newpath, 0775)
print "Remember to run 'do checkin %s' when you are finished." % file_name
return spss_sys_util.SUCCESS
else:
print resp
return not spss_sys_util.SUCCESS


if __name__ == '__main__':
import sys
if len(sys.argv) > 1:
run(sys.argv[1])
else:
run()