def request_url(self, doc, url, stream): gdoc = self._window.get_active_document() if not gdoc: source_path = None else: source_path = gdoc.get_location() if source_path: source_path = gnomevfs.URI(source_path.get_uri()) if source_path: url = source_path.resolve_relative(url) try: f = gnomevfs.open(url, gnomevfs.OPEN_READ) except: print "Error opening url", url stream.close() return while True: try: stream.write(f.read (1024)) except gnomevfs.EOFError: break f.close() stream.close()
def less(self, file): file = self.cwd.resolve_relative(file) file_info = gnomevfs.get_file_info(file) fp = gnomevfs.open(file, gnomevfs.OPEN_READ) less = os.popen('less -m -F -', 'w') buffer = fp.read(file_info.size) less.write(buffer) less.close()
def open(uri, mode = OPEN_READ): try: fd = gnomevfs.open(uri, mode) except: log("Warning: Couldn't open file \"%s\"." % (uri,)) return return fd
def extract(self, backup, spath, tdir): tarline = "tar -xzp --occurrence=1 --ignore-failed-read -C '" + tdir + "' " if self.islocal(backup): tarline += " -f '" + backup + "/files.tgz' '" + spath + "' >/dev/null 2>&1" os.system(tarline) else: tarline += "'" + spath + "' 2>/dev/null" tsrc = gnomevfs.open(backup + "/files.tgz", 1) tdst = os.popen(tarline, "w") try: shutil.copyfileobj(tsrc, tdst, 100 * 1024) except gnomevfs.EOFError: pass tdst.close() tsrc.close()
def filter_location(self, location): url = urlutil.UrlParse(location) if not url.is_local: fd = gnomevfs.open(url.unparse()) def read_all(): buff = "" try: while 1: buff += fd.read(1024) except gnomevfs.EOFError: pass return buff fd.read = read_all else: fd = open(url.path) try: zfile = zipfile.ZipFile(fd) except zipfile.BadZipfile: return except IOError: # it's not a file return try: buff = zfile.read("maindata.xml") except KeyError: # zip file does not contain the file return try: root = minidom.parseString(buff) except ExpatError: # Malformed xml return # Iterate over tracks hints_list = [] for node in Evaluate("/k3b_audio_project/contents/track", root): try: hints_list.append({"location": node.attributes["url"].value}) except KeyError: # skip elements with not 'url' attribute set pass return hints_list
def filter_location (self, location): url = urlutil.UrlParse (location) if not url.is_local: fd = gnomevfs.open (url.unparse ()) def read_all (): buff = "" try: while 1: buff += fd.read (1024) except gnomevfs.EOFError: pass return buff fd.read = read_all else: fd = open (url.path) try: zfile = zipfile.ZipFile (fd) except zipfile.BadZipfile: return except IOError: # it's not a file return try: buff = zfile.read ("maindata.xml") except KeyError: # zip file does not contain the file return try: root = minidom.parseString (buff) except ExpatError: # Malformed xml return # Iterate over tracks hints_list = [] for node in Evaluate ("/k3b_audio_project/contents/track", root): try: hints_list.append ({"location": node.attributes["url"].value}) except KeyError: # skip elements with not 'url' attribute set pass return hints_list
def save_file(self, document, filename=None, encoding='utf-8'): # TODO: Implement File Save operation buf = document.Buffer string = buf.get_text(buf.get_start_iter(), buf.get_end_iter()) handler = open(document.filename, 'w') unicode_string = to_unicode_or_bust(string, encoding) handler.write(unicode_string) handler.flush() handler.close() last_mod = get_last_modification(document.filename) self.__document.last_modified_time = last_mod # 1. Check For Other Program Modifications by checking the last modified # time whith last file modified time # 2. Check For Permissions to Save # 3. Encode File before writing to disk # 4. Write to a tmp file # 5. Copy tmp File over original file (For Crash Prevent) # 6. Delete old file return True
def file_write(file, data): "Writes data to file" try: if file is None: raise IOError if data is None: data = "" if file_exists(file) == True: f = gnomevfs.open(file, gnomevfs.OPEN_WRITE) else: f = gnomevfs.create(file, gnomevfs.OPEN_WRITE) f.write(data) f.close() except gnomevfs.Error: raise IOError
def filter_location(self, location): url = urlutil.UrlParse(location) if not url.is_local: fd = gnomevfs.open(url.unparse()) def read_all(): buff = "" try: while 1: buff += fd.read(1024) except gnomevfs.EOFError: pass return buff fd.read = read_all else: try: fd = open(url.path) except IOError: # Could not open the filename return try: zfile = zipfile.ZipFile(fd) except zipfile.BadZipfile: return except IOError: # it's not a file return try: buff = zfile.read("maindata.xml") except KeyError: # zip file does not contain the file fd.close() return fd.close() try: root = minidom.parseString(buff) except ExpatError: # Malformed xml return # Iterate over tracks hints_list = [] for node in Evaluate("/k3b_audio_project/contents/track", root): try: hints_list.append({"location": node.attributes["url"].value}) except KeyError: # skip elements with not 'url' attribute set pass # New versions of K3B changed the internal structure # since there's no version present for the file format we'll just # try both for node in Evaluate("/k3b_audio_project/contents/track/sources/file", root): try: hints_list.append({"location": node.attributes["url"].value}) except KeyError: # skip elements with not 'url' attribute set pass return hints_list
def filter_location (self, location): url = urlutil.UrlParse (location) if not url.is_local: fd = gnomevfs.open (url.unparse ()) def read_all (): buff = "" try: while 1: buff += fd.read (1024) except gnomevfs.EOFError: pass return buff fd.read = read_all else: try: fd = open (url.path) except IOError: # Could not open the filename return try: zfile = zipfile.ZipFile (fd) except zipfile.BadZipfile: return except IOError: # it's not a file return try: buff = zfile.read ("maindata.xml") except KeyError: # zip file does not contain the file fd.close () return fd.close () try: root = minidom.parseString (buff) except ExpatError: # Malformed xml return # Iterate over tracks hints_list = [] for node in Evaluate ("/k3b_audio_project/contents/track", root): try: hints_list.append ({"location": node.attributes["url"].value}) except KeyError: # skip elements with not 'url' attribute set pass # New versions of K3B changed the internal structure # since there's no version present for the file format we'll just # try both for node in Evaluate ("/k3b_audio_project/contents/track/sources/file", root): try: hints_list.append ({"location": node.attributes["url"].value}) except KeyError: # skip elements with not 'url' attribute set pass return hints_list
def __load_uri(self): try: open(URI(self.__uri), self.__open_cb, OPEN_READ, 10) except: self._error(i.exception_file_open) return