आशा है कि यह एक और पोस्ट को पुनः के साथ ठीक है: python-subversion
: मैं Example 8.3. A Python status crawler - Using the APIs (svnbook) कोशिश करना चाहता था। उबंटू 11.04, पायथन 2.7, svn_client_status2
"त्रुटि (22) के साथ यूटीएफ -8 अक्षरों के साथ एक फ़ाइल नाम पर दुर्घटनाग्रस्त हो गया: यूटीएफ -8 पर निर्देशिका 'पथ' में प्रविष्टि को परिवर्तित करने में त्रुटि" - इसका समाधान setlocale
को किसी भी से पहले कॉल करना है इस समारोह में कॉल करता है।
मुझे यह भी एहसास हुआ कि पाइथन एपीआई में svn_client_status3
और svn_client_status4
हैं; svn_client_status3
में थोड़ा अलग कॉल है, और setlocale
की भी आवश्यकता है। हालांकि, svn_client_status4
का उपयोग नहीं किया जाना चाहिए - यह segfaults, क्योंकि इसे एक स्ट्रक्चर तर्क की आवश्यकता है जो पायथन वितरित नहीं कर सकता है; अधिक के लिए, #16027750 Debugging: stepping through Python script using gdb? देखें।
इसे लपेटने के लिए, यहां उदाहरण 8 है।
#!/usr/bin/env python
# modified from:
# http://svnbook.red-bean.com/en/1.5/svn.developer.usingapi.html
# does the same as `svn status`, and is marked:
"""Crawl a working copy directory, printing status information."""
# tested on Python 2.7, Ubuntu Natty 11.04; needs:
# sudo apt-get install python-subversion
import locale
print locale.getlocale() # (None, None) - in C: ANSI_X3.4-1968
locale.setlocale(locale.LC_ALL, '') # would print en_US.UTF-8
print locale.getlocale() # NOW it is ('en_US', 'UTF-8')
import sys
import os.path
import getopt
import svn.core, svn.client, svn.wc
def generate_status_code(status):
"""Translate a status value into a single-character status code,
using the same logic as the Subversion command-line client."""
code_map = { svn.wc.svn_wc_status_none : ' ',
svn.wc.svn_wc_status_normal : ' ',
svn.wc.svn_wc_status_added : 'A',
svn.wc.svn_wc_status_missing : '!',
svn.wc.svn_wc_status_incomplete : '!',
svn.wc.svn_wc_status_deleted : 'D',
svn.wc.svn_wc_status_replaced : 'R',
svn.wc.svn_wc_status_modified : 'M',
svn.wc.svn_wc_status_merged : 'G',
svn.wc.svn_wc_status_conflicted : 'C',
svn.wc.svn_wc_status_obstructed : '~',
svn.wc.svn_wc_status_ignored : 'I',
svn.wc.svn_wc_status_external : 'X',
svn.wc.svn_wc_status_unversioned : '?',
}
return code_map.get(status, '?')
def do_status(wc_path, verbose):
# Build a client context baton.
ctx = svn.client.svn_client_ctx_t()
def _status_callback(path, status):
"""A callback function for svn_client_status."""
# Print the path, minus the bit that overlaps with the root of
# the status crawl
text_status = generate_status_code(status.text_status)
prop_status = generate_status_code(status.prop_status)
print '%s%s %s' % (text_status, prop_status, path)
# Do the status crawl, using _status_callback() as our callback function.
revision = svn.core.svn_opt_revision_t()
revision.type = svn.core.svn_opt_revision_head
#~ svn.client.svn_client_status2(wc_path, revision, _status_callback,
#~ svn.core.svn_depth_infinity, verbose,
#~ 0, 0, 1, ctx)
svn.client.svn_client_status3(wc_path, revision, _status_callback,
svn.core.svn_depth_infinity, verbose,
0, 0, 1,(), ctx)
# DO NOT USE svn_client_status4! (needs a C struct argument)
def usage_and_exit(errorcode):
"""Print usage message, and exit with ERRORCODE."""
stream = errorcode and sys.stderr or sys.stdout
stream.write("""Usage: %s OPTIONS WC-PATH
Options:
--help, -h : Show this usage message
--verbose, -v : Show all statuses, even uninteresting ones
""" % (os.path.basename(sys.argv[0])))
sys.exit(errorcode)
if __name__ == '__main__':
# Parse command-line options.
try:
opts, args = getopt.getopt(sys.argv[1:], "hv", ["help", "verbose"])
except getopt.GetoptError:
usage_and_exit(1)
verbose = 0
for opt, arg in opts:
if opt in ("-h", "--help"):
usage_and_exit(0)
if opt in ("-v", "--verbose"):
verbose = 1
if len(args) != 1:
usage_and_exit(2)
# Canonicalize the repository path.
wc_path = svn.core.svn_path_canonicalize(args[0])
# Do the real work.
try:
do_status(wc_path, verbose)
except svn.core.SubversionException, e:
sys.stderr.write("Error (%d): %s\n" % (e.apr_err, e.message))
sys.exit(1)
pysvn लोगों मैं का उपयोग करना चाहते कर रहा हूँ की तुलना में अजगर बाइंडिंग का एक अलग सेट है: और क्रैश नहीं होता अपने सिस्टम पर (यहां तक कि UTF-8 वर्णों के साथ फ़ाइल नाम पर) - जो
svn_client_status3
का उपयोग करता है स्थानीय सेटिंग के साथ 3 । लेकिन वे उदाहरण उपयोगी हो सकते हैं। – retracile+1 svnshell.py काफी उपयोगी होगा। लेकिन मैं चेकआउट और विलय से ज्यादा संबंधित नहीं देख रहा हूं, इसलिए मैं अभी भी और अधिक खोज रहा हूं। – retracile