Hello,

as I wrote earlier today, I'm unable to copy a file in async mode with
the methods provided by Gio (via introspection).
So I'm trying to workaround this problem with other functions. At the
bottom of this mail, is the best I came to.
Unfortunately, it doesn't work: after running it, the target file starts
with some characters of garbage (which change from execution to
execution!) - the rest of the original file is copied correctly.

I'm really clueless, any help is appreciated.

Pietro

----8<--------8<--------8<--------8<--------8<--------8<--------8<----

#! /usr/bin/python

import sys
from gi.repository import Gio, GLib


class Uploader(object):
    def read(self):
        self.f = Gio.file_new_for_commandline_arg( '/tmp/first' )
        self.f.load_contents_async( None, self.read_finished, None )
    
    def read_finished( self, gdaemonfile, result, data ):
        self.content = self.f.load_contents_finish( result )[1]
        print self.content
#        self.g =
Gio.file_new_for_uri( 'file:///home/pietro/cancellami/pippopippo2' )
#        self.g.delete( None )
        self.g = Gio.file_new_for_uri( 'file:///tmp/second' )
        self.g.create_async( 0, GLib.PRIORITY_DEFAULT, None,
self.created, None )
    
    def created(self, gdaemonfile, result, data):
        self.stream = self.g.create_finish( result )
        self.stream.write_async( self.content, GLib.PRIORITY_DEFAULT,
None, self.written, None )
    
    def written(self, gdaemonfile, result, data):
        print self.stream.write_finish( result )
        self.loop.quit()


u = Uploader()
GLib.timeout_add(10, u.read)
u.loop = GLib.MainLoop()
u.loop.run()

----8<--------8<--------8<--------8<--------8<--------8<--------8<----



_______________________________________________
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Reply via email to