Ejemplo n.º 1
0
    def __init__(self, data=None):        
        QObject.__init__(self)
        
        self.view = MountLineWidget()
        self.config = Config()
        #self.authcommand = self.config.get_de_auth()

        if data:
            self.host = data.host
            self.address = data.address
            self.path = data.path
            self.mountpoint = data.mountpoint
            self.view.fill_widgets(self.address, self.path, self.mountpoint)

        QObject.connect(self.view.mount_button,
            SIGNAL("clicked()"),
            self.read_and_mount)
        
        QObject.connect(self.view.umount_button,
            SIGNAL("clicked()"),
            lambda:self.read_and_umount())
Ejemplo n.º 2
0
class MountLine(QObject):
    def __init__(self, data=None):        
        QObject.__init__(self)
        
        self.view = MountLineWidget()
        self.config = Config()
        #self.authcommand = self.config.get_de_auth()

        if data:
            self.host = data.host
            self.address = data.address
            self.path = data.path
            self.mountpoint = data.mountpoint
            self.view.fill_widgets(self.address, self.path, self.mountpoint)

        QObject.connect(self.view.mount_button,
            SIGNAL("clicked()"),
            self.read_and_mount)
        
        QObject.connect(self.view.umount_button,
            SIGNAL("clicked()"),
            lambda:self.read_and_umount())

    def set_address(self, address):
        self.address = address
        self.view.address_label.setText(address)
        
    def read_and_mount(self):
        self.address = self.view.get_address()
        self.path = self.view.get_path()
        self.mountpoint = self.view.get_mountpoint()
        
        if self.address=='':
            return
        if self.path=='':
            return
        if self.mountpoint=='':
            return

        #mount, unire le funzioni?
        if self.mount(self.address, self.path, self.mountpoint):
            self.view.set_umountable()

    def mount(self, address, path, mountpoint):
        
        #controllare che address sia un ip
        if not check_ip(address):
            print('address not an ip!')
            return

        active = self.check_status(address)
        mounted = self.check_already_mounted(address,path)
        
        if not active:
            print('not active!')
            return

        if mounted:
            print('already mounted!')
            return

        bus = dbus.SystemBus()
        remote_object = bus.get_object("org.nfsmanager", "/NFSManager")
        iface = dbus.Interface(remote_object, "org.nfsmanager.Interface")
        return iface.Mount(address, path, mountpoint)
            
    def read_and_umount(self):

        self.address = self.view.get_address()
        self.path = self.view.get_path()
        self.mountpoint = self.view.get_mountpoint()
        
        if self.umount(self.mountpoint):
            self.view.set_mountable()
    
    def umount(self, mountpoint):

        bus = dbus.SystemBus()
        remote_object = bus.get_object("org.nfsmanager", "/NFSManager")
        iface = dbus.Interface(remote_object, "org.nfsmanager.Interface")
        return iface.Umount(mountpoint)

    def check_status(self,address):
        
        try:
            pingable = subprocess.check_call(["ping","-c1",address])
            return True
        except subprocess.CalledProcessError:
            print(pingable.returncode) #dovrebbe ritornare l'errore
            return False
            
    def check_already_mounted(self, address, path):
        
        mounts = self.list_mount_points()
        if address+':'+path in mounts:
            return True
        else:
            return False

    def list_mount_points(self):
        
        l = subprocess.check_output(['mount'])
        l = l.split()

        n=0
        result = ['']
        for element in l:
            result.append(l[n])
            n=n+6
            if (n >= len(l)):
                break
        return result