#!/usr/bin/env python # #******************************************************************************* # #Copyright (c) 2009, Perforce Software, Inc. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE SOFTWARE, INC. BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #******************************************************************************* # #Author: Stephen Moon #Summary: Deletes a large number of users using a CSV file # #******************************************************************************* from subprocess import Popen,PIPE,STDOUT from subprocess import Popen,PIPE,STDOUT import optparse,csv,re def main(): parser = optparse.OptionParser(usage="%prog [-h,-v] csvName", version="%prog v0.9") parser.add_option("-v","--verbose",action="store_true",dest="verbose",help="Print debug messages to stdout") (options,args) = parser.parse_args() #by default sys.argv[1:] if len(args) != 1: parser.error("Incorrect number of arguments") #read a CSV file file = csv.reader(open(args[0], "r"),delimiter='\n',quoting=csv.QUOTE_NONE) rlist = [] clist = [] for row in file: rlist = row[0].split(",") clist.append(rlist) p4userOut = ['p4','-u','smoon','-p','20092','user','-d','-f'] lines = open(args[0]).readlines() for row in clist: p4userOut.append(row[0]) p2 = Popen(p4userOut,stdout=PIPE) p4userOut.remove(row[0]) output = p2.communicate()[0] #print output if __name__ == '__main__': main()