Svn Recursive Checkout
Hi All,
Its a small helper function to checkout svn repo recursively .
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
""" Helper function for recursively checkout svn repo to a location. """ import os import logging import sys logger = logging.getLogger("svnRcout") logging.basicConfig() #~ we need to make sure we have pysvn installed. try: import pysvn except ImportError: logger.exception("svnRcout need pysvn, please make sure you have pysvn installed.") sys.exit() from optparse import OptionParser as optparse #~ creating pysvn client. client = pysvn.Client() def list_all_svn_childs(root_svn, checkout_loc,trunk_chk,recurse): """ Function for creating svn repo to local location. :param root_svn: Svn root path for checkout_loc :type root_svn: string :param checkout_loc: local checkout location path :type checkout_loc: string :param trunk_chk: do we need to check only trunk or all including branch and tags. :type trunk_chk: bool :param recurse: do we need to checkout recursively or not :type trunk_chk: bool """ entries_list = client.ls( root_svn, revision=pysvn.Revision( pysvn.opt_revision_kind.head ), \ recurse=False, peg_revision=pysvn.Revision\ ( pysvn.opt_revision_kind.unspecified ) ) print "\n=" * 80 print "\t\tSVN Checkout starting for %s.\n" % (root_svn) print "=" * 80 for each_svn in entries_list: svn_url = each_svn.name if trunk_chk: svn_url = os.path.join(each_svn.name,"trunk") if not os.path.exists(os.path.join(checkout_loc, os.path.basename(each_svn.name))): os.mkdir(os.path.join(checkout_loc, os.path.basename(each_svn.name))) svn_check_out_loc = os.path.join(checkout_loc, os.path.basename(each_svn.name)) revision = client.checkout(svn_url, svn_check_out_loc, recurse=recurse, \ revision=pysvn.Revision( pysvn.opt_revision_kind.head ), \ peg_revision=pysvn.Revision( pysvn.opt_revision_kind.unspecified ), \ ignore_externals=False ) print " \"%s\" checked out to %s with revision number of %s." % ( os.path.basename(each_svn.name)\ , svn_check_out_loc, revision.number) print "=\n" * 80 def main(): """ Main function and more details can say be the help doc's """ usage = "usage: svnRcout.py [options] arg1 arg2" parser = optparse(description = "Tool for recursively checkout svn repo. ", prog = "svnRcout", usage = usage, version = "Version 0.0.1") parser.add_option("-s", "--svnroot", action = "store", type = "string", \ help = "SVN Root folder path (required).") parser.add_option("-o", "--output", action = "store", type = "string", \ help = "Checkout location (required).") parser.add_option("-t", "--trunk", action = "store_true", default = True, \ help = "Checkout only trunk, by default its true") parser.add_option("-r", "--recurse", action = "store_true", default = True, \ help = "Checkout recursively , by default its true.") (options, args) = parser.parse_args() svn_root = options.svnroot svn_checkout = options.output trunk_chk = options.trunk recurse = options.recurse if not svn_root or not svn_checkout: parser.print_help() parser.error ("Insufficient arguments.") list_all_svn_childs(svn_root, svn_checkout, trunk_chk, recurse) if __name__ == "__main__": main() |