[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: Learning the Python API - early questions

From: Barry Scott <barry_at_barrys-emacs.org>
Date: 2003-10-16 23:08:14 CEST

(let's stop cross posting. Use dev?)

At 16-10-2003 18:50, Russell Yanofsky wrote:
>If the subversion API were a normal python library, it would need to report
>these types of errors. But it's not a normal python library. It already
>requires users to use pools and manage their own memory. I don't think it's
>too much to ask them to ask them to write correct programs in order to
>prevent crashes.

Sorry I don't accept this line of reasoning. Why must it be so hard and
unfriendly? It means that any app I build for users will crash in response
to my bugs in a way that makes support a nightmare. Atleast with python
exception I get a useful report. (Tupically I catch the exceptions
and automatically mail bug reports in for in house projects).

>I saw your svncpp patches browsing the rapidsvn dev list. Can you post your
>swig wrapper somewhere? Do you think your work could be incorporated into
>rapidsvn?

I'm trying to convince Alex not to make svncpp dependent on wxWindows.
I'd be happy if the source is available to compile and build the extension
from, using std::list and std::string is fine.

Here is the prototype (not fit to ship) swig file. I've added in functions
to convert types into something that SWIG can convert. Below is my
unittest for ls. I have status and log working as well.

Barry

------------------ svncpp.i ------------------------------
%module svncpp
%{
#include "client.hpp"
#include "context.hpp"
#include "dirent.hpp"
#include "entry.hpp"
#include "exception.hpp"
#include "log_entry.hpp"
#include "notify.hpp"
#include "path.hpp"
#include "pool.hpp"
#include "property.hpp"
#include "revision.hpp"
#include "status.hpp"
#include "targets.hpp"
#include "url.hpp"
#include "wc.hpp"

using namespace svn;

int lenDirentList( svn::DirEntries &entry_list )
         {
         return entry_list.size();
         }

svn::DirEntry &getDirentFromList( svn::DirEntries &entry_list, int index )
         {
         return entry_list[index];
         }

int lenLogEntriesList( svn::LogEntries &entry_list )
         {
         return entry_list.size();
         }

svn::LogEntry &getLogEntryFromList( svn::LogEntries &entry_list, int index )
         {
         return entry_list[index];
         }

int lenStatusList( svn::StatusEntries &entry_list )
         {
         return entry_list.size();
         }

svn::Status &getStatusFromList( svn::StatusEntries &entry_list, int index )
         {
         return entry_list[index];
         }

double pyTimeFromAprTime( apr_time_t &apr_time )
         {
         return apr_time / 1000000.0;
         }

double pyFileSizeFromSvnFileSize( svn_filesize_t &size )
         {
         return (double)(signed __int64)size;
         }

const char *cstrFromStdString( const std::string &str )
         {
         return str.c_str();
         }

%}
%rename(doImport) svn::Client::import (const Path & path, const char * url,
const char * message, bool recurse);

%include "client.hpp"
%include "context.hpp"
%include "dirent.hpp"
%include "entry.hpp"
%include "exception.hpp"
%include "log_entry.hpp"
%include "notify.hpp"
%include "path.hpp"
%include "pool.hpp"
%include "property.hpp"
%include "revision.hpp"
%include "status.hpp"
%include "targets.hpp"
%include "url.hpp"
%include "wc.hpp"

%include "svn_types.h"
%include "svn_wc.h"

extern int lenDirentList( svn::DirEntries &entry_list );
extern svn::DirEntry &getDirentFromList( svn::DirEntries &entry_list, int
index );
extern int lenLogEntriesList( svn::LogEntries &entry_list );
extern svn::LogEntry &getLogEntryFromList( svn::LogEntries &entry_list, int
index );
extern int lenStatusList( svn::StatusEntries &entry_list );
extern svn::Status &getStatusFromList( svn::StatusEntries &entry_list, int
index );
extern double pyTimeFromAprTime( apr_time_t &time );
extern double pyFileSizeFromSvnFileSize( svn_filesize_t &size );
extern const char *cstrFromStdString( const std::string &str );
--------------------- test_ls.py ----------------------
import sys
import time
import svncpp

kind_map = {
         svncpp.svn_node_none: 'none',
         svncpp.svn_node_file: 'file',
         svncpp.svn_node_dir: 'dir',
         svncpp.svn_node_unknown: 'unknown'
         }

def main( argv ):
         c = svncpp.Client()
         r = svncpp.Revision( svncpp.Revision.HEAD )
         all_dirents = c.ls( argv[1], r.revision(), 0 )
         for i in range( svncpp.lenDirentList( all_dirents ) ):
                 entry = svncpp.getDirentFromList( all_dirents, i )
                 print '%4.4s %s' % (kind_map[ entry.kind() ], entry.name())
                 print ' %d %s %s %d' % ( entry.createdRev(),
entry.lastAuthor(),
                         time.strftime( '%d-%b-%Y %H:%M:%S',
                                 time.localtime( svncpp.pyTimeFromAprTime(
entry.time() ) ) ),
                         long(svncpp.pyFileSizeFromSvnFileSize(
entry.size() )))

if __name__ == '__main__':
         main( sys.argv )
------------------------- end ----------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Thu Oct 16 23:09:14 2003

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.