Exemplo n.º 1
0
 def create_dataprovider(self):
     self.folder = Utils.new_tempdir()
     dp = self.klass()
     dp.set_configuration({
         "folder": self.folder,
     })
     return dp
Exemplo n.º 2
0
 def __init__(self, *args):
     #Put a single tempfile into a tempdir
     FileDataProvider.FolderTwoWay.__init__(self,
                                            folder="file://" +
                                            Utils.new_tempdir(),
                                            folderGroupName="Test",
                                            includeHidden=False,
                                            compareIgnoreMtime=False,
                                            followSymlinks=False)
Exemplo n.º 3
0
 def __init__(self, *args):
     #Put a single tempfile into a tempdir
     FileDataProvider.FolderTwoWay.__init__(
                         self,
                         folder= "file://"+Utils.new_tempdir(),
                         folderGroupName="Test",
                         includeHidden=False,
                         compareIgnoreMtime=False,
                         followSymlinks=False
                         )
Exemplo n.º 4
0
    def __init__(self, *args):
        #Put photos into the users Pictures dir
        pdir = Utils.exec_command_and_return_result("xdg-user-dir", "PICTURES")
        if pdir:
            folder = "file://" + pdir.strip()
        else:
            folder = "file://" + Utils.new_tempdir()

        log.info("Storing pictures in %s" % folder)

        FileDataProvider.FolderTwoWay.__init__(self,
                                               folder=folder,
                                               folderGroupName="Pictures",
                                               includeHidden=False,
                                               compareIgnoreMtime=False,
                                               followSymlinks=False)

        if WPTYPE == WPGNOME:
            self._client = gconf.client_get_default()
Exemplo n.º 5
0
    def __init__(self, *args):
        #Put photos into the users Pictures dir
        pdir = Utils.exec_command_and_return_result("xdg-user-dir", "PICTURES")
        if 1:
            folder = "file://"+pdir.strip()
        else:
            folder = "file://"+Utils.new_tempdir()

        log.info("Storing pictures in %s" % folder)

        FileDataProvider.FolderTwoWay.__init__(
                            self,
                            folder=folder,
                            folderGroupName="Pictures",
                            includeHidden=False,
                            compareIgnoreMtime=False,
                            followSymlinks=False
                            )

        self._client = gconf.client_get_default()
Exemplo n.º 6
0
 def __init__(self, *args):
     _TestBase.__init__(self)
     DataProvider.DataSink.__init__(self)
     self.folder = "file://"+Utils.new_tempdir()
Exemplo n.º 7
0
safe = '/&=:@'
unsafe = ' !<>#%()[]{}'
safeunsafe = '%20%21%3C%3E%23%25%28%29%5B%5D%7B%7D'

ok("Dont escape path characters",Vfs.uri_escape(safe+unsafe) == safe+safeunsafe)
ok("Unescape back to original",Vfs.uri_unescape(safe+safeunsafe) == safe+unsafe)
ok("Get protocol", Vfs.uri_get_protocol("file:///foo/bar") == "file://")
name, ext = Vfs.uri_get_filename_and_extension("file:///foo/bar.ext")
ok("Get filename (%s,%s)" % (name,ext), name == "bar" and ext == ".ext")
ok("file:///home exists", Vfs.uri_exists("file:///home") == True)
ok("/home exists", Vfs.uri_exists("/home") == True)
ok("/home is folder", Vfs.uri_is_folder("/home") == True)
ok("/foo/bar does not exist", Vfs.uri_exists("/foo/bar") == False)
ok("format uri", Vfs.uri_format_for_display("file:///foo") == "/foo")

tmpdiruri = Utils.new_tempdir()

# Test the folder scanner theading stuff
fileuri = Utils.new_tempfile("bla").get_local_uri()
stm = VfsFile.FolderScannerThreadManager(maxConcurrentThreads=1)

def prog(*args): pass
def done(*args): pass

t1 = stm.make_thread("file:///tmp", False, False, prog, done)
t2 = stm.make_thread("file://"+tmpdiruri, False, False, prog, done)
stm.join_all_threads()

ok("Scanned /tmp ok - found %s" % fileuri, "file://"+fileuri in t1.get_uris())
ok("Scanned %s ok (empty)" % tmpdiruri, t2.get_uris() == [])
Exemplo n.º 8
0
null = File.File("/foo/bar")
ok("Base: non-existant file", null.exists() == False)

# test tempfile handling
temp = Utils.new_tempfile(Utils.random_string())
ok("Base: Detected tempfile", temp.is_local() and temp._is_tempfile())

uri = temp.get_local_uri()
ok("Base: Tempfile in temp dir", uri and uri.startswith(tempfile.gettempdir()))

temp.delete()
gone = File.File(uri)
ok("Base: Delete tempfile", not gone.exists())

# test making directories
tmpdir = Utils.new_tempdir()
tmpdir2 = os.path.join(tmpdir, "subdir")
f = File.File(tmpdir2)
ok("Base: make directory", f.make_directory() == True)

temp = Utils.new_tempfile(Utils.random_string())
temp.set_contents_as_text("123")
contents = temp.get_contents_as_text()
ok("Base: wrote contents", contents == "123")

temp.set_contents_as_text("456")
contents = temp.get_contents_as_text()
ok("Base: wrote contents again", contents == "456")

# write a random amount to the temp file
Exemplo n.º 9
0
#common sets up the conduit environment
    
from common import *

import threading
import os.path
import shutil
import traceback

import conduit.modules.iPodModule.iPodModule as iPodModule
import conduit.utils as Utils


#simulate an ipod
fakeIpodDir = Utils.new_tempdir()
ok("Created fake ipod at %s" % fakeIpodDir, os.path.exists(fakeIpodDir))

ipodNoteDp = iPodModule.IPodNoteTwoWay(fakeIpodDir,"")
ipodContactsDp = iPodModule.IPodContactsTwoWay(fakeIpodDir,"")
ipodCalendarDp = iPodModule.IPodCalendarTwoWay(fakeIpodDir,"")
ipodPhotoDp = iPodModule.IPodPhotoSink(fakeIpodDir,"")
ipodMusicDp = iPodModule.IPodMusicTwoWay(None,"")

#The ipod photo (and music AFAICT) require some initialization of 
#a skeleton database file. 
#This code, and example resources are taken from libgpod test suite
control_dir = os.path.join(fakeIpodDir,'iPod_Control')
photo_dir = os.path.join(control_dir, 'Photos')
shutil.copytree(
            os.path.join(get_data_dir(),'resources-ipod'),
            control_dir
Exemplo n.º 10
0
    f.write(Utils.random_string())
    f.close()
    return name,uri

#Test removable volume support
removableUri = get_external_resources('folder')['removable-volume']
ok("Is on a removable volume", FileDataProvider.is_on_removable_volume(removableUri))

#save and restore a group
groupInfo = (removableUri, GROUP_NAME)
ok("Save group info", FileDataProvider.save_removable_volume_group_file(*groupInfo))
readInfo = FileDataProvider.read_removable_volume_group_file(removableUri)
ok("Read group info (%s)" % str(readInfo), len(readInfo) > 0 and readInfo[0][1] == GROUP_NAME)

#create some test directories
dpdir = "file://"+Utils.new_tempdir()
tempdir = "file://"+Utils.new_tempdir()
tempdir2 = Vfs.uri_join(tempdir, NESTED_DIR_NAME)
Vfs.uri_make_directory(tempdir2)
#create some test files
f1Name, f1URI = create_file(tempdir)
f2Name, f2URI = create_file(tempdir2)
#create a test dataprovider
dp = FileDataProvider.FolderTwoWay(
            folder=dpdir,
            folderGroupName=GROUP_NAME,
            includeHidden=False,
            compareIgnoreMtime=False,
            followSymlinks=False)

# Scenario 1)
Exemplo n.º 11
0
#common sets up the conduit environment
from common import *

import conduit.Vfs as Vfs
import conduit.utils as Utils
import conduit.datatypes.File as File

import time
import os.path

#Get a giant list of many music files
music = open(
            os.path.join(get_data_dir(), "music-list.txt"),
            "r")

sourceDir = Utils.new_tempdir()
sinkDir = Utils.new_tempdir()
lines = [Vfs.uri_join(sourceDir, l[0:-1]) for l in music]
dirs = {}

for l in lines:
    dirs[os.path.dirname(l)] = True

#make all the directories for these files
for d in dirs:  
    f = File.File(d)
    f.make_directory_and_parents()

#leaving only files behind
for d in dirs:
    try:
Exemplo n.º 12
0
#setup the conduit
test = SimpleSyncTest()
sourceW = test.get_dataprovider("TomboyNoteTwoWay")
sinkW = test.get_dataprovider("FolderTwoWay")
test.prepare(sourceW, sinkW)
test.set_two_way_policy({"conflict":"ask","deleted":"ask"})

#check if tomboy running
tomboy = sourceW.module
if not Utils.dbus_service_available(tomboy.TOMBOY_DBUS_IFACE):
    skip("tomboy not running")

#configure the source and sink
config = {}
config["folder"] = "file://"+Utils.new_tempdir()
config["folderGroupName"] = "Tomboy"
test.configure(sink=config)

#check they refresh ok
test.refresh()
a = test.get_source_count()
ok("Got notes to sync (%s)" % a, a > 0)

#sync
test.set_two_way_sync(True)
a,b = test.sync()
abort,error,conflict = test.get_sync_result()
ok("Sync completed", abort == False)
ok("All notes transferred (%s,%s)" % (a,b), a == b)
Exemplo n.º 13
0
 def create_dataprovider(self):
     self.folder = Utils.new_tempdir()
     path = os.path.join(self.folder, self.klass.DEFAULT_FOLDER)
     if not os.path.exists(path):
         os.mkdir(path)
     return self.klass(self.folder, str(uuid.uuid4()))
Exemplo n.º 14
0
(SAFE_CONTACT_URI,      new_contact,            "EvoContactTwoWay"),
(SAFE_CALENDAR_URI,     new_event,              "EvoCalendarTwoWay"),
(SAFE_TASK_URI,         new_event,              "EvoTasksTwoWay"),
)

for uri, newdata_func, name in TESTS:
    #setup the conduit
    test = SimpleSyncTest()
    test.prepare(
            source=test.get_dataprovider(name),
            sink=test.get_dataprovider("FolderTwoWay")
            )
    test.set_two_way_policy({"conflict":"ask","deleted":"ask"})

    #configure the source and sink
    test.configure(
            source={"sourceURI":uri},
            sink={"folder":"file://"+Utils.new_tempdir()}
            )
    test.set_two_way_sync(True)

    a = test.get_source_count()
    ok("%s: %s items to sync" % (name, a), a > 0)
    
    #sync
    test.sync()
    abort,error,conflict = test.get_sync_result()
    ok("%s: sync completed" % name, abort == False and error == False and conflict == False)

finished()
Exemplo n.º 15
0
 def __init__(self, *args):
     DataProvider.DataSink.__init__(self, *args)
     _TestBase.__init__(self)
     self.folder = "file://" + Utils.new_tempdir()
Exemplo n.º 16
0
 def create_dataprovider(self):
     import gpod
     self.folder = Utils.new_tempdir()
     assert gpod.gpod.itdb_init_ipod(self.folder, "MA450", "Test iPod", None)
     return self.klass(self.folder, str(uuid.uuid4()))