def fill_places(self):
        self.store_places.clear()

        #add global places
        self.store_places.append(["<b>%s</b>" % _('Global'), '', ''])
        self.store_places.append([_('Root'), '/', gtk.STOCK_HARDDISK])
        self.store_places.append(
            [_('Home'), os.path.expanduser('~'), gtk.STOCK_HOME])

        #add bookmarks
        rawbookmarks = ''

        try:
            file = open(os.path.expanduser('~/.gtk-bookmarks'))
            rawbookmarks = file.read()
            file.close()
        except:
            pass

        bookmarks = []
        for rawbookmark in rawbookmarks.split('\n'):
            if rawbookmark.startswith('file://'):
                index = rawbookmark.find(' ')
                if index > 0:
                    bookmarks.append((gnomevfs.unescape_string_for_display(
                        rawbookmark[7:index]), rawbookmark[index + 1:]))
                elif index < 0:
                    index = rawbookmark.rfind('/')
                    if index > 0:
                        bookmarks.append((gnomevfs.unescape_string_for_display(
                            rawbookmark[7:]),
                                          gnomevfs.unescape_string_for_display(
                                              rawbookmark[index + 1:])))

        if len(bookmarks) > 0:
            self.store_places.append(["<b>%s</b>" % _('Bookmarks'), '', ''])
            for bookmark in bookmarks:
                self.store_places.append([
                    bookmark[1], bookmark[0],
                    self.icon_names.get_icon(bookmark[0])
                ])

        #add backup folders
        include_folders = self.config.get_include_folders()
        if len(include_folders) > 0:
            if len(include_folders) > 0:
                self.store_places.append(
                    ["<b>%s</b>" % _('Backup Directories'), '', ''])
                for folder in include_folders:
                    self.store_places.append(
                        [folder[0], folder[0], gtk.STOCK_SAVE])
Example #2
0
    def __init__(self,
                 filename="",
                 displayed_name="",
                 expected_hash="",
                 size=0):
        if displayed_name:
            self.displayed_name = displayed_name
        else:
            self.displayed_name = os.path.split(filename)[1]
        self.displayed_name = gnomevfs.unescape_string_for_display(
            self.displayed_name)
        self.filename = filename
        # the Hash loaded from file
        self.expected_hash = expected_hash
        # the Hash calculated
        self.real_hash = ""
        # the file size
        self.size = size
        self.status = HASH_NOT_CHECKED

        if not size:
            try:
                info = gnomevfs.get_file_info(self.filename,
                                              gnomevfs.FILE_INFO_FIELDS_SIZE)
                self.size = info.size
            except:
                log(_("Warning: cannot get size of file '%s'") % filename)
                self.size = 0
	def fill_places( self ):
		self.store_places.clear()

		#add global places
		self.store_places.append( [ "<b>%s</b>" % _('Global'), '', '' ] )
		self.store_places.append( [ _('Root'), '/', gtk.STOCK_HARDDISK ] )
		self.store_places.append( [ _('Home'), os.path.expanduser( '~' ), gtk.STOCK_HOME ] )

		#add bookmarks
		rawbookmarks = ''
		
		try:
			file = open( os.path.expanduser('~/.gtk-bookmarks') )
			rawbookmarks = file.read()
			file.close()
		except:
			pass

		bookmarks = []
		for rawbookmark in rawbookmarks.split( '\n' ):
			if rawbookmark.startswith( 'file://' ):
				index = rawbookmark.find( ' ' )
				if index > 0:
					bookmarks.append( ( gnomevfs.unescape_string_for_display( rawbookmark[ 7 : index ] ), rawbookmark[ index + 1 : ] ) )
				elif index < 0:
					index = rawbookmark.rfind( '/' )
					if index > 0:
						bookmarks.append( ( gnomevfs.unescape_string_for_display( rawbookmark[ 7 : ] ), gnomevfs.unescape_string_for_display( rawbookmark[ index + 1 : ] ) ) )

		if len( bookmarks ) > 0:
			self.store_places.append( [ "<b>%s</b>" % _('Bookmarks'), '', '' ] )
			for bookmark in bookmarks:
				self.store_places.append( [ bookmark[1], bookmark[0], self.icon_names.get_icon(bookmark[0]) ] )

		#add backup folders
		include_folders = self.config.get_include_folders()
		if len( include_folders ) > 0:
			if len( include_folders ) > 0:
				self.store_places.append( [ "<b>%s</b>" % _('Backup Directories'), '', '' ] )
				for folder in include_folders:
					self.store_places.append( [ folder[0], folder[0], gtk.STOCK_SAVE ] )
Example #4
0
    def add_folder(self, folder, prefix=None):
        log("adding folder:", folder)
        glade = os.path.join(DATADIR, "parano.glade")
        self.progress_dialog = gtk.glade.XML(glade, "addfolder_progress")

        events = {"on_button_cancel_clicked": self.on_addfolder_cancel}
        self.window.signal_autoconnect(events)

        progressbar = self.window.get_widget("progressbar")
        progresslabel = self.statusbar
        progress = self.window.get_widget("progress_frame")
        self.window.get_widget("button_pause").hide()

        self.adding_folders = True
        self.abort = False
        progress.show()
        self.current_file = ""
        self.set_status(_("Listing files...."), STATE_HASHING)

        # save current files list
        backup = self.files[:]
        t = 0

        thread.start_new_thread(self.add_folder_thread, (folder, prefix))

        while (self.adding_folders):
            progresslabel.set_markup(
                "<small><i>%s</i></small>" %
                gnomevfs.unescape_string_for_display(self.current_file))
            progressbar.pulse()
            gtk_iteration()
            time.sleep(0.1)

        if not self.abort:
            self.modified = True
            self.update_ui()

        if self.abort:
            # restore original file list
            self.files = backup
            self.set_status(_("Add Folder canceled."))
        else:
            self.set_status(_("Ready."))
        progress.hide()
Example #5
0
	def add_folder(self, folder, prefix=None):
		log("adding folder:", folder)
		glade = os.path.join(DATADIR, "parano.glade")
		self.progress_dialog = gtk.glade.XML(glade,"addfolder_progress")
		
		events = { "on_button_cancel_clicked" : self.on_addfolder_cancel }
		self.window.signal_autoconnect(events)
		
		progressbar = self.window.get_widget("progressbar")
		progresslabel = self.statusbar
		progress = self.window.get_widget("progress_frame")
		self.window.get_widget("button_pause").hide()
		
		self.adding_folders=True
		self.abort=False
		progress.show()	
		self.current_file=""
		self.set_status(_("Listing files...."), STATE_HASHING)
		
		# save current files list
		backup = self.files[:]
		t=0

		thread.start_new_thread(self.add_folder_thread, (folder,prefix))
		
		while(self.adding_folders):
			progresslabel.set_markup("<small><i>%s</i></small>" % gnomevfs.unescape_string_for_display(self.current_file))
			progressbar.pulse()
			gtk_iteration()
			time.sleep(0.1)

		if not self.abort:
			self.modified=True
			self.update_ui()

		if self.abort:
			# restore original file list
			self.files = backup
			self.set_status(_("Add Folder canceled."))
		else:
			self.set_status(_("Ready."))
		progress.hide()	
Example #6
0
	def add_folder_thread(self, folder, prefix):
		files = []
		self.current_file = _("Reading list of files...") 
		for uri in vfs_walk(folder):
			files.append(uri)
	
		if not prefix:
			prefix = os.path.commonprefix(files)
		
		if prefix[-1] != "/":
			# warning: prefix is NOT the containing folder, so cut it. 
			visible = prefix.rfind("/") + 1
		else:	
			visible = len(prefix)

		for uri in files:
			self.add_file(uri, gnomevfs.unescape_string_for_display(uri[visible:]))
			if self.abort:
				break
		self.adding_folders = False
Example #7
0
	def add_folder_thread(self, folder, prefix):
		files = []
		self.current_file = _("Reading list of files...") 
		for uri in vfs_walk(folder):
			files.append(uri)
	
		if not prefix:
			prefix = os.path.commonprefix(files)
			
		if prefix[-1] != "/":
			prefix = prefix + "/"
			
		visible = 0
		if prefix:
			visible = len(prefix)

		for uri in files:
			self.add_file(uri, gnomevfs.unescape_string_for_display(uri[visible:]))
			if self.abort:
				break
		self.adding_folders = False
Example #8
0
    def add_folder_thread(self, folder, prefix):
        files = []
        self.current_file = _("Reading list of files...")
        for uri in vfs_walk(folder):
            files.append(uri)

        if not prefix:
            prefix = os.path.commonprefix(files)

        if prefix[-1] != "/":
            # warning: prefix is NOT the containing folder, so cut it.
            visible = prefix.rfind("/") + 1
        else:
            visible = len(prefix)

        for uri in files:
            self.add_file(uri,
                          gnomevfs.unescape_string_for_display(uri[visible:]))
            if self.abort:
                break
        self.adding_folders = False
Example #9
0
	def add_folder_thread(self, folder, prefix):
		files = []
		self.current_file = _("Reading list of files...") 
		for uri in vfs_walk(folder):
			files.append(uri)
	
		if not prefix:
			prefix = os.path.commonprefix(files)
			
		if prefix[-1] != "/":
			prefix = prefix + "/"
			
		visible = 0
		if prefix:
			visible = len(prefix)

		for uri in files:
			self.add_file(uri, gnomevfs.unescape_string_for_display(uri[visible:]))
			if self.abort:
				break
		self.adding_folders = False
Example #10
0
	def __init__(self, filename="", displayed_name="", expected_hash="", size=0):
		if displayed_name:
			self.displayed_name=displayed_name
		else:
			self.displayed_name=os.path.split(filename)[1]
		self.displayed_name = gnomevfs.unescape_string_for_display(self.displayed_name)	
		self.filename=filename
		# the Hash loaded from file
		self.expected_hash=expected_hash
		# the Hash calculated
		self.real_hash=""
		# the file size
		self.size=size
		self.status=HASH_NOT_CHECKED

		if not size:
			try:
				info = gnomevfs.get_file_info(self.filename, gnomevfs.FILE_INFO_FIELDS_SIZE)
				self.size = info.size
			except:
				log(_("Warning: cannot get size of file '%s'") % filename)
				self.size = 0;
Example #11
0
    def save_hashfile(self, uri):

        for format in formats:
            regex = format.filename_regex
            result = regex.search(uri)
            if result:
                self.format = format
                log("Saving with format:", format.name)
                break

        self.update_hashfile()
        if self.abort:
            return

        list = []
        base = os.path.dirname(uri)
        remove = len(base) + 1
        for ff in self.files:
            # convert to a path relative to hashfile
            dest = self.get_relative_filename(ff.filename, base)
            if not dest:
                self.set_status(_("Cannot save hashfile"))
                log("Cannot save hashfile '%s'" % ff.filename)
                return
            file = gnomevfs.unescape_string_for_display(dest)
            hash = ff.real_hash
            list.append((hash, file))

        u = gnomevfs.URI(uri)
        log("saving to:", u)
        f = gnomevfs.create(u, gnomevfs.OPEN_WRITE)
        self.format.write_file(f, list)
        f.close()

        self.modified = False
        self.filename = uri
        self.update_title()
        self.set_status(_("Hashfile Saved"))
Example #12
0
	def save_hashfile(self, uri):

		for format in formats:
			regex = format.filename_regex
			result = regex.search(uri)
			if result:
				self.format = format
				log("Saving with format:", format.name)
				break

		self.update_hashfile()
		if self.abort:
			return

		list=[]
		base = os.path.dirname(uri)
		remove = len(base)+1
		for ff in self.files:
			# convert to a path relative to hashfile
			dest = self.get_relative_filename(ff.filename, base)
			if not dest:
				self.set_status(_("Cannot save hashfile"))
				log("Cannot save hashfile '%s'" % ff.filename)
				return
			file = gnomevfs.unescape_string_for_display(dest)
			hash = ff.real_hash
			list.append( (hash,file) )
			
		u = gnomevfs.URI(uri)
		log("saving to:", u)
		f = gnomevfs.create(u , gnomevfs.OPEN_WRITE)
		self.format.write_file(f, list)
		f.close()
		
		self.modified=False
		self.filename=uri
		self.update_title()
		self.set_status(_("Hashfile Saved"))
Example #13
0
	def update_hashfile(self):

		if not self.files:
			return

		self.set_status(_("Hashing..."), STATE_HASHING)
		glade = os.path.join(DATADIR, "parano.glade")
		sensitive_widgets = ("menubar","toolbar","filelist")
		for w in sensitive_widgets:
			self.window.get_widget(w).set_sensitive(False)

		events = { 
					"on_button_cancel_clicked" : self.on_update_hash_cancel,
					"on_button_pause_clicked" : self.on_update_hash_pause 
		}
		self.window.signal_autoconnect(events)
		self.progressbar = self.window.get_widget("progressbar")
		self.progresslabel = self.statusbar
		progress = self.window.get_widget("progress_frame")
		self.window.get_widget("button_pause").show()

		self.progresslabel.set_markup("")
		progress.show()

		gtk_iteration()

		self.abort = False
		self.paused = False
		
		self.progress_nbfiles=len(self.files)
		self.progress_file=0
		self.current_file=""

		self.progress_total_bytes=1L
		for f in self.files:
			self.progress_total_bytes=self.progress_total_bytes+f.size
		self.progress_current_bytes=0L

		start=time.time()
		total = self.progress_total_bytes
		thread.start_new_thread(self.thread_update_hash, ())
		
		while self.progress_total_bytes>0:
			if self.abort:
				self.progressbar.set_text(_("Canceling..."))
				break
			if not self.paused:
				now=time.time()
				self.progresslabel.set_markup(_("Hashing file <b>%d</b> of <b>%d</b>: <i>%s</i>") % (self.progress_file, self.progress_nbfiles, gobject.markup_escape_text(gnomevfs.unescape_string_for_display(self.current_file))))
				fraction = float(self.progress_current_bytes) / float(self.progress_total_bytes)
				fraction2= float(self.progress_file) / float(self.progress_nbfiles)
				fraction = (fraction + fraction2) / 2.0
				if fraction>1.0:
					fraction=1.0
				self.progressbar.set_fraction(fraction)
				if fraction>0.0:
					remaining = int((now-start)/fraction-(now-start))
					minutes = remaining/60.0
					seconds = remaining%60
					if minutes >= 1:
						text = _("About %d:%02d minute(s) remaining") % (minutes, seconds)
						#text = _("About %d minute(s) remaining") % minutes
					else:
						text = _("Less than one minute remaining")
					self.progressbar.set_text(text)
				
			gtk_iteration()
			time.sleep(0.1)

		progress.hide()	
		if self.abort:
			self.update_file_list()
			log(_("Hashing canceled!"))
			self.set_status(_("Hashing canceled!"))
		else:
			self.update_and_check_file_list()
			log( "hashed %d file(s) at %.2f MiB/s" % (len(self.files),total/(time.time()-start)/(1024*1024)))

		self.window_main.set_sensitive(True)
		for w in sensitive_widgets:
			self.window.get_widget(w).set_sensitive(True)
Example #14
0
    def update_hashfile(self):

        if not self.files:
            return

        self.set_status(_("Hashing..."), STATE_HASHING)
        glade = os.path.join(DATADIR, "parano.glade")
        sensitive_widgets = ("menubar", "toolbar", "filelist")
        for w in sensitive_widgets:
            self.window.get_widget(w).set_sensitive(False)

        events = {
            "on_button_cancel_clicked": self.on_update_hash_cancel,
            "on_button_pause_clicked": self.on_update_hash_pause
        }
        self.window.signal_autoconnect(events)
        self.progressbar = self.window.get_widget("progressbar")
        self.progresslabel = self.statusbar
        progress = self.window.get_widget("progress_frame")
        self.window.get_widget("button_pause").show()

        self.progresslabel.set_markup("")
        progress.show()

        gtk_iteration()

        self.abort = False
        self.paused = False

        self.progress_nbfiles = len(self.files)
        self.progress_file = 0
        self.current_file = ""

        self.progress_total_bytes = 1L
        for f in self.files:
            self.progress_total_bytes = self.progress_total_bytes + f.size
        self.progress_current_bytes = 0L

        start = time.time()
        total = self.progress_total_bytes
        thread.start_new_thread(self.thread_update_hash, ())

        while self.progress_total_bytes > 0:
            if self.abort:
                self.progressbar.set_text(_("Canceling..."))
                break
            if not self.paused:
                now = time.time()
                self.progresslabel.set_markup(
                    _("Hashing file <b>%d</b> of <b>%d</b>: <i>%s</i>") %
                    (self.progress_file, self.progress_nbfiles,
                     gobject.markup_escape_text(
                         gnomevfs.unescape_string_for_display(
                             self.current_file))))
                fraction = float(self.progress_current_bytes) / float(
                    self.progress_total_bytes)
                fraction2 = float(self.progress_file) / float(
                    self.progress_nbfiles)
                fraction = (fraction + fraction2) / 2.0
                if fraction > 1.0:
                    fraction = 1.0
                self.progressbar.set_fraction(fraction)
                if fraction > 0.0:
                    remaining = int((now - start) / fraction - (now - start))
                    minutes = remaining / 60.0
                    seconds = remaining % 60
                    if minutes >= 1:
                        text = _("About %d:%02d minute(s) remaining") % (
                            minutes, seconds)
                        #text = _("About %d minute(s) remaining") % minutes
                    else:
                        text = _("Less than one minute remaining")
                    self.progressbar.set_text(text)

            gtk_iteration()
            time.sleep(0.1)

        progress.hide()
        if self.abort:
            self.update_file_list()
            log(_("Hashing canceled!"))
            self.set_status(_("Hashing canceled!"))
        else:
            self.update_and_check_file_list()
            self.set_status(
                _("%d files verified and ok. (%.2f MiB)") %
                (len(self.files), total / 1024.0 / 1024.0), STATE_CORRECT)
            log("hashed %d file(s) at %.2f MiB/s" %
                (len(self.files), total / (time.time() - start) /
                 (1024 * 1024)))

        self.window_main.set_sensitive(True)
        for w in sensitive_widgets:
            self.window.get_widget(w).set_sensitive(True)
Example #15
0
def unescape(uri):
    return gnomevfs.unescape_string_for_display(str(uri))