Exemplo n.º 1
0
//
//    Return true to cancel a long running operation
//
bool pysvn_context::contextCancel()
{
    PythonDisallowThreads callback_permission( m_permission );

    // make sure we can call the users object
    if( !m_pyfn_Cancel.isCallable() )
        return false;

    Py::Callable callback( m_pyfn_Cancel );

    Py::Tuple args( 0 );

    // bool
    Py::Object result;

    Py::Int retcode;

    try
    {
        result = callback.apply( args );
        retcode = result;

        return long( retcode ) != 0;
    }
    catch( Py::Exception &e )
    {
        PyErr_Print();
        e.clear();

        m_error_message = "unhandled exception in callback_cancel";

        return false;
    }
}
Exemplo n.º 2
0
//
// this method will be called to retrieve
// a log message
//
bool pysvn_context::contextGetLogMessage( std::string & a_msg )
{
    if( !m_log_message.empty() )
    {
        a_msg = m_log_message;
        m_log_message.erase();

        return true;
    }

    PythonDisallowThreads callback_permission( m_permission );

    if( !m_pyfn_GetLogMessage.isCallable() )
    {
        m_error_message = "callback_get_log_message required";
        return false;
    }

    Py::Tuple args( 0 );
    try
    {
        return get_string( m_pyfn_GetLogMessage, args, a_msg );
    }
    catch( Py::Exception &e )
    {
        PyErr_Print();
        e.clear();

        m_error_message = "unhandled exception in callback_get_log_message";
    }

    return false;
}
Exemplo n.º 3
0
void pysvn_context::contextProgress
(
    apr_off_t progress,
    apr_off_t total
)
{
    PythonDisallowThreads callback_permission( m_permission );

    // make sure we can call the users object
    if( !m_pyfn_Progress.isCallable() )
        return;

    Py::Callable callback( m_pyfn_Progress );

    Py::Tuple args( 2 );
    // on some platforms apr_off_t is int64
    args[0] = Py::Int( static_cast<long int>( progress ) );
    args[1] = Py::Int( static_cast<long int>( total ) );

    Py::Object results;

    try
    {
        results = callback.apply( args );
    }
    catch( Py::Exception &e )
    {
        PyErr_Print();
        e.clear();

        m_error_message = "unhandled exception in callback_progress";
    }
}
svn_error_t *changelistReceiver
    (
    void *baton_,
    const char *path,
    const char *changelist,
    apr_pool_t *pool
    )
{
    ChangelistBaton *baton = reinterpret_cast<ChangelistBaton *>( baton_ );

    PythonDisallowThreads callback_permission( baton->m_permission );

    if( path == NULL || changelist == NULL )
    {
        return NULL;
    }

    Py::Tuple values( 2 );
    values[0] = Py::String( path );
    values[1] = Py::String( changelist );

    baton->m_changelist_list.append( values );

    return NULL;
}
Exemplo n.º 5
0
static svn_error_t *info_receiver_c( void *baton_, const char *path, const svn_info_t *info, apr_pool_t *pool )
{
    InfoReceiveBaton *baton = reinterpret_cast<InfoReceiveBaton *>( baton_ );

    PythonDisallowThreads callback_permission( baton->m_permission );

    if( path != NULL )
    {
        std::string std_path( path );
        if( std_path.empty() )
        {
            std_path = ".";
        }
        Py::String py_path( std_path );

        Py::Tuple py_pair( 2 );
        py_pair[0] = py_path;
        py_pair[1] = toObject(
                    *info,
                    baton->m_wrapper_info,
                    baton->m_wrapper_lock,
                    baton->m_wrapper_wc_info );

        baton->m_info_list.append( py_pair );
    }

    return SVN_NO_ERROR;
}
Exemplo n.º 6
0
//
// this method is called to retrieve the password
// for the certificate
//
// @param password
//
bool pysvn_context::contextSslClientCertPwPrompt
(
    std::string &_password,
    const std::string &_realm,
    bool &_may_save
)
{
    PythonDisallowThreads callback_permission( m_permission );

    // make sure we can call the users object
    if( !m_pyfn_SslClientCertPwPrompt.isCallable() )
    {
        m_error_message = "callback_ssl_client_cert_password_prompt required";

        return false;
    }

    Py::Callable callback( m_pyfn_SslClientCertPwPrompt );

    Py::Tuple args( 2 );
    args[0] = Py::String( _realm );
    args[1] = Py::Int( (long)_may_save );

    // bool, username, password
    Py::Tuple results;
    Py::Int retcode;
    Py::String username;
    Py::String password;
    Py::Int may_save_out;

    try
    {
        results = callback.apply( args );
        retcode = results[0];
        password = results[1];
        may_save_out = results[2];

        // true returned
        if( long( retcode ) != 0 )
        {
            // copy out the answers
            _password = password.as_std_string();
            _may_save = long( may_save_out ) != 0;

            return true;
        }
    }
    catch( Py::Exception &e )
    {
        PyErr_Print();
        e.clear();

        m_error_message = "unhandled exception in callback_ssl_client_cert_password_prompt";

        return false;
    }

    return false;
}
Exemplo n.º 7
0
void pysvn_context::contextNotify2
(
    const svn_wc_notify_t *notify,
    apr_pool_t *pool
)
{
    PythonDisallowThreads callback_permission( m_permission );

    // make sure we can call the users object
    if( !m_pyfn_Notify.isCallable() )
        return;

    Py::Callable callback( m_pyfn_Notify );

    Py::Tuple args( 1 );
    Py::Dict info;
    args[0] = info;

    info["path"] = Py::String( notify->path );
    info["action"] = toEnumValue( notify->action );
    info["kind"] = toEnumValue( notify->kind );
    if( notify->mime_type == NULL )
        info["mime_type"] = Py::Nothing();
    else
        info["mime_type"] = Py::String( notify->mime_type );
    info["content_state"] = toEnumValue( notify->content_state );
    info["prop_state"] = toEnumValue( notify->prop_state );
    info["revision"] = Py::asObject( new pysvn_revision( svn_opt_revision_number, 0, notify->revision ) );
    if( notify->err != NULL )
    {
        SvnException error( notify->err );
        info["error"] = error.pythonExceptionArg( 1 );
    }
    else
    {
        info["error"] = Py::None();
    }

    Py::Object results;

    try
    {
        results = callback.apply( args );
    }
    catch( Py::Exception &e )
    {
        PyErr_Print();
        e.clear();

        m_error_message = "unhandled exception in callback_notify";
    }
}
Exemplo n.º 8
0
//
// this method is called to retrieve client side
// information
//
bool pysvn_context::contextSslClientCertPrompt( std::string &_cert_file, const std::string &_realm, bool &_may_save )
{
    PythonDisallowThreads callback_permission( m_permission );

    if( !m_pyfn_SslClientCertPrompt.isCallable() )
    {
        m_error_message = "callback_ssl_client_cert_prompt required";

        return false;
    }

    Py::Callable callback( m_pyfn_SslClientCertPrompt );

    Py::Tuple args( 2 );
    args[0] = Py::String( _realm );
    args[1] = Py::Int( _may_save );

    Py::Tuple results;
    Py::Int retcode;
    Py::String cert_file;
    Py::Int may_save_out;

    try
    {
        results = callback.apply( args );
        retcode = results[0];
        cert_file = results[1];
        may_save_out = results[2];

        if( long( retcode ) != 0 )
        {
            _cert_file = cert_file.as_std_string();
            _may_save = long( may_save_out ) != 0;

            return true;
        }
    }
    catch( Py::Exception &e )
    {
        PyErr_Print();
        e.clear();

        m_error_message = "unhandled exception in callback_ssl_client_cert_prompt";

        return false;
    }

    return false;
}
Exemplo n.º 9
0
void pysvn_context::contextNotify
(
    const char *path,
    svn_wc_notify_action_t action,
    svn_node_kind_t kind,
    const char *mime_type,
    svn_wc_notify_state_t content_state,
    svn_wc_notify_state_t prop_state,
    svn_revnum_t revnum
)
{
    PythonDisallowThreads callback_permission( m_permission );

    // make sure we can call the users object
    if( !m_pyfn_Notify.isCallable() )
        return;

    Py::Callable callback( m_pyfn_Notify );

    Py::Tuple args( 1 );
    Py::Dict info;
    args[0] = info;

    info["path"] = Py::String( path );
    info["action"] = toEnumValue( action );
    info["kind"] = toEnumValue( kind );
    if( mime_type == NULL )
        info["mime_type"] = Py::Nothing();
    else
        info["mime_type"] = Py::String( mime_type );
    info["content_state"] = toEnumValue( content_state );
    info["prop_state"] = toEnumValue( prop_state );
    info["revision"] = Py::asObject( new pysvn_revision( svn_opt_revision_number, 0, revnum ) );

    Py::Object results;

    try
    {
        results = callback.apply( args );
    }
    catch( Py::Exception &e )
    {
        PyErr_Print();
        e.clear();

        m_error_message = "unhandled exception in callback_notify";
    }
}
Exemplo n.º 10
0
    svn_error_t *proplist_receiver_c
    (
        void *baton_,
        const char *path,
        apr_hash_t *prop_hash,
        apr_pool_t *pool
    )
    {
        ProplistReceiveBaton *baton = reinterpret_cast<ProplistReceiveBaton *>( baton_ );

        PythonDisallowThreads callback_permission( baton->m_permission );

        Py::Dict prop_dict;

        Py::Tuple py_tuple( 2 );
        py_tuple[0] = Py::String( path );
        py_tuple[1] = propsToObject( prop_hash, baton->m_pool );

        baton->m_prop_list.append( py_tuple );

        return SVN_NO_ERROR;
    }
Exemplo n.º 11
0
svn_error_t *diff_summarize_c
    (
    const svn_client_diff_summarize_t *diff,
    void *baton_,
    apr_pool_t *pool
    )
{
    DiffSummarizeBaton *baton = reinterpret_cast<DiffSummarizeBaton *>( baton_ );

    PythonDisallowThreads callback_permission( baton->m_permission );

    Py::Dict diff_dict;

    diff_dict[ *py_name_path ] = Py::String( diff->path, name_utf8 );
    diff_dict[ *py_name_summarize_kind ] = toEnumValue( diff->summarize_kind );
    diff_dict[ *py_name_prop_changed ] = Py::Int( diff->prop_changed != 0 );
    diff_dict[ *py_name_node_kind ] = toEnumValue( diff->node_kind );

    baton->m_diff_list.append( baton->m_wrapper_diff_summary->wrapDict( diff_dict ) );

    return SVN_NO_ERROR;
}
Exemplo n.º 12
0
svn_error_t *list_receiver_c
    (
    void *baton_,
    const char *path,
    const svn_dirent_t *dirent,
    const svn_lock_t *lock,
    const char *abs_path,
    apr_pool_t *pool
    )
{
    ListReceiveBaton *baton = reinterpret_cast<ListReceiveBaton *>( baton_ );

    PythonDisallowThreads callback_permission( baton->m_permission );

    std::string full_path( baton->m_url_or_path );
    std::string full_repos_path( abs_path );
    if( strlen( path ) != 0 )
    {
        full_path += "/";
        full_path += path;

        full_repos_path += "/";
        full_repos_path += path;
    }

    Py::Tuple py_tuple( 2 );

    Py::Dict entry_dict;
    entry_dict[ *py_name_path ] = Py::String( full_path, name_utf8 );
    entry_dict[ *py_name_repos_path ] = Py::String( full_repos_path, name_utf8 );

    if( dirent != NULL )
    {
        if( baton->m_dirent_fields&SVN_DIRENT_KIND )
        {
            entry_dict[ *py_name_kind ] = toEnumValue( dirent->kind );
        }
        if( baton->m_dirent_fields&SVN_DIRENT_SIZE )
        {
            entry_dict[ *py_name_size ] = Py::Long( Py::Float( double( static_cast<signed_int64>( dirent->size ) ) ) );
        }
        if( baton->m_dirent_fields&SVN_DIRENT_CREATED_REV )
        {
            entry_dict[ *py_name_created_rev ] = Py::asObject( new pysvn_revision( svn_opt_revision_number, 0, dirent->created_rev ) );
        }
        if( baton->m_dirent_fields&SVN_DIRENT_TIME )
        {
            entry_dict[ *py_name_time ] = toObject( dirent->time );
        }
        if( baton->m_dirent_fields&SVN_DIRENT_HAS_PROPS )
        {
            entry_dict[ *py_name_has_props ] = Py::Int( dirent->has_props );
        }
        if( baton->m_dirent_fields&SVN_DIRENT_LAST_AUTHOR )
        {
            entry_dict[ *py_name_last_author ] = utf8_string_or_none( dirent->last_author );
        }
    }
    py_tuple[0] = baton->m_wrapper_list->wrapDict( entry_dict );

    if( lock == NULL )
    {
        py_tuple[1] = Py::None();
    }
    else
    {
        py_tuple[1] = toObject( *lock, *baton->m_wrapper_lock );
    }
    baton->m_list_list.append( py_tuple );

    return SVN_NO_ERROR;
}
Exemplo n.º 13
0
//
// this method is called if there is ssl server
// information, that has to be confirmed by the user
//
// @param data
// @return @a SslServerTrustAnswer
//
bool pysvn_context::contextSslServerTrustPrompt
(
    const svn_auth_ssl_server_cert_info_t &info,
    const std::string &realm,
    apr_uint32_t &a_accepted_failures,
    bool &accept_permanent
)
{
    PythonDisallowThreads callback_permission( m_permission );

    // make sure we can call the users object
    if( !m_pyfn_SslServerTrustPrompt.isCallable() )
    {
        m_error_message = "callback_ssl_server_trust_prompt required";

        return false;
    }

    Py::Callable callback( m_pyfn_SslServerTrustPrompt );

    Py::Dict trust_info;
    trust_info[Py::String("failures")] = Py::Int( long( a_accepted_failures ) );
    trust_info[Py::String("hostname")] = Py::String( info.hostname );
    trust_info[Py::String("finger_print")] = Py::String( info.fingerprint );
    trust_info[Py::String("valid_from")] = Py::String( info.valid_from );
    trust_info[Py::String("valid_until")] = Py::String( info.valid_until );
    trust_info[Py::String("issuer_dname")] = Py::String( info.issuer_dname );
    trust_info[Py::String("realm")] = Py::String( realm );

    Py::Tuple args( 1 );
    args[0] = trust_info;

    Py::Tuple result_tuple;
    Py::Int retcode;
    Py::Int accepted_failures;
    Py::Int may_save;

    try
    {
        result_tuple = callback.apply( args );
        retcode = result_tuple[0];
        accepted_failures = result_tuple[1];
        may_save = result_tuple[2];

        a_accepted_failures = long( accepted_failures );
        if( long( retcode ) != 0 )
        {
            accept_permanent = long( may_save ) != 0;
            return true;
        }
        else
            return false;
    }
    catch( Py::Exception &e )
    {
        PyErr_Print();
        e.clear();

        m_error_message = "unhandled exception in callback_ssl_server_trust_prompt";
    }

    return false;
}
Exemplo n.º 14
0
static svn_error_t *log4Receiver
    (
    void *baton_,
    svn_log_entry_t *log_entry,
    apr_pool_t *pool
    )
{
    Log4Baton *baton = reinterpret_cast<Log4Baton *>( baton_ );

    if( log_entry->revision == 0 )
    {
        // skip this blank entry
        // as the svn log command does
        return NULL;
    }

    PythonDisallowThreads callback_permission( baton->m_permission );

    Py::Dict entry_dict;

    Py::Object revprops;
    if( log_entry->revprops == NULL )
    {
        revprops = Py::None();
    }
    else
    {
        revprops = propsToObject( log_entry->revprops, baton->m_pool );
        Py::Dict revprops_dict;
        revprops_dict = revprops;

        if( revprops_dict.hasKey( "svn:date" ) )
        {
            Py::String date( revprops_dict[ "svn:date" ] );
            Py::Object int_date = toObject( convertStringToTime( date.as_std_string( g_utf_8 ), baton->m_now, baton->m_pool ) );
            revprops_dict[ "svn:date" ] = int_date;
            entry_dict[ name_date ] = int_date;
        }
        if( revprops_dict.hasKey( "svn:author" ) )
        {
            entry_dict[ name_author ] = revprops_dict[ "svn:author" ];
        }
        if( revprops_dict.hasKey( "svn:log" ) )
        {
            Py::String message( revprops_dict[ "svn:log" ] );
            revprops_dict[ "svn:log" ] = message;
            entry_dict[ name_message ] = message;
        }
    }
    entry_dict[ name_revprops ] = revprops;
    entry_dict[ name_revision ] = Py::asObject( new pysvn_revision( svn_opt_revision_number, 0, log_entry->revision ) );

    Py::List changed_paths_list;
#if defined( PYSVN_HAS_CLIENT_LOG5 )
    if( log_entry->changed_paths2 != NULL )
    {
        for( apr_hash_index_t *hi = apr_hash_first( pool, log_entry->changed_paths2 );
                hi != NULL;
                    hi = apr_hash_next( hi ) )
        {
            Py::Dict changed_entry_dict;

            char *path = NULL;
            void *val = NULL;
            apr_hash_this( hi, (const void **) &path, NULL, &val );

            svn_log_changed_path_t *log_item = reinterpret_cast<svn_log_changed_path_t *> (val);

            changed_entry_dict[ name_path ] = Py::String( path );

            char action[2]; action[0] = log_item->action; action[1] = 0;
            changed_entry_dict[ name_action ] = Py::String( action );

            changed_entry_dict[ name_copyfrom_path ] = utf8_string_or_none( log_item->copyfrom_path );

            if( SVN_IS_VALID_REVNUM( log_item->copyfrom_rev ) )
                changed_entry_dict[ name_copyfrom_revision ] =
                    Py::asObject( new pysvn_revision( svn_opt_revision_number, 0, log_item->copyfrom_rev ) );
            else
                changed_entry_dict[ name_copyfrom_revision ] = Py::None();

            changed_paths_list.append( baton->m_wrapper_log_changed_path->wrapDict( changed_entry_dict ) );
        }
    }
#else
    if( log_entry->changed_paths != NULL )
    {
        for( apr_hash_index_t *hi = apr_hash_first( pool, log_entry->changed_paths );
                hi != NULL;
                    hi = apr_hash_next( hi ) )
        {
            Py::Dict changed_entry_dict;

            char *path = NULL;
            void *val = NULL;
            apr_hash_this( hi, (const void **) &path, NULL, &val );

            svn_log_changed_path_t *log_item = reinterpret_cast<svn_log_changed_path_t *> (val);

            changed_entry_dict[ name_path ] = Py::String( path );

            char action[2]; action[0] = log_item->action; action[1] = 0;
            changed_entry_dict[ name_action ] = Py::String( action );

            changed_entry_dict[ name_copyfrom_path ] = utf8_string_or_none( log_item->copyfrom_path );

            if( SVN_IS_VALID_REVNUM( log_item->copyfrom_rev ) )
                changed_entry_dict[ name_copyfrom_revision ] =
                    Py::asObject( new pysvn_revision( svn_opt_revision_number, 0, log_item->copyfrom_rev ) );
            else
                changed_entry_dict[ name_copyfrom_revision ] = Py::None();

            changed_paths_list.append( baton->m_wrapper_log_changed_path->wrapDict( changed_entry_dict ) );
        }
    }
#endif

    entry_dict[ name_changed_paths ] = changed_paths_list;
    entry_dict[ "has_children" ] = Py::Int( log_entry->has_children != 0 ? 1 : 0 );

    baton->m_log_list.append( baton->m_wrapper_log->wrapDict( entry_dict ) );

    return NULL;
}