{"id":571,"date":"2011-09-27T10:22:48","date_gmt":"2011-09-27T10:22:48","guid":{"rendered":"http:\/\/www.kurianos.com\/wordpress\/?p=571"},"modified":"2011-10-23T07:19:20","modified_gmt":"2011-10-23T07:19:20","slug":"svn-recursive-checkout","status":"publish","type":"post","link":"https:\/\/www.kurianos.com\/wordpress\/?p=571","title":{"rendered":"Svn Recursive Checkout"},"content":{"rendered":"<p>Hi All,<\/p>\n<p>Its a small helper function to checkout svn repo recursively .<br \/>\n[Python]<br \/>\n&#8220;&#8221;&#8221;<br \/>\nHelper function for recursively checkout svn repo to a location.<br \/>\n&#8220;&#8221;&#8221;<br \/>\nimport os<br \/>\nimport logging<br \/>\nimport sys<br \/>\nlogger = logging.getLogger(&#8220;svnRcout&#8221;)<br \/>\nlogging.basicConfig()<\/p>\n<p>#~ we need to make sure we have pysvn installed.<br \/>\ntry:<br \/>\n\timport pysvn<br \/>\nexcept ImportError:<br \/>\n\tlogger.exception(&#8220;svnRcout need pysvn, please make sure you have pysvn installed.&#8221;)<br \/>\n\tsys.exit()<\/p>\n<p>from optparse import OptionParser as optparse<\/p>\n<p>#~ creating pysvn client.<br \/>\nclient = pysvn.Client()<\/p>\n<p>def list_all_svn_childs(root_svn, checkout_loc,trunk_chk,recurse):<br \/>\n\t&#8220;&#8221;&#8221;<br \/>\n\tFunction for creating svn repo to local location.<\/p>\n<p>\t:param root_svn: Svn root path for checkout_loc<\/p>\n<p>\t:type root_svn: string<\/p>\n<p>\t:param checkout_loc: local checkout location path<\/p>\n<p>\t:type checkout_loc: string<\/p>\n<p>\t:param trunk_chk: do we need to check only trunk or all including branch and tags.<\/p>\n<p>\t:type trunk_chk: bool<\/p>\n<p>\t:param recurse: do we need to checkout recursively or not<\/p>\n<p>\t:type trunk_chk: bool<\/p>\n<p>\t&#8220;&#8221;&#8221;<br \/>\n\tentries_list = client.ls( root_svn, revision=pysvn.Revision( pysvn.opt_revision_kind.head ), \\<br \/>\n\t\t\t\t\t\t\t\trecurse=False, peg_revision=pysvn.Revision\\<br \/>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t( pysvn.opt_revision_kind.unspecified ) )<br \/>\n\tprint &#8220;\\n=&#8221; * 80<br \/>\n\tprint &#8220;\\t\\tSVN Checkout starting for %s.\\n&#8221; % (root_svn)<br \/>\n\tprint &#8220;=&#8221; * 80<br \/>\n\tfor each_svn in entries_list:<br \/>\n\t\tsvn_url = each_svn.name<\/p>\n<p>\t\tif trunk_chk:<br \/>\n\t\t\tsvn_url = os.path.join(each_svn.name,&#8221;trunk&#8221;)<\/p>\n<p>\t\tif not os.path.exists(os.path.join(checkout_loc, os.path.basename(each_svn.name))):<br \/>\n\t\t\tos.mkdir(os.path.join(checkout_loc, os.path.basename(each_svn.name)))<\/p>\n<p>\t\tsvn_check_out_loc = os.path.join(checkout_loc, os.path.basename(each_svn.name))<br \/>\n\t\trevision = client.checkout(svn_url, svn_check_out_loc, recurse=recurse, \\<br \/>\n\t\t\t\t\trevision=pysvn.Revision( pysvn.opt_revision_kind.head ), \\<br \/>\n\t\t\t\t\tpeg_revision=pysvn.Revision( pysvn.opt_revision_kind.unspecified ), \\<br \/>\n\t\t\t\t\tignore_externals=False )<br \/>\n\t\tprint &#8221; \\&#8221;%s\\&#8221; checked out to %s with revision number of %s.&#8221; % ( os.path.basename(each_svn.name)\\<br \/>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t, svn_check_out_loc, revision.number)<\/p>\n<p>\tprint &#8220;=\\n&#8221; * 80<\/p>\n<p>def main():<br \/>\n\t&#8220;&#8221;&#8221;<br \/>\n\tMain function and more details can say be the help doc&#8217;s<br \/>\n\t&#8220;&#8221;&#8221;<br \/>\n\tusage = &#8220;usage: svnRcout.py [options] arg1 arg2&#8221;<br \/>\n\tparser = optparse(description = &#8220;Tool for recursively checkout svn repo. &#8220;,<br \/>\n\t\t\t\t\t\tprog = &#8220;svnRcout&#8221;,<br \/>\n\t\t\t\t\t\tusage = usage,<br \/>\n\t\t\t\t\t\tversion = &#8220;Version 0.0.1&#8221;)<br \/>\n\tparser.add_option(&#8220;-s&#8221;, &#8220;&#8211;svnroot&#8221;, action = &#8220;store&#8221;, type = &#8220;string&#8221;, \\<br \/>\n\thelp = &#8220;SVN Root folder path (required).&#8221;)<br \/>\n\tparser.add_option(&#8220;-o&#8221;, &#8220;&#8211;output&#8221;, action = &#8220;store&#8221;, type = &#8220;string&#8221;, \\<br \/>\n\thelp = &#8220;Checkout location (required).&#8221;)<br \/>\n\tparser.add_option(&#8220;-t&#8221;, &#8220;&#8211;trunk&#8221;, action = &#8220;store_true&#8221;, default = True, \\<br \/>\n\thelp = &#8220;Checkout only trunk, by default its true&#8221;)<br \/>\n\tparser.add_option(&#8220;-r&#8221;, &#8220;&#8211;recurse&#8221;, action = &#8220;store_true&#8221;, default = True, \\<br \/>\n\thelp = &#8220;Checkout recursively , by default its true.&#8221;)<br \/>\n\t(options,  args) =  parser.parse_args()<\/p>\n<p>\tsvn_root = options.svnroot<br \/>\n\tsvn_checkout = options.output<br \/>\n\ttrunk_chk = options.trunk<br \/>\n\trecurse = options.recurse<\/p>\n<p>\tif not svn_root or not svn_checkout:<br \/>\n\t\tparser.print_help()<br \/>\n\t\tparser.error (&#8220;Insufficient arguments.&#8221;)<\/p>\n<p>\tlist_all_svn_childs(svn_root, svn_checkout, trunk_chk, recurse)<\/p>\n<p>if __name__ == &#8220;__main__&#8221;:<\/p>\n<p>\tmain()<\/p>\n<p>[\/Python]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi All, Its a small helper function to checkout svn repo recursively . [Python] &#8220;&#8221;&#8221; Helper function for recursively checkout svn repo to a location. &#8220;&#8221;&#8221; import os import logging import sys logger = logging.getLogger(&#8220;svnRcout&#8221;) logging.basicConfig() #~ we need to make sure we have pysvn installed. try: import pysvn except ImportError: logger.exception(&#8220;svnRcout need pysvn, please [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[15,14,1],"tags":[],"class_list":["post-571","post","type-post","status-publish","format-standard","hentry","category-linux","category-python","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.kurianos.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/571","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kurianos.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kurianos.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kurianos.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kurianos.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=571"}],"version-history":[{"count":3,"href":"https:\/\/www.kurianos.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/571\/revisions"}],"predecessor-version":[{"id":596,"href":"https:\/\/www.kurianos.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/571\/revisions\/596"}],"wp:attachment":[{"href":"https:\/\/www.kurianos.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=571"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kurianos.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=571"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kurianos.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=571"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}