def react(action, device): print('MTP device %s,' % action, end="") try: bus = device['BUSNUM'] dev = device['DEVNUM'] model = device['ID_MODEL'] except KeyError as e: print('but %s key missing' % e.args[0]) return print('model is %s,' % model, end="") mp = os.path.join(mp_root, model) if action == 'add': try: mkdir_p(mp) except OSError as e: print('but failed to create mountpoint %s' % mp) return else: print('created mountpoint %s, mouting' % mp) e = invoke('jmtpfs', '-device=%s,%s' % (bus, dev), mp) if e is None: mounted.add((bus, dev)) elif action == 'remove': if (bus, dev) not in mounted: print("but I didn't seem to have mounted it, unmounting anyway") else: print('unmounting') mounted.remove((bus, dev)) invoke('fusermount', '-u', mp)
def react(action, device): print 'MTP device %s,' % action, try: bus = device['BUSNUM'] dev = device['DEVNUM'] model = device['ID_MODEL'] except KeyError as e: print 'but %s key missing' % e.args[0] return print 'model is %s,' % model, mp = os.path.join(mp_root, model) if action == 'add': try: mkdir_p(mp) except OSError as e: print 'but failed to create mountpoint %s' % mp return else: print 'created mountpoint %s, mouting' % mp e = invoke('jmtpfs', '-device=%s,%s' % (bus, dev), mp) if e is None: mounted.add((bus, dev)) elif action == 'remove': if (bus, dev) not in mounted: print "but I didn't seem to have mounted it, unmounting anyway" else: print 'unmounting' mounted.remove((bus, dev)) invoke('fusermount', '-u', mp)
def react(action, device): #print('USB device %s,++++++++++++++++++++++++++++++' % action, end="") #for key, value in device.items(): # print('{key}={value}'.format(key=key, value=value)) devpath = device.get('DEVNAME') if action == 'add': if devpath in str(invoke('pmount')): invoke('pumount', devpath) invoke('pmount', devpath) mounted.add(devpath) elif action == 'remove': if devpath in str(invoke('pmount')) or devpath in mounted: logging.info('unmounting') mounted.remove(devpath) invoke('pumount', devpath)
def update(): with open("/sys/class/drm/card0-HDMI-A-2/status", "r") as f: status = f.read().strip() if status == "connected": dis = "xrandr --output HDMI2 --mode 1920x1080 --pos 1980x0" aud = "pactl set-default-sink Laptop" else: dis = "xrandr --output HDMI2 --off" aud = "pactl set-default-sink Laptop" invoke(*dis.split(" ")) invoke(*aud.split(" ")) invoke("fbsetbg", "-F", "/home/brian/.wallpaper")
def react(action, device): logging.info('MTP device %s,' % action) try: bus = device['BUSNUM'] dev = device['DEVNUM'] if (action == 'add'): model = device['ID_MODEL'] except KeyError as e: loggging.info('but %s key missing' % e.args[0]) return if action == 'add': mp = os.path.join(mp_root, model) try: if Path(mp).exists(): umount(mp, bus, dev) mkdir_p(mp) except OSError as e: if e.errno == errno.EEXIST: logging.info('but failed to create mountpoint %s' % mp) logging.info('Error %s' % str(e)) return else: logging.info('created mountpoint %s, mouting' % mp) e = invoke('jmtpfs', '-device=%s,%s' % (bus, dev), mp) if isinstance(e, bytes) or (e is None): mounted[(bus, dev)] = mp else: umount(mp, bus, dev) elif action == 'remove': if (bus, dev) in mounted: logging.info('unmounting') umount(mounted[bus,dev], bus, dev)
def react(action, device): print('new keyboard attached') invoke('xset', *xset_args)
def react(action, device): print('monitor change') invoke('autorandr', '-c')
def init(): print('init autorandr') invoke('autorandr', '-c')
def umount(path, bus, dev): if (bus, dev) in mounted: del mounted[(bus, dev)] invoke('fusermount', '-u', path) invoke('rmdir', path)