def check(): i = 0 s = False while i < 11: c = 'sudo ls /media -l' r = subprocess.Popen(c, shell=True, stdout=subprocess.PIPE).stdout.read() _r = r.split('\n') for l in _r: if not l.startswith('d?????????'): continue s = True i = l.rindex(' ') d = l[i + 1:] os.system('sudo umount /media/%s -l' % d) u = _get_udev('/dev/disk/by-uuid/%s' % d) if u.has_key('ID_MTP_DEVICE') and u['ID_MTP_DEVICE'] == '1': android(d, u['BUSNUM'], u['DEVNUM']) elif u.has_key('ID_VENDOR') and u['ID_VENDOR'] == 'Apple_Inc.': apple(d) else: _mount(d) shell(d) if s: storage() time.sleep(5) i += 1
def _fileinfo(fp): ismount = os.path.ismount(os.path.realpath(fp)) isroot = os.path.samefile(fp, '/') if isroot: ismount = True name = os.path.basename(fp) mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime = os.stat(fp) try: owner = pwd.getpwuid(uid).pw_name except: owner = uid try: group = grp.getgrgid(gid).gr_name except: group = gid mtime = mtime * 1000 mode = oct(mode)[-3:] ext = os.path.splitext(name)[1].lower() isfile = os.path.isfile(fp) isdir = os.path.isdir(fp) islink = os.path.islink(fp) rpath = name if isdir: rpath = name + '/' try: size = len(os.listdir(fp)) except: size = 0 _u, _a, _p = _get_usage(fp) isstorage = os.path.samefile( fp, os.path.dirname(os.path.realpath('/box/storage'))) usage = { 'size': _u + _a, 'avail': _a, 'used': _u, 'storage': isstorage, 'root': isroot } udev = {} if os.path.dirname(fp) in ['/media', '/box/drives'] and ismount: dev = '/dev/disk/by-uuid/%s' % os.path.basename(os.path.realpath(fp)) if os.path.exists(dev): udev = _get_udev(dev) islink = False writable = True if fp == '/media' or fp == '/box/drives': writable = False name = 'computer' thumbnail = False mime = 'folder' charset = '' mime, charset = _get_mime(fp) _t = '%s/.thumbnails/.%s.jpg' % (os.path.dirname(fp), os.path.basename(fp)) if isfile and os.path.exists(_t) and os.path.getsize(_t) > 0: thumbnail = True return [ name, ext, size, mtime, isfile, isdir, islink, ismount, rpath, owner, group, mode, ino, usage, udev, writable, thumbnail, mime, charset ]
def _getconf(d): c=CONF%d if not os.path.exists(c):c=CONF%0 from disk import _get_udev u=_get_udev('/dev/video%s'%d) p={'mode':'','size':'','frequency':''} _get_name_value(c,p) if u.has_key('ID_USB_DRIVER'): if u['ID_USB_DRIVER']=='uvcvideo':p['mode']='yuv' return p
def read(): r=[] p='/media' l=os.listdir(p) for d in l: _d='%s/%s'%(p,d) dev='/dev/disk/by-uuid/%s'%d if not os.path.ismount(_d) or os.path.samefile(_d,'/') or not os.path.exists(dev):continue udev=_get_udev(dev) if udev.has_key('SUBSYSTEM') and udev['SUBSYSTEM']=='usb':continue r.append(_read(_d)) return r
def get(): p = '/media' l = os.listdir(p) storage = {'internal': {}, 'external': {}} root = '' for f in l: try: uf = '/dev/disk/by-uuid/%s' % f if not os.path.exists(uf): continue _p = '%s/%s' % (p, f) print f if os.path.samefile('/media/%s' % f, '/'): root = f print root if not os.path.ismount(_p): continue udev = _get_udev(uf) if udev['SUBSYSTEM'] == 'usb': continue s = os.statvfs(_p) a = s.f_bfree * s.f_bsize b = 'mmc' if udev.has_key('ID_BUS'): b = udev['ID_BUS'] d = udev['ID_FS_UUID'] tp = udev['ID_FS_TYPE'] pt = 'internal' if b == 'usb': pt = 'external' if tp: storage[pt][f] = {'size': a, 'uuid': d} except: continue he = '' size = 0 e = storage['external'] for _e in e: E = e[_e] sz = E['size'] if sz > size: size = sz he = E['uuid'] hi = '' size = 0 i = storage['internal'] for _i in i: I = i[_i] if os.path.samefile('/media/%s' % I['uuid'], '/') or os.path.samefile( '/media/%s' % I['uuid'], '/boot'): continue sz = I['size'] if sz > size: size = sz hi = I['uuid'] r = root if he != '': r = he if hi != '': r = hi return r
def get(): u, a = auth._auth() if not a: return 403 r = [] d = '/media' l = os.listdir(d) for i in l: udev = _get_udev('/dev/disk/by-uuid/%s' % i) if udev.has_key('ID_MTP_DEVICE') or (udev.has_key('ID_VENDOR') and udev['ID_VENDOR'] == 'Apple_Inc.'): r.append({ 'vendor': udev['ID_VENDOR'], 'model': udev['ID_MODEL'], 'uuid': i }) d = '/home/%s/.network' % u l = os.listdir(d) for i in l: f = '%s/%s' % (d, i) if not i.startswith('ftp') or not os.path.ismount(f): continue p = '%s/DCIM' % f if os.path.exists(p): r.append({'ftp': i}) return r
def batch(): m = '/media' p = '/dev/disk/by-uuid' l = os.listdir(m) for d in l: pd = '%s/%s' % (p, d) md = '%s/%s' % (m, d) if not os.path.exists(pd): _umount(d) l = os.listdir(p) for d in l: _md = '%s/%s' % (m, d) if os.path.exists(_md) and (os.path.ismount(_md) or os.path.samefile(_md, '/')): continue pd = '%s/%s' % (p, d) u = _get_udev(pd) if u.has_key('ID_MTP_DEVICE') and u['ID_MTP_DEVICE'] == '1': android(d, u['BUSNUM'], u['DEVNUM']) elif u.has_key('ID_VENDOR') and u['ID_VENDOR'] == 'Apple_Inc.': apple(d) else: _mount(d) shell(d) thread.start_new_thread(storage, ())