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
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
def __init__(self, *args): N800Base.__init__( self, mount=args[0], udi=args[1], folder=Vfs.uri_join(args[0],self.DEFAULT_FOLDER) )
def get_relative_uri(self): """ @returns: The files URI relative to its basepath """ if self.basePath: return Vfs.uri_get_relative(self.basePath,self._get_text_uri()) else: return self._get_text_uri()
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"
def get_all(self): DataProvider.DataSource.get_all(self) photos = [] for album in self.albums: if album[FILENAME_IDX] in self.enabledAlbums: for photouri in album[PHOTOS_IDX]: if Vfs.uri_exists(photouri): photos.append(photouri) return photos
def refresh(self): DataProvider.TwoWay.refresh(self) #cache the filesystem type for speed self.fstype = Vfs.uri_get_filesystem_type(self.folder) #scan the folder scanThread = Vfs.FolderScanner(self.folder, self.includeHidden, self.followSymlinks) scanThread.start() scanThread.join() self.files = scanThread.get_uris()
def _dnd_data_get(self, wid, context, x, y, selection, targetType, time): for uri in selection.get_uris(): try: log.debug("Drag recieved %s" % uri) if Vfs.uri_is_folder(uri): self._add_folder(uri) else: self._add_file(uri) except Exception, err: log.debug("Error adding %s\n%s" % (uri,err))
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"
def do_image_dataprovider_tests(self, supportsGet, supportsDelete, safePhotoLUID, ext="png"): """ Tests get(), put(), delete() and Image dataprovider specific functions """ #Test get() and image specific friends if supportsGet: try: info = self.sink.module._get_photo_info(safePhotoLUID) ok("Got photo info", info != None) url = self.sink.module._get_raw_photo_url(info) ok("Got photo url (%s)" % url, url != None and Vfs.uri_exists(str(url))) except Exception, err: traceback.print_exc() ok("Got photo info/url (%s)" % err, False)
def read_removable_volume_group_file(folderUri): items = [] f = File.File(URI=folderUri) if f.is_on_removale_volume(): #read from the /volume/root/.conduit file rooturi,path = get_removable_volume_info(f) if rooturi and path: conf = ConfigParser.SafeConfigParser() conf.read(path) for p,n in conf.items("DEFAULT"): log.debug("Read group (%s = %s)" % (p,n)) #check the path still exists on the volume if Vfs.uri_exists(rooturi+p): items.append((p,n)) return items
def _item_name_data_func(self, column, cell_renderer, tree_model, rowref): """ If the user has set a descriptive name for the folder the display that, otherwise display the filename. """ path = self.model.get_path(rowref) uri = self.model[path][URI_IDX] if self.model[path][GROUP_NAME_IDX] != "": displayName = self.model[path][GROUP_NAME_IDX] else: displayName = Vfs.uri_format_for_display(uri) cell_renderer.set_property("text", displayName) cell_renderer.set_property("ellipsize", True) #Can not edit the group name of a file if self.model[path][TYPE_IDX] == FileDataProvider.TYPE_FILE: cell_renderer.set_property("editable", False) else: cell_renderer.set_property("editable", True)
def load_all(self, whitelist, blacklist): """ Loads all classes in the configured paths. If whitelist and blacklist are supplied then the name of the file is tested against them. Default policy is to load all modules unless """ for f in self.filelist: name, ext = Vfs.uri_get_filename_and_extension(f) if whitelist: if name in whitelist: self._load_modules_in_file(f) elif blacklist: if name not in blacklist: self._load_modules_in_file(f) else: self._load_modules_in_file(f) for i in self.dataproviderFactories: i.connect("dataprovider-removed", self._on_dynamic_dataprovider_removed) i.connect("dataprovider-added", self._on_dynamic_dataprovider_added) i.probe() self.emit('all-modules-loaded')
def get_name(self): return Vfs.uri_get_filename(self.folder)
import conduit.Vfs as Vfs import conduit.utils as Utils for impl in ("GIO", "GnomeVfs",): conduit.FILE_IMPL = impl reload(Vfs) reload(Utils) ok("--- TESTING VFS WITH FILE IMPL: %s" % impl, True) #print Vfs.FolderScanner 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 = Vfs.FolderScannerThreadManager(maxConcurrentThreads=1)
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
def is_configured(self, isSource, isTwoWay): return self.folder and Vfs.uri_exists(self.folder)
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()
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: lines.remove(d) except ValueError: pass
def on_compare_conflicts(self, sender): model, rowref = self.view.get_selection().get_selected() conflict = model.get_value(rowref, CONFLICT_IDX) Vfs.uri_open(conflict.sourceData.get_open_URI()) Vfs.uri_open(conflict.sinkData.get_open_URI())
old_hash = temp.get_hash(); # now, add some more tempsize = random.randint(100, 200) contents += "b"*tempsize temp.set_contents_as_text(contents) ok("Base: Check if appending to a file changes its hash", temp.get_hash() != old_hash) # reset the mtime, and make sure the hash is still different temp.set_mtime( old_mtime ) ok( "Base: Check if reseting a file's mtime is successful", temp.get_mtime() == old_mtime ) ok( "Base: Check that the hash is still different, even with the same mtime.", temp.get_hash() != old_hash ) remUri = get_external_resources('folder')['removable-volume'] rf = File.File(remUri,implName=impl) if Vfs.uri_exists(remUri): ok("Base: Removable volume detected", rf.is_on_removale_volume() == True) ok("Base: Removable volume calculate root path", rf.get_removable_volume_root_uri() == remUri) folder = File.File(os.environ["HOME"],implName=impl) ok("Base: check if HOME exists", folder.exists() == True) ok("Base: check if HOME is folder", folder.is_directory() == True) localURIs = [ os.path.abspath(os.path.join(my_path,"..", "test-data","oldest")), os.path.abspath(os.path.join(my_path,"..", "test-data","older")), os.path.abspath(os.path.join(my_path,"..", "test-data","newer")), os.path.abspath(os.path.join(my_path,"..", "test-data","newest")) ] #test the comparison of files by mtime oldest = File.File(localURIs[0],implName=impl)