Ejemplo n.º 1
0
    def mount(self, usbid, usbserial, model):
        if model == 'h3' or model == 'h3p':
            deviceid = usbid
            mounted = False
            for device in syscalls.sdList():
                if syscalls.USBId(device) != deviceid:
                    continue
                mounted = True

                if self.mountPoint:
                    return

                if not os.path.isdir('/media/' + deviceid):
                    os.mkdir('/media/' + deviceid)

                syscalls.terminal('sudo mount /dev/' + device + '/ /media/' + deviceid)
                self.mountPoint = '/media/' + deviceid
                print usbid + ': Mounted at ' + self.mountPoint

            if mounted == False and self.mountPoint:
                self.mountPoint = ''
                self.unmount(usbid, usbserial, model)

        elif model == 'h4':
            autoMounts = syscalls.terminal('ls /run/user/1000/gvfs', asUser=True)
            autoMounts = autoMounts.split('\n')
            while '' in autoMounts:
                autoMounts.remove('')

            usbInfoFromCommand = syscalls.getBusInfo([usbid, usbserial])
            for folder in autoMounts:
                usbInfoFromFolder = syscalls.decodeGPhotoFolder(folder)
                if usbInfoFromCommand == usbInfoFromFolder:
                    if self.mountPoint == '':
                        self.mountPoint = '/run/user/1000/gvfs/' + folder
                        print usbid + ': Mounted at ' + self.mountPoint
                    return
            self.mountPoint = ''

        else:
            print 'Error in mounting of ' + usbid + ': Model ' + model + ' not supported. Must be h3, h3p or h4'
Ejemplo n.º 2
0
#Flushes previous hanging instances of program
#Run when socket errno 98 turns up
#This means that there is still a previous instance binding the port we use
#Reproduce: Launch main.py. ctrl-z after initialization
#NOTE: if the hanging intance is launched from the same terminal as flush, this will kill the terminal aswell

from syscalls import terminal

processes = terminal('ps -ef')
processes = processes.split('\n')

for process in processes:
    if 'python main.py' in process or 'python launcher.py' in process:
        process = process.split(' ')

        while '' in process:
            process.remove('')
            print 'Killing: ' + str(process)
            terminal('kill -9 ' + process[1] + ' ' + process[2])
Ejemplo n.º 3
0
 def unmount(self, usbid, usbserial, model):
     if model == 'h3' or model == 'h3p':
         if os.path.isdir('/media/' + usbid):
             syscalls.terminal('sudo umount /media/' + usbid)
             os.rmdir('/media/' + usbid)
             print usbid + '_' + usbserial + ': Unmounted'