Exemple #1
0
    def __init__(self, treeview, statusbar, ui):
        self.treeview = treeview
        self.logger = fwlogger.getLogger()
        self.statusbar = statusbar
        self.ui = ui
        self.liststore = gtk.ListStore(gobject.TYPE_BOOLEAN,
                                       gobject.TYPE_STRING)
        # Give it columns
        cell = gtk.CellRendererToggle()
        cell.connect('toggled', self._on_toggled, self.liststore)
        cell.set_property('activatable', True)
        col = gtk.TreeViewColumn(_('Export'), cell, active=0)
        col.set_resizable(True)
        self.treeview.append_column(col)

        cell = gtk.CellRendererText()
        cell.set_property('ellipsize', pango.ELLIPSIZE_MIDDLE)
        col = gtk.TreeViewColumn(_('Set'), cell, text=1)
        col.set_resizable(True)
        self.treeview.append_column(col)

        self.treeview.set_model(self.liststore)
        self.treeview.set_reorderable(False)
        # Just to keep things clean.
        self._clear()
Exemple #2
0
 def __init__(self, logger=None, printToo=True):
   """Initializes elements common to all operations. If no logger is specified,
   a new one will be created."""
   # Initialize a logger if none passed
   if not logger:
     from fwbackups import fwlogger
     self.logger = fwlogger.getLogger()
   else:
     self.logger = logger
   # Totals: Nothing so far
   self._status = 0
   self._current = 0
   self._total = 0
   self._currentName = ''
   # No pids to kill, we're not cancelling
   self.pids = []
   self.toCancel = False
   # Execute commands with this environment.
   self.environment = {'PATH': os.getenv('PATH')}
Exemple #3
0
  def __init__(self, treeview, statusbar, ui):
    self.treeview = treeview
    self.logger = fwlogger.getLogger()
    self.statusbar= statusbar
    self.ui = ui
    self.liststore = gtk.ListStore(gobject.TYPE_BOOLEAN, gobject.TYPE_STRING)
    # Give it columns
    cell = gtk.CellRendererToggle()
    cell.connect('toggled', self._on_toggled, self.liststore)
    cell.set_property('activatable', True)
    col = gtk.TreeViewColumn(_('Export'), cell, active=0)
    col.set_resizable(True)
    self.treeview.append_column(col)

    cell = gtk.CellRendererText()
    cell.set_property('ellipsize', pango.ELLIPSIZE_MIDDLE)
    col = gtk.TreeViewColumn(_('Set'), cell, text=1)
    col.set_resizable(True)
    self.treeview.append_column(col)

    self.treeview.set_model(self.liststore)
    self.treeview.set_reorderable(False)
    # Just to keep things clean.
    self._clear()
Exemple #4
0
    def __init__(self, treeview, statusbar, ui, parent):
        self.treeview = treeview
        self.statusbar = statusbar
        self.ui = ui
        self.parent = parent
        self.logger = fwlogger.getLogger()

        # Give it columns
        cell = gtk.CellRendererPixbuf()
        col = gtk.TreeViewColumn(_('Access'), cell, stock_id=0)
        col.set_resizable(True)
        self.treeview.append_column(col)

        cell = gtk.CellRendererText()
        cell.set_property('ellipsize', pango.ELLIPSIZE_MIDDLE)
        col = gtk.TreeViewColumn(_('Path'), cell, text=1)
        col.set_resizable(True)
        self.treeview.append_column(col)

        self.liststore = gtk.ListStore(gobject.TYPE_STRING,
                                       gobject.TYPE_STRING)
        self.treeview.set_model(self.liststore)
        self.treeview.set_reorderable(False)
        self.treeview.get_selection().set_mode(gtk.SELECTION_MULTIPLE)

        # Allow enable drag and drop of rows including row move
        #self.TARGETS = [('text/plain', 0, 1)]
        #self.treeview.enable_model_drag_dest(self.TARGETS, gtk.gdk.ACTION_DEFAULT)
        target = [('text/uri-list', 0, 0)]
        self.treeview.drag_dest_set(gtk.DEST_DEFAULT_ALL, target,
                                    gtk.gdk.ACTION_COPY)

        def escape(uri):
            "Convert each space to %20, etc"
            _to_utf8 = codecs.getencoder('utf-8')
            return re.sub('[^:-_./a-zA-Z0-9]',
                          lambda match: '%%%02x' % ord(match.group(0)),
                          _to_utf8(uri)[0])

        def unescape(uri):
            "Convert each %20 to a space, etc"
            if '%' not in uri: return uri
            return re.sub('%[0-9a-fA-F][0-9a-fA-F]',
                          lambda match: chr(int(match.group(0)[1:], 16)), uri)

        def get_local_path(uri):
            """Convert 'uri' to a local path and return, if possible. If 'uri'
      is a resource on a remote machine, return None. URI is in the escaped form
      (%20 for space)."""
            if not uri:
                return None

            if uri[0] == '/':
                if uri[1:2] != '/':
                    return unescape(uri)  # A normal Unix pathname
                i = uri.find('/', 2)
                if i == -1:
                    return None  # //something
                if i == 2:
                    if MSWINDOWS:
                        return unescape(
                            uri[3:])  # ///path - from the removal of file:///
                    else:
                        return unescape(
                            uri[2:]
                        )  # ///path - from the removal of file:// as we need / (is root)
                remote_host = uri[2:i]
                if remote_host == our_host_name():
                    return unescape(uri[i:])  # //localhost/path
                # //otherhost/path
            elif uri[:5].lower() == 'file:':
                if uri[5:6] == '/':
                    return get_local_path(uri[5:])
            elif uri[:2] == './' or uri[:3] == '../':
                return unescape(uri)
            return None

        def drag_data_received(w, context, x, y, data, info, time):
            paths = []
            if data and data.format == 8:
                for i in data.data.split('\r\n'):
                    if i != "" or i != None:
                        path = get_local_path(i)
                        if path != None:
                            paths.append(path.decode('utf-8'))
            for i in paths:
                self.add([os.path.normpath(i)],
                         self._buildListstoreIndex(self.liststore, 1))
            context.finish(True, False, time)

        self.treeview.connect('drag_data_received', drag_data_received)
        # Just to keep things clean.
        self.clear()
       sys.exit(1)
     if opt == "-v" or opt == "--verbose":
       verbose = True
     if opt == "-l" or opt == "--silent":
       printToo = False
     if opt == "-f" or opt == "--force":
       forceRun = True
 if not len(sets) >= 1:
   usage(_('Invalid usage: Requires at least one set name to backup'))
   sys.exit(1)
 prefs = config.PrefsConf(create=True)
 if verbose == True or int(prefs.get('Preferences', 'AlwaysShowDebug')) == 1:
   level = fwlogger.L_DEBUG
 else:
   level = fwlogger.L_INFO
 logger = fwlogger.getLogger()
 logger.setLevel(level)
 logger.setPrintToo(printToo)
 # handle ctrl + c
 signal.signal(signal.SIGINT, handleStop)
 for setPath in sets:
   if MSWINDOWS:
     setPath = setPath.strip("'")
   setPath = os.path.join(SETLOC, "%s.conf" % setPath)
   if not os.path.exists(encode(setPath)):
     logger.logmsg("ERROR", _("The set configuration for '%s' was not found - skipping." % setPath))
     continue
   try:
     backupHandle = backup.SetBackupOperation(setPath, logger=logger, forceRun=forceRun)
     backupThread = fwbackups.FuncAsThread(backupHandle.start, {})
   except Exception, error:
             options["RemotePassword"] = value
         if opt == "--remote-port":
             options["RemotePort"] = value
 # handle ctrl + c
 options["Excludes"] = '\n'.join(excludes)
 signal.signal(signal.SIGINT, handleStop)
 if len(paths) < 2:
     usage(_('Requires at least one path to backup and a destination'))
     sys.exit(1)
 prefs = config.PrefsConf(create=True)
 if verbose == True or int(prefs.get('Preferences',
                                     'AlwaysShowDebug')) == 1:
     level = fwlogger.L_DEBUG
 else:
     level = fwlogger.L_INFO
 logger = fwlogger.getLogger()
 logger.setLevel(level)
 logger.setPrintToo(True)
 # FIXME: Why both? Make RemoteDestination == Destination
 options["Destination"] = paths[-1]
 options["RemoteFolder"] = paths[-1]
 if not options.has_key("DestinationType"):
     usage(_('Destination type was not specified'))
     sys.exit(1)
 if not options.has_key("Engine"):
     usage(_('An engine was not specified'))
     sys.exit(1)
 onetime.save(paths[:-1], options)
 try:
     backupHandle = backup.OneTimeBackupOperation(ONETIMELOC, logger=logger)
     backupThread = fwbackups.FuncAsThread(backupHandle.start, {})
Exemple #7
0
  def __init__(self, treeview, statusbar, ui, parent):
    self.treeview = treeview
    self.statusbar = statusbar
    self.ui = ui
    self.parent = parent
    self.logger = fwlogger.getLogger()

    # Give it columns
    cell = gtk.CellRendererPixbuf()
    col = gtk.TreeViewColumn(_('Access'), cell, stock_id=0)
    col.set_resizable(True)
    self.treeview.append_column(col)

    cell = gtk.CellRendererText()
    cell.set_property('ellipsize', pango.ELLIPSIZE_MIDDLE)
    col = gtk.TreeViewColumn(_('Path'), cell, text=1)
    col.set_resizable(True)
    self.treeview.append_column(col)

    self.liststore = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
    self.treeview.set_model(self.liststore)
    self.treeview.set_reorderable(False)
    self.treeview.get_selection().set_mode(gtk.SELECTION_MULTIPLE)

    # Allow enable drag and drop of rows including row move
    #self.TARGETS = [('text/plain', 0, 1)]
    #self.treeview.enable_model_drag_dest(self.TARGETS, gtk.gdk.ACTION_DEFAULT)
    target = [('text/uri-list', 0, 0)]
    self.treeview.drag_dest_set(gtk.DEST_DEFAULT_ALL, target, gtk.gdk.ACTION_COPY)

    def escape(uri):
      "Convert each space to %20, etc"
      _to_utf8 = codecs.getencoder('utf-8')
      return re.sub('[^:-_./a-zA-Z0-9]',
        lambda match: '%%%02x' % ord(match.group(0)),
        _to_utf8(uri)[0])

    def unescape(uri):
      "Convert each %20 to a space, etc"
      if '%' not in uri: return uri
      return re.sub('%[0-9a-fA-F][0-9a-fA-F]',
        lambda match: chr(int(match.group(0)[1:], 16)),
        uri)

    def get_local_path(uri):
      """Convert 'uri' to a local path and return, if possible. If 'uri'
      is a resource on a remote machine, return None. URI is in the escaped form
      (%20 for space)."""
      if not uri:
        return None

      if uri[0] == '/':
        if uri[1:2] != '/':
          return unescape(uri)  # A normal Unix pathname
        i = uri.find('/', 2)
        if i == -1:
          return None  # //something
        if i == 2:
          if MSWINDOWS:
            return unescape(uri[3:])  # ///path - from the removal of file:///
          else:
            return unescape(uri[2:])  # ///path - from the removal of file:// as we need / (is root)
        remote_host = uri[2:i]
        if remote_host == our_host_name():
          return unescape(uri[i:])  # //localhost/path
        # //otherhost/path
      elif uri[:5].lower() == 'file:':
        if uri[5:6] == '/':
          return get_local_path(uri[5:])
      elif uri[:2] == './' or uri[:3] == '../':
        return unescape(uri)
      return None

    def drag_data_received(w, context, x, y, data, info, time):
      paths = []
      if data and data.format == 8:
        for i in data.data.split('\r\n'):
          if i != "" or i != None:
            path = get_local_path(i)
            if path != None:
              paths.append(path.decode('utf-8'))
      for i in paths:
        self.add([os.path.normpath(i)], self._buildListstoreIndex(self.liststore, 1))
      context.finish(True, False, time)

    self.treeview.connect('drag_data_received', drag_data_received)    
    # Just to keep things clean.
    self.clear()