Ejemplo n.º 1
0
 def __init__(self, *args):
     N800Base.__init__(
                 self,
                 mount=args[0],
                 udi=args[1],
                 folder=Vfs.uri_join(args[0],self.DEFAULT_FOLDER)
                 )
Ejemplo n.º 2
0
def create_file(inDirURI):
    name = Utils.random_string()+".txt"
    uri = Vfs.uri_join(inDirURI.replace("file://",""),name)
    f = open(uri,'w')
    f.write(Utils.random_string())
    f.close()
    return name,uri
Ejemplo n.º 3
0
 def __init__(self, *args):
     N800Base.__init__(self,
                       mount=args[0],
                       udi=args[1],
                       folder=Vfs.uri_join(args[0], self.DEFAULT_FOLDER))
     self.encodings = Video.PRESET_ENCODINGS.copy()
     self.encoding = "ogg"
Ejemplo n.º 4
0
 def __init__(self, *args):
     N800Base.__init__(
                 self,
                 mount=args[0],
                 udi=args[1],
                 folder=Vfs.uri_join(args[0],self.DEFAULT_FOLDER)
                 )
     self.encodings =  Video.PRESET_ENCODINGS.copy()
     self.encoding = "ogg"
Ejemplo n.º 5
0
 def __init__(self, *args):
     N800Base.__init__(self,
                       mount=args[0],
                       udi=args[1],
                       folder=Vfs.uri_join(args[0], self.DEFAULT_FOLDER))
     self.encodings = Photo.PRESET_ENCODINGS.copy()
     #Add size = 800x480 to the default photo encodings
     for k in self.encodings.keys():
         self.encodings[k]['size'] = '800x480'
     self.encoding = "jpeg"
Ejemplo n.º 6
0
 def __init__(self, *args):
     N800Base.__init__(
                 self,
                 mount=args[0],
                 udi=args[1],
                 folder=Vfs.uri_join(args[0],self.DEFAULT_FOLDER)
                 )
     self.encodings =  Photo.PRESET_ENCODINGS.copy()
     #Add size = 800x480 to the default photo encodings
     for k in self.encodings.keys():
         self.encodings[k]['size'] = '800x480'
     self.encoding = "jpeg"
Ejemplo n.º 7
0
def get_removable_volume_info(f):
    """
    Returns the root uri of the volume, and local path of the 
    group config file
    """
    rooturi = f.get_removable_volume_root_uri()
    if rooturi:
        path = Vfs.uri_to_local_path(rooturi)
        if path:
            path = Vfs.uri_join(path, ".conduit")
            return rooturi, path
    return None, None
Ejemplo n.º 8
0
def get_removable_volume_info(f):
    """
    Returns the root uri of the volume, and local path of the 
    group config file
    """
    rooturi = f.get_removable_volume_root_uri()
    if rooturi:
        path = Vfs.uri_to_local_path(rooturi)
        if path:
            path = Vfs.uri_join(path, ".conduit")
            return rooturi,path
    return None,None
Ejemplo n.º 9
0
    ok("Removable volume detected removable", Vfs.uri_is_on_removable_volume(removableUri))
    ok("Removable volume calculate root path", Vfs.uri_get_volume_root_uri(removableUri).startswith("file:///media/"))

URIS_TO_JOIN = (
    (   ("file:///foo/bar","gax","ssss"),   
        "file:///foo/bar/gax/ssss"),
    (   ("smb://192.168.1.1","Disk-2","Travel%20Videos/","Switzerland"),
        "smb://192.168.1.1/Disk-2/Travel%20Videos/Switzerland"),
    (   ("ssh://[email protected]/home","john","phd"),
        "ssh://[email protected]/home/john/phd"),
    (   ("foo","bar","baz"),
        "foo/bar/baz")
)

for parts, result in URIS_TO_JOIN:
    got = Vfs.uri_join(*parts)
    ok("Join uri: %s" % result, got == result)
    
RELATIVE_URIS = (
    #from                   #to                         #relativ    
(   "file:///foo/bar",      "file:///baz/bob",          "file:///baz/bob"   ),
(   "file:///foo/bar",      "file:///foo/bar/baz/bob",  "baz/bob"           ),
(   "file:///foo/bar",      "file:///foo/bar/baz",      "baz"               ))
for f,t,result in RELATIVE_URIS:
    got = Vfs.uri_get_relative(f,t)
    ok("Get relative uri: %s" % result, got == result)
    
VALID_URIS = (
    #uri                                #valid
(   "smb://192.168.1.1/foo/bar",        True                        ),
(   "ftp://192.168.1.1/foo/bar",        True                        ),
Ejemplo n.º 10
0
    def put(self, vfsFile, overwrite, LUID=None):
        """
        Puts vfsFile at the correct location. There are three scenarios
        1) File came from a foreign DP like tomboy
        2) File came from another file dp

        Behaviour:
        1) The foreign DP should have encoded enough information (such as
        the filename) so that we can go ahead and put the file in the dir
        2) First we see if the file has a group attribute.
            a) If so, and the group matches the groupName here then we 
            put the files into the directory.
            b) If not we put the file in a subdir by the name of the group 
            
        We always retain the relative path for the files
        """
        DataProvider.TwoWay.put(self, vfsFile, overwrite, LUID)
        newURI = ""
        if LUID != None:
            newURI = LUID
        elif vfsFile.basePath == "":
            #came from another type of dataprovider such as tomboy
            #where relative path makes no sense. Could also come from
            #the FileSource dp when the user has selected a single file
            log.debug("No basepath. Going to empty dir")
            newURI = Vfs.uri_join(self.folder, vfsFile.get_filename())
        else:
            #Look for corresponding groups
            relpath = vfsFile.get_relative_uri()
            log.debug("Relative path: %s" % relpath)
            if self.folderGroupName == vfsFile.group:
                log.debug("Found corresponding group")
                #put in the folder
                newURI = Vfs.uri_join(self.folder, relpath)
            else:
                log.debug("Recreating group: %s" % vfsFile.group)
                #unknown. Store in the dir but recreate the group
                newURI = Vfs.uri_join(self.folder, vfsFile.group, relpath)

        #escape illegal filesystem characters
        if self.fstype:
            newURI = Vfs.uri_sanitize_for_filesystem(newURI, self.fstype)

        #overwrite is the easy case, as for it to be true, requires specific user
        #interaction
        if overwrite == True:
            self._transfer_file(vfsFile, newURI, overwrite)
        else:
            #check for conflicts
            destFile = File.File(URI=newURI)
            if destFile.exists():
                comp = vfsFile.compare(destFile,
                                       sizeOnly=self.compareIgnoreMtime)

                if LUID != None and comp == DataType.COMPARISON_NEWER:
                    #we were expecting an existing file, we found it, but
                    #we are newer, so overwrite it
                    self._transfer_file(vfsFile, newURI, True)
                elif comp == DataType.COMPARISON_EQUAL:
                    #in File.compare, the files are compared based on size, if
                    #their mtimes are the same, so this case is true when
                    # 1) The sizes are the same, and the user told us
                    #    to ignore the mtimes
                    # 2) The mtimes and size is the same, and we checked both
                    pass
                else:
                    raise Exceptions.SynchronizeConflictError(
                        comp, vfsFile, destFile)
            else:
                self._transfer_file(vfsFile, newURI, overwrite)

        return self.get(newURI).get_rid()
Ejemplo n.º 11
0
    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)
#   File came from a foreign DP like tomboy. No concept of relative path
#   or group. Goes into the folder and keeps its name
Ejemplo n.º 12
0
    def put(self, vfsFile, overwrite, LUID=None):
        """
        Puts vfsFile at the correct location. There are three scenarios
        1) File came from a foreign DP like tomboy
        2) File came from another file dp

        Behaviour:
        1) The foreign DP should have encoded enough information (such as
        the filename) so that we can go ahead and put the file in the dir
        2) First we see if the file has a group attribute.
            a) If so, and the group matches the groupName here then we 
            put the files into the directory.
            b) If not we put the file in a subdir by the name of the group 
            
        We always retain the relative path for the files
        """
        DataProvider.TwoWay.put(self, vfsFile, overwrite, LUID)
        newURI = ""
        if LUID != None:
            newURI = LUID
        elif vfsFile.basePath == "":
            #came from another type of dataprovider such as tomboy
            #where relative path makes no sense. Could also come from
            #the FileSource dp when the user has selected a single file
            log.debug("No basepath. Going to empty dir")
            newURI = Vfs.uri_join(self.folder,vfsFile.get_filename())
        else:
            #Look for corresponding groups
            relpath = vfsFile.get_relative_uri()
            log.debug("Relative path: %s" % relpath)
            if self.folderGroupName == vfsFile.group:
                log.debug("Found corresponding group")
                #put in the folder
                newURI = Vfs.uri_join(self.folder,relpath)
            else:
                log.debug("Recreating group: %s" % vfsFile.group)
                #unknown. Store in the dir but recreate the group
                newURI = Vfs.uri_join(self.folder,vfsFile.group,relpath)

        #escape illegal filesystem characters
        if self.fstype:
            newURI = Vfs.uri_sanitize_for_filesystem(newURI, self.fstype)
            
        #overwrite is the easy case, as for it to be true, requires specific user
        #interaction
        if overwrite == True:
            self._transfer_file(vfsFile, newURI, overwrite)
        else:
            #check for conflicts
            destFile = File.File(URI=newURI)
            if destFile.exists():
                comp = vfsFile.compare(
                            destFile, 
                            sizeOnly=self.compareIgnoreMtime
                            )

                if LUID != None and comp == DataType.COMPARISON_NEWER:
                    #we were expecting an existing file, we found it, but
                    #we are newer, so overwrite it
                    self._transfer_file(vfsFile, newURI, True)
                elif comp == DataType.COMPARISON_EQUAL:
                    #in File.compare, the files are compared based on size, if
                    #their mtimes are the same, so this case is true when
                    # 1) The sizes are the same, and the user told us
                    #    to ignore the mtimes
                    # 2) The mtimes and size is the same, and we checked both
                    pass
                else:
                    raise Exceptions.SynchronizeConflictError(comp, vfsFile, destFile)
            else:
                self._transfer_file(vfsFile, newURI, overwrite)                    

        return self.get(newURI).get_rid()
Ejemplo n.º 13
0
 def __init__(self, *args):
     N800Base.__init__(self,
                       mount=args[0],
                       udi=args[1],
                       folder=Vfs.uri_join(args[0], self.DEFAULT_FOLDER))
Ejemplo n.º 14
0
import conduit.vfs as Vfs
import conduit.vfs.File as VfsFile
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:
        lines.remove(d)
    except ValueError: pass