Example #1
0
File: drop.py Project: thouters/ltr
    def children(self):
        if self.ftype != "dir":
            return []
        names = listdir(self.diskpath)

        mounts = filter(lambda f: ismount(join(self.diskpath,f)),names)
        names = filter(lambda f: not ismount(join(self.diskpath,f)),names)
        for m in mounts:
            print "ltr: skip mount ", m

        if ".ltr" in names:
            if self.volpath != "/":
                print "ltr: skip ltrbox ", self.diskpath
            names.remove(".ltr")
        
        if self.ignoreFileName in names:
            f = open(join(self.diskpath,self.ignoreFileName),"r")
            ignores = f.readlines()
            f.close()
            #FIXME: use glob
            if "." in ignores:
                return []
            for ignore in ignores:
                if ignore in names:
                    names.remove(ignore)
        return map(lambda fname: LtrDrop(fname,self.volpath,self.fspath),names)
Example #2
0
def isProperDirection(path):
    if not path.startswith(target_mount):
        raise Exception("Wrong direction param, %s not starts with %s"%(path, target_mount)) 
    if (not ismount(source_mount)):
       logger.error("%s not mounted"%source_mount)
       raise Exception("%s not mounted"%source_mount) 
    if (not ismount(target_mount)):
       logger.error("%s not mounted"%target_mount)
       raise Exception("%s not mounted"%target_mount) 
Example #3
0
def wait_for_mount(mount_path):
    for c in xrange(20):
        if path.ismount(mount_path):
            return True
        time.sleep(.1)
    else:
        return False
Example #4
0
def find_mount_point(path):
    # Even if something's wrong, "/" is a mount point, so the loop will exit.
    # Use realpath in case it's a symlink
    path = op.realpath(path)  # Required to avoid infinite loop
    while not op.ismount(path):
        path = op.split(path)[0]
    return path
Example #5
0
def create_dirs(a):
    dirlist = []
    filelist = []
    _path_ = ''
    is_top = 0

    if a == RANDOM_NUMBER:
        dirlist = find_drives()
        _path_ = 'My Computer'
        is_top = 1
    else:
        chdir(a)
        b = listdir(a)

        for x in b:
            if not x[0] == '.':
                if path.isdir(x):
                    dirlist.append(x)
                elif path.isfile(x):
                    if x[-4:].upper() == '.WAV'\
                       or x[-4:].upper() == '.OGG'\
                       or x[-4:].upper() == '.MID'\
                       or x[-4:].upper() == '.CDA'\
                       or x[-3:].upper() == '.XM':
                        filelist.append(x)

        dirlist.sort()
        filelist.sort()

        if path.ismount(a):
            _path_ = a
        else:
            _path_ = path.split(a)[1]

    return (is_top, _path_, dirlist, filelist)
Example #6
0
	def __init__(self, *argz, **kwz):
		super(CGAcct, self).__init__(*argz, **kwz)

		self.stuck_list = join(self.conf.cg_root, 'sticky.cgacct')

		# Check which info is available, if any
		self.rc_collectors = list()
		for rc in self.conf.resource_controllers:
			try: rc_collector = getattr(self, rc)
			except AttributeError:
				log.warn( 'Unable to find processor'
					' method for rc {!r} metrics, skipping it'.format(rc) )
				continue
			rc_path = join(self.conf.cg_root, rc)
			if not ismount(rc_path + '/'):
				log.warn(( 'Specified rc path ({}) does not'
					' seem to be a mountpoint, skipping it' ).format(rc_path))
				continue
			log.debug('Using cgacct collector for rc: {}'.format(rc))
			self.rc_collectors.append(rc_collector)

		if not self.rc_collectors: # no point doing anything else
			log.info('No cgroup rcs to poll (rc_collectors), disabling collector')
			self.conf.enabled = False
			return

		# List of cgroup sticky bits, set by this service
		self._stuck_list_file = open(self.stuck_list, 'ab+')
		self._stuck_list = dict()
		fcntl.lockf(self._stuck_list_file, fcntl.LOCK_EX | fcntl.LOCK_NB)
		self._stuck_list_file.seek(0)
		for line in self._stuck_list_file:
			rc, svc = line.strip().split()
			if rc not in self._stuck_list: self._stuck_list[rc] = set()
			self._stuck_list[rc].add(svc)
Example #7
0
	def __init__(self):
		self.hdd = [ ]
		self.cd = ""
		self.partitions = [ ]
		self.devices_scanned_on_init = [ ]
		self.on_partition_list_change = CList()
		self.enumerateBlockDevices()
		# Find stuff not detected by the enumeration
		p = (
			("/media/hdd", _("Harddisk")),
			("/media/card", _("Card")),
			("/media/cf", _("Compact Flash")),
			("/media/mmc1", _("MMC Card")),
			("/media/net", _("Network Mount")),
			("/media/net1", _("Network Mount") + " 1"),
			("/media/net2", _("Network Mount") + " 2"),
			("/media/net3", _("Network Mount") + " 3"),
			("/media/ram", _("Ram Disk")),
			("/media/usb", _("USB Stick")),
			("/", _("Internal Flash"))
		)
		known = set([path.normpath(a.mountpoint) for a in self.partitions if a.mountpoint])
		for m,d in p:
			if (m not in known) and path.ismount(m):
				self.partitions.append(Partition(mountpoint=m, description=d))
Example #8
0
def mount_devices(target_nbd_device):
    """
    Performs functions required to mount the NBD device to the file system

    Creates the desired mount point if it doesn't exist;
    Ensures nothing is already mounted at the mount point;
    Mounts the appropriate NBD device at the desired mount point;

    """
    log.debug("Trying to mount %s at %s" % (target_nbd_device, MOUNT_POINT))

    # Create mount point if it doesn't already exist
    if not path.exists(MOUNT_POINT):
        log.warning("Creating the mount point at %s" % MOUNT_POINT)
        mkdir(MOUNT_POINT)

    # Check MOUNT_POINT isn't already mounted
    if path.ismount(MOUNT_POINT):
        mounted_on = check_output("mount | grep %s | cut -f 1 -d ' '" % MOUNT_POINT, shell=True)
        exit("The target path is already mounted on %sPlease un-mount this path first." % mounted_on.decode())

    # Mount nbd_device_to_mount to MOUNT_POINT
    try:
        # need to pause before mounting the NBD device, to prevent mount attempt before partitions are recognised
        sleep(2)
        check_output(["mount", target_nbd_device, MOUNT_POINT])
    except CalledProcessError:
        exit("Everything seemed to go fine, right up until mounting %s at %s!" % (target_nbd_device, MOUNT_POINT))

    log.debug("%s successfully mounted at %s" % (target_nbd_device, MOUNT_POINT))
Example #9
0
def is_nonroot_mountpoint():
    backup_dir = BACKUPDIR
    while backup_dir != "/":
        if path.ismount(backup_dir):
            return True
        else:
            backup_dir = path.dirname(backup_dir)
    return False
Example #10
0
def mount_path(path):
    """Get the mount root of a directory"""
    path = abspath(realpath(path))
    while path != '/':
        if ismount(path):
            return path
        path = dirname(path)
    return '/'
def test115():
    f = __file__
    assert path.isabs(f) == True
    assert path.isdir(f) == False
    assert path.isfile(f) == True
    assert path.islink(f) == False
    assert path.ismount(f) == False
    assert path.exists(f) == True
Example #12
0
	def populate_List(self):
		self['lab1'].setText(_("Select a package to install:"))

		del self.list[:]
		f = listdir(self.defaultDir)
		for line in f:
			if line.find('.ipk') != -1:
				self.list.append(line)
		
		if path.ismount('/media/usb'):
			f = listdir('/media/usb')
			for line in f:
				if line.find('.ipk') != -1:
					self.list.append(line)
		elif path.ismount('/media/hdd'):
			f = listdir('/media/hdd')
			for line in f:
				if line.find('.ipk') != -1:
					self.list.append(line)

		self.list.sort()
		self['list'].l.setList(self.list)
def getCoverPath():
	blockList = ['hdd','cf','usb','sdcard']
	dirList = os_listdir("/media")
	coverPaths = ['/usr/share/enigma2/cover/', '/data/cover/', '/media/cf/cover/', '/media/usb/cover/', '/media/sdcard/cover/', '/media/hdd/cover/']

	if fileExists("/proc/mounts"):
		mountsFile = open("/proc/mounts" ,"r")
		for line in mountsFile:
			entry = line.split()
			if entry[2] in ["nfs", "nfs4", "smbfs", "cifs"]:
				if entry[1].startswith("/media/"):
					blockList.append(entry[1][7:])
		mountsFile.close()

	for dir in dirList:
		if dir in blockList:
			print dir, blockList
			continue
		if os_path.ismount("/media/%s" %(dir)) or (os_path.islink("/media/%s" %(dir)) and os_path.ismount(os_path.realpath("/media/%s" %(dir)))):
			path = "/media/%s/cover/" % (dir)
			coverPaths.append(path)
	return coverPaths
Example #14
0
def countFiles(dirpath,onefilesystem=True):
    """
    Count files in dirpath
    """
    num = 1
    for dirpath,dirnames,filenames in os.walk(dirpath):
        num += len(set(dirnames) | set(filenames))
        if onefilesystem:
            mountDirs = filter(lambda x:path.ismount(path.join(dirpath,x)),
                        dirnames)
            for dirname in mountDirs:
                dirnames.remove(dirname)
    return num
Example #15
0
	def new_client(self):
		mnt = self.mountpt + '.' + str(self.handler_id)
		if exists(mnt):
			if ismount(mnt):
				print 'Filesystem already mounted at %s' % mnt
				return
		else:
			mkdir(mnt)

		print 'Mounting client DOM at %s' % mnt
		FUSE(DomFS(self), mnt, foreground=True)
		rmdir(mnt)
		self.send_close()
Example #16
0
	def _onSharesApplied(self):
		Log.d()
		for sharename, data in self._mounts.items():
			mountpoint = AutoMount.MOUNT_BASE + sharename
			Log.d("mountpoint: %s" %(mountpoint,))
			if os_path.exists(mountpoint):
				if os_path.ismount(mountpoint):
					Log.d("'%s' is mounted" %(mountpoint,))
					data['isMounted'] = True
					desc = data['sharename']
					if data['hdd_replacement']: #hdd replacement hack
						self._linkAsHdd(mountpoint)
					harddiskmanager.addMountedPartition(mountpoint, desc)
				else:
					Log.d("'%s' is NOT mounted" %(mountpoint,))
					sharename = self._mounts.get(data['sharename'], None)
					if sharename:
						data['isMounted'] = False
					if os_path.exists(mountpoint):
						if not os_path.ismount(mountpoint):
							removeDir(mountpoint)
							harddiskmanager.removeMountedPartition(mountpoint)
Example #17
0
def get_path_type(path_):
    """
    returns if a path is a file, directory, link, or mount
    """
    path_type = ''
    if isfile(path_):
        path_type += 'file'
    if isdir(path_):
        path_type += 'directory'
    if islink(path_):
        path_type += 'link'
    if ismount(path_):
        path_type += 'mount'
    return path_type
Example #18
0
def _check_for_directory():
    checkdirectory = os.getcwd()
    directories_checked = []
    hitch_directory = None

    while not ismount(checkdirectory):
        directories_checked.append(checkdirectory)
        if exists(join(checkdirectory, DOTDIR)):
            hitch_directory = join(checkdirectory, DOTDIR)
            break
        else:
            checkdirectory = abspath(join(checkdirectory, os.pardir))

    return hitch_directory, directories_checked
Example #19
0
	def doBackup1(self):
		print '[ImageManager] Stage1: Creating tmp folders.', self.BackupDirectory
		print '[ImageManager] Stage1: Creating backup Folders.'
		if path.exists(self.WORKDIR):
			rmtree(self.WORKDIR)
		mkdir(self.WORKDIR, 0644)
		print '[ImageManager] Stage1: Create root folder.'
		if path.exists(self.TMPDIR + '/root') and path.ismount(self.TMPDIR + '/root'):
			system('umount ' + self.TMPDIR + '/root')
		elif path.exists(self.TMPDIR + '/root'):
			rmtree(self.TMPDIR + '/root')
		if path.exists(self.TMPDIR):
			rmtree(self.TMPDIR)
		makedirs(self.TMPDIR + '/root', 0644)
		makedirs(self.MAINDESTROOT, 0644)
		self.commands = []
		print '[ImageManager] Stage1: Making Root Image.'
		makedirs(self.MAINDEST, 0644)
		if self.ROOTFSTYPE == 'jffs2':
			print '[ImageManager] Stage1: JFFS2 Detected.'
			if getMachineBuild() == 'vuuno':
				JFFS2OPTIONS = " --disable-compressor=lzo -126976 -l -p125829120"
			if getMachineBuild() in ('dm800', 'dm800se','dm500hd'):
				JFFS2OPTIONS = " --eraseblock=0x4000 -n -l"
			else:
				JFFS2OPTIONS = " --disable-compressor=lzo --eraseblock=0x20000 -n -l"
			self.commands.append('mount --bind / ' + self.TMPDIR + '/root')
			self.commands.append('mount -t jffs2 /dev/mtdblock/2 ' + self.TMPDIR + '/boot')
			self.commands.append('mkfs.jffs2 --root=' + self.TMPDIR + '/root --faketime --output=' + self.WORKDIR + '/root.jffs2' + JFFS2OPTIONS)
			if getMachineBuild() in ('dm800', 'dm800se', 'dm500hd'):
				self.commands.append('mkfs.jffs2 --root=' + self.TMPDIR + '/boot --faketime --output=' + self.WORKDIR + '/boot.jffs2' + JFFS2OPTIONS)
		else:
			print '[ImageManager] Stage1: UBIFS Detected.'
			UBINIZE = 'ubinize'
			UBINIZE_ARGS = getMachineUBINIZE()
			MKUBIFS_ARGS = getMachineMKUBIFS()
			output = open(self.WORKDIR + '/ubinize.cfg', 'w')
			output.write('[ubifs]\n')
			output.write('mode=ubi\n')
			output.write('image=' + self.WORKDIR + '/root.ubi\n')
			output.write('vol_id=0\n')
			output.write('vol_type=dynamic\n')
			output.write('vol_name=rootfs\n')
			output.write('vol_flags=autoresize\n')
			output.close()
			self.commands.append('mount --bind / ' + self.TMPDIR + '/root')
			self.commands.append('touch ' + self.WORKDIR + '/root.ubi')
			self.commands.append('mkfs.ubifs -r ' + self.TMPDIR + '/root -o ' + self.WORKDIR + '/root.ubi ' + MKUBIFS_ARGS)
			self.commands.append('ubinize -o ' + self.WORKDIR + '/root.ubifs ' + UBINIZE_ARGS + ' ' + self.WORKDIR + '/ubinize.cfg')
		self.Console.eBatch(self.commands, self.Stage1Complete, debug=False)
Example #20
0
	def doBackup1(self):
		print '[ImageManager] Stage1: Creating tmp folders.', self.BackupDirectory
		print '[ImageManager] Stage1: Creating backup Folders.'
		if path.exists(self.WORKDIR):
			rmtree(self.WORKDIR)
		mkdir(self.WORKDIR, 0644)
		if path.exists(self.TMPDIR + '/root') and path.ismount(self.TMPDIR + '/root'):
			system('umount ' + self.TMPDIR + '/root')
		elif path.exists(self.TMPDIR + '/root'):
			rmtree(self.TMPDIR + '/root')
		if path.exists(self.TMPDIR):
			rmtree(self.TMPDIR)
		if not getImageFileSystem() == 'tar.bz2':
			makedirs(self.TMPDIR + '/root', 0644)
		makedirs(self.MAINDESTROOT, 0644)
		self.commands = []
		print '[ImageManager] Stage1: Making Root Image.'
		makedirs(self.MAINDEST, 0644)
		if self.ROOTFSTYPE == 'jffs2':
			print '[ImageManager] Stage1: JFFS2 Detected.'
			if getMachineBuild() == 'gb800solo':
				JFFS2OPTIONS = " --disable-compressor=lzo -e131072 -l -p125829120"
			else:
				JFFS2OPTIONS = " --disable-compressor=lzo --eraseblock=0x20000 -n -l"
			self.commands.append('mount --bind / %s/root' % self.TMPDIR)
			self.commands.append('mkfs.jffs2 --root=%s/root --faketime --output=%s/rootfs.jffs2 %s' %(self.TMPDIR, self.self.WORKDIR, JFFS2OPTIONS))
		elif self.ROOTFSTYPE == 'tar.bz2':
			print '[ImageManager] Stage1: TAR.BZIP Detected.'
			self.commands.append('mount --bind / %s/root' % self.TMPDIR)
			self.commands.append("/bin/tar -cf %s/rootfs.tar -C %s/root ." % (self.WORKDIR, self.TMPDIR))
			self.commands.append("/usr/bin/bzip2 %s/rootfs.tar" % self.WORKDIR)
		else:
			print '[ImageManager] Stage1: UBIFS Detected.'
			UBINIZE_ARGS = getMachineUBINIZE()
			MKUBIFS_ARGS = getMachineMKUBIFS()
			output = open('%s/ubinize.cfg' % self.WORKDIR, 'w')
			output.write('[ubifs]\n')
			output.write('mode=ubi\n')
			output.write('image=%s/root.ubi\n' % self.WORKDIR)
			output.write('vol_id=0\n')
			output.write('vol_type=dynamic\n')
			output.write('vol_name=rootfs\n')
			output.write('vol_flags=autoresize\n')
			output.close()
			self.commands.append('mount --bind / %s/root' % self.TMPDIR)
			self.commands.append('touch %s/root.ubi' % self.WORKDIR)
			self.commands.append('mkfs.ubifs -r %s/root -o %s/root.ubi %s' % (self.TMPDIR, self.WORKDIR, MKUBIFS_ARGS))
			self.commands.append('ubinize -o %s/rootfs.ubifs %s %s/ubinize.cfg' % (self.WORKDIR, UBINIZE_ARGS, self.WORKDIR))
		self.Console.eBatch(self.commands, self.Stage1Complete, debug=False)
Example #21
0
 def spawn_neovimfs(self):
     """
     Mount the NeovimFS filesystem if not already mounted.
     Otherwise, register the current client using the filesystem interface (`/clients/new`).
     """
     if not exists(self.config['mountpoint']):
         mkdir(self.config['mountpoint'])
     if not ismount(self.config['mountpoint']):
         # NVIM_LISTEN_ADDRESS is used from the environment
         p = Popen([fs_script, self.config['mountpoint']])
     else:
         start_addr = environ['NVIM_LISTEN_ADDRESS']
         # start_addr -> /clients/new
         p = join(self.config['mountpoint'], 'clients', 'new')
         with open(p, 'w') as newf:
             newf.write(start_addr)
Example #22
0
def get_partitions():
    p_lsblk = Popen(['lsblk'], stdout=PIPE)
    p_awk = Popen(['awk', '{print $7}'], stdin=p_lsblk.stdout, stdout=PIPE)
    p_grep = Popen(['grep', '/'], stdin=p_awk.stdout, stdout=PIPE)
    p_lsblk.stdout.close()
    p_awk.stdout.close()
    output = p_grep.communicate()[0]
    for line in output.splitlines():
        device = line.rstrip().decode('utf-8')
        if not ismount(device):
            continue
        if device.startswith('/snap/') or device == '/boot/efi':
            continue
        if (device == "/"):
            yield device, "Root"
        else:
            yield device, basename(normpath(device)).capitalize()
Example #23
0
def get_ring(server, force_validate=None):
    ring = Ring('/etc/swift/%s.ring.gz' % server)
    if not VALIDATE_RSYNC and not force_validate:
        return ring
    # easy sanity checks
    assert 3 == ring.replica_count, '%s has %s replicas instead of 3' % (
        ring.serialized_path, ring.replica_count)
    assert 4 == len(ring.devs), '%s has %s devices instead of 4' % (
        ring.serialized_path, len(ring.devs))
    # map server to config by port
    port_to_config = {}
    for node_id in range(1, 5):
        conf = readconf('/etc/swift/%s-server/%d.conf' % (server, node_id),
                        section_name='%s-replicator' % server)
        port_to_config[int(conf['bind_port'])] = conf
    for dev in ring.devs:
        # verify server is exposing mounted device
        conf = port_to_config[dev['port']]
        for device in os.listdir(conf['devices']):
            if device == dev['device']:
                full_path = path.realpath(path.join(conf['devices'], device))
                assert path.ismount(full_path), \
                    'device %s in %s was not mounted (%s)' % (
                        device, conf['devices'], full_path)
                break
        else:
            raise AssertionError(
                "unable to find ring device %s under %s's devices (%s)" % (
                    dev['device'], server, conf['devices']))
        # verify server is exposing rsync device
        rsync_export = '%s%s' % (server, dev['replication_port'])
        cmd = "rsync rsync://localhost/%s" % rsync_export
        p = Popen(cmd, shell=True, stdout=PIPE)
        stdout, _stderr = p.communicate()
        if p.returncode:
            raise AssertionError('unable to connect to rsync '
                                 'export %s (%s)' % (rsync_export, cmd))
        for line in stdout.splitlines():
            if line.rsplit(None, 1)[-1] == dev['device']:
                break
        else:
            raise AssertionError("unable to find ring device %s under rsync's "
                                 "exported devices for %s (%s)" % (
                                     dev['device'], rsync_export, cmd))
    return ring
Example #24
0
	def runBackup(self, result):
		if result:
			if path.ismount(MountPoints[self.backup.location.value]):
				self.createBackupfolders()
				d = localtime()
				dt = date(d.tm_year, d.tm_mon, d.tm_mday)
				self.path = BackupPath[self.backup.location.value]
				if self.backup.type.value == "settings":
					print "Backup Mode: Settings"
					self.session.open(Console, title = "Backup running", cmdlist = ["tar -czvf " + self.path + "/" + str(dt) + "_settings_backup.tar.gz /etc/enigma2/ /etc/network/interfaces /etc/wpa_supplicant.conf"])
				elif self.backup.type.value == "var":
					print "Backup Mode: var"
					self.session.open(Console, title = "Backup running", cmdlist = [ "tar -czvf " + self.path + "/" + str(dt) + "_var_backup.tar.gz /var/"])
				elif self.backup.type.value == "skin":
					print "Backup Mode: skin"
					self.session.open(Console, title ="Backup running", cmdlist = [ "tar -czvf " + self.path + "/" + str(dt) + "_skin_backup.tar.gz /usr/share/enigma2/"])
			else:
				self.session.open(MessageBox, _("Sorry your Backup destination does not exist\n\nPlease choose an other one."), MessageBox.TYPE_INFO)
Example #25
0
	def checkStoragePath(self):
		tmppath = config.mediaportal.storagepath.value
		if tmppath != "/tmp" and tmppath != "/media/ba":
			if os_path.islink(tmppath):
				tmppath = os_readlink(tmppath)
			loopcount = 0
			while not os_path.ismount(tmppath):
				loopcount += 1
				tmppath = os_path.dirname(tmppath)
				if tmppath == "/" or tmppath == "" or loopcount > 50:
					self.session.open(MessageBoxExt, _("Error: Can not create cache-folders inside flash memory. Check your Cache-Folder Settings!"), type=MessageBoxExt.TYPE_INFO, timeout=20)
					return False

		os_system("mkdir -p "+config.mediaportal.storagepath.value)
		if not os_path.exists(config.mediaportal.storagepath.value):
			self.session.open(MessageBoxExt, _("Error: No write permission to create cache-folders. Check your Cache-Folder Settings!"), type=MessageBoxExt.TYPE_INFO, timeout=20)
			return False
		else:
			return True
Example #26
0
 def _do_mount(self):
     assert not ismount(self.connect_args.mp)
     self.connect_args.required_for_mount('pw')
     self.created_for_mount = self._ensure_mount_dir_exists()
     if self.connect_args.domain!=None:
         credentials = "domain=%s\nusername=%s\npassword=%s\n" % \
                       (self.connect_args.domain, self.connect_args.user, self.connect_args.pw)
         logger.info("credentials: domain=%s, username=%s, password=****" % (self.connect_args.domain,
                                                                            self.connect_args.user))
     else:
         credentials = "username=%s\npassword=%s\n" % (self.connect_args.user,
                                                       self.connect_args.pw)
         logger.info("credentials: username=%s, password=****" % self.connect_args.user)
     def do_mount(credentials_file):
         for mtry in [1, 2, 3]:
             if mtry==1:
                 options = ['noperm', 'credentials=%s' % credentials_file, 'sec=ntlmv2']
             elif mtry ==2:
                 options = ['noperm', 'credentials=%s' % credentials_file, 'sec=ntlm']
             else:
                 options = ['noperm', 'credentials=%s' % credentials_file]
             if self.connect_args.read_only:
                 options.append('ro')
             else:
                 options.append('rw')
             if self.connect_args.direct_attribute_access==True:
                 options.append('actimeo=0')
             cmd = ['/sbin/mount.cifs', self.df_name, self.connect_args.mp, '-o'] + \
                   [','.join(options)]
             if os.getuid()!=0:
                 cmd = ['/usr/bin/sudo',] + cmd
             rc = process.run_and_log_program(cmd, None, logger)
             if rc!=0 and mtry==1:
                 logger.warn("Unable to mount with sec=ntlmv2, will try again using sec=ntlm")
             elif rc!=0 and mtry==2:
                 logger.warn("Unable to mount with sec=ntlm, will try again using no sec option.")
             elif rc!=0 and mtry==3:
                 raise FsMgrError("mount failed: non-zero return code %d when running %s" %
                                  (rc, ' '.join(cmd)))
             else:
                 return
     run_with_secure_tempfile(credentials, do_mount, only_root_accessible=True)
Example #27
0
    def populate_List(self):
        if self.defaultDir == '/tmp':
            self['key_yellow'].setText(_("Extra IPK's"))
        else:
            self['key_yellow'].setText(_('Temp Folder'))
        self['lab1'].setText(_('Select a package to install:'))
        del self.list[:]
        f = listdir(self.defaultDir)
        for line in f:
            if line.find('.ipk') != -1:
                self.list.append(line)

        if path.ismount('/media/usb'):
            f = listdir('/media/usb')
            for line in f:
                if line.find('.ipk') != -1:
                    self.list.append(line)

        self.list.sort()
        self['list'].l.setList(self.list)
Example #28
0
def relative_path(filename):
    """return the relative path to a mount point for a file on a removable disc"""
    from os.path import isabs, ismount, split, join

    if not isabs(filename) and not ismount(filename): return filename
    drivepaths = []
    for item in config.REMOVABLE_MEDIA:
        drivepaths.append(item.mountdir)
    for path in drivepaths:
        if filename.find(path) != -1:
            head = filename
            tail = ''
            while (head != path):
                x = split(head)
                head = x[0]
                if x[0] == '/' and x[1] == '' : return filename
                elif tail == '': tail = x[1]
                else: tail = join(x[1], tail)

            if head == path: return tail

    return filename
Example #29
0
 def __init__(self):
     self.hdd = []
     self.cd = ''
     self.partitions = []
     self.devices_scanned_on_init = []
     self.on_partition_list_change = CList()
     self.enumerateBlockDevices()
     p = (('/media/hdd', _('Harddisk')),
      ('/media/card', _('Card')),
      ('/media/cf', _('Compact Flash')),
      ('/media/mmc1', _('MMC Card')),
      ('/media/net', _('Network Mount')),
      ('/media/net1', _('Network Mount') + ' 1'),
      ('/media/net2', _('Network Mount') + ' 2'),
      ('/media/net3', _('Network Mount') + ' 3'),
      ('/media/ram', _('Ram Disk')),
      ('/media/usb', _('USB Stick')),
      ('/', _('Internal Flash')))
     known = set([ path.normpath(a.mountpoint) for a in self.partitions if a.mountpoint ])
     for m, d in p:
         if m not in known and path.ismount(m):
             self.partitions.append(Partition(mountpoint=m, description=d))
def recursive_walk(root):
    children = []
    try:
        files = os.listdir(root)
    except OSError:
        pass # ignore, regard as empty
    else:
        for fname in files:
            fullname = path.join(root, fname)
            if not path.islink(fullname) and not path.ismount(fullname): # ignore links and mounts
                if path.isdir(fullname):
                    children.append(recursive_walk(fullname))
                else:
                    fsize = path.getsize(fullname)
                    if fsize > 0: # ignore zero sized files
                        children.append(File(fname, fsize))
    # sort children by size
    children.sort(File.cmp)
    (_,name) = path.split(root)
    size = sum([child.size for child in children]) # total size of children
    size += path.getsize(root) # size of dir itself
    return File(name, size, children)
Example #31
0
 def ismount(path=("StringPin", "", {PinSpecifires.INPUT_WIDGET_VARIANT: "PathWidget"})):
     '''Return True if pathname path is a mount point: a point in a file system where a different file system has been mounted. The function checks whether path’s parent, path/.., is on a different device than path, or whether path/.. and path point to the same i-node on the same device — this should detect mount points for all Unix and POSIX variants.'''
     return osPath.ismount(path)
Example #32
0
 def appClosed(self, data="", retval=0, extra_args=None):
     BuildVersion = "  "
     Build = " "  # ViX Build No.
     Dev = " "  # ViX Dev No.
     Creator = " "  # Openpli Openvix Openatv etc
     Date = " "
     BuildType = " "  # release etc
     if retval:
         self.imagelist[self.slot] = {"imagename": _("Empty slot")}
     if retval == 0 and self.phase == self.MOUNT:
         if SystemInfo["HasRootSubdir"] and SystemInfo["canMultiBoot"][
                 self.slot]["rootsubdir"] != None:
             imagedir = (
                 '%s/%s' %
                 (Imagemount,
                  SystemInfo["canMultiBoot"][self.slot]["rootsubdir"]))
         else:
             imagedir = Imagemount
         if path.isfile("%s/usr/bin/enigma2" % imagedir):
             Creator = open("%s/etc/issue" % imagedir).readlines(
             )[-2].capitalize().strip()[:-6].replace("-release", " rel")
             if Creator.startswith("Openvix"):
                 reader = boxbranding_reader(imagedir)
                 BuildType = reader.getImageType()
                 Build = reader.getImageBuild()
                 Dev = BuildType != "release" and " %s" % reader.getImageDevBuild(
                 ) or ""
                 BuildVersion = "%s %s %s %s" % (Creator, BuildType[0:3],
                                                 Build, Dev)
             else:
                 try:
                     from datetime import datetime
                     date = datetime.fromtimestamp(
                         stat(path.join(
                             imagedir,
                             "var/lib/opkg/status")).st_mtime).strftime(
                                 "%Y-%m-%d")
                     if date.startswith("1970"):
                         date = datetime.fromtimestamp(
                             stat(
                                 path.join(imagedir,
                                           "usr/share/bootlogo.mvi")).
                             st_mtime).strftime("%Y-%m-%d")
                     date = max(
                         date,
                         datetime.fromtimestamp(
                             stat(path.join(
                                 imagedir,
                                 "usr/bin/enigma2")).st_mtime).strftime(
                                     "%Y-%m-%d"))
                 except Exception:
                     date = _("Unknown")
                 BuildVersion = "%s (%s)" % (open(
                     path.join(imagedir, "etc/issue")).readlines(
                     )[-2].capitalize().strip()[:-6], date)
             self.imagelist[self.slot] = {"imagename": "%s" % BuildVersion}
         else:
             self.imagelist[self.slot] = {"imagename": _("Empty slot")}
         if self.slots and SystemInfo["canMultiBoot"][
                 self.slot]["device"] == SystemInfo["canMultiBoot"][
                     self.slots[0]]["device"]:
             self.slot = self.slots.pop(0)
             self.appClosed()
         else:
             self.phase = self.UNMOUNT
             self.run()
     elif self.slots:
         self.phase = self.MOUNT
         self.run()
     else:
         self.container.killAll()
         if not path.ismount(Imagemount):
             rmdir(Imagemount)
         self.callback(self.imagelist)
Example #33
0
 def ismount(self):
     return p.ismount(self.name)
Example #34
0
def get_repo_instance(path=curdir, class_=None):
    """Returns an instance of appropriate datalad repository for path.

    Check whether a certain path is inside a known type of repository and
    returns an instance representing it. May also check for a certain type
    instead of detecting the type of repository.

    Parameters
    ----------
    path: str
      path to check; default: current working directory

    class_: class
      if given, check whether path is inside a repository, that can be
      represented as an instance of the passed class.

    Raises
    ------
    RuntimeError, in case cwd is not inside a known repository.
    """

    from os.path import join as opj, ismount, exists, abspath, expanduser, \
        expandvars, normpath, isabs
    from git.exc import InvalidGitRepositoryError
    from ..utils import expandpath
    from ..support.gitrepo import GitRepo
    from ..support.annexrepo import AnnexRepo

    dir_ = expandpath(path)
    abspath_ = path if isabs(path) else dir_
    if class_ is not None:
        if class_ == AnnexRepo:
            type_ = "annex"
        elif class_ == GitRepo:
            type_ = "git"
        else:
            raise RuntimeError("Unknown class %s." % str(class_))

    while not ismount(dir_):  # TODO: always correct termination?
        if exists(opj(dir_, '.git')):
            # found git dir
            if class_ is None:
                # detect repo type:
                try:
                    return AnnexRepo(dir_, create=False)
                except RuntimeError as e:
                    pass
                try:
                    return GitRepo(dir_, create=False)
                except InvalidGitRepositoryError as e:
                    raise RuntimeError("No datalad repository found in %s" %
                                       abspath_)
            else:
                try:
                    return class_(dir_, create=False)
                except (RuntimeError, InvalidGitRepositoryError) as e:
                    raise RuntimeError("No %s repository found in %s." %
                                       (type_, abspath_))
        else:
            dir_ = normpath(opj(dir_, ".."))

    if class_ is not None:
        raise RuntimeError("No %s repository found in %s" % (type_, abspath_))
    else:
        raise RuntimeError("No datalad repository found in %s" % abspath_)
Example #35
0
 def unmountCallback(self, value, data=None, retval=None, extra_args=None):
     self.container.killAll()
     if not path.ismount(self.mountDir):
         rmdir(self.mountDir)
     self.close(value)
Example #36
0
def isMount(path):
    return os_path.ismount(path)
Example #37
0
def getMultiBootSlots():
    global bootSlots, startupDevice
    bootSlots = {}
    mode12Found = False
    if startupDevice is None:
        startupDevice = getMultiBootStartupDevice()
    if startupDevice:
        tempDir = mkdtemp(prefix=PREFIX)
        Console().ePopen((MOUNT, MOUNT, startupDevice, tempDir))
        for file in glob(pathjoin(tempDir, "STARTUP_*")):
            if "STARTUP_RECOVERY" in file:
                BoxInfo.setItem("RecoveryMode", True)
                print("[MultiBoot] Recovery mode is set to True.")
            if "MODE_" in file:
                mode12Found = True
                slotNumber = file.rsplit("_", 3)[1]
            else:
                slotNumber = file.rsplit("_", 1)[1]
            if slotNumber.isdigit() and slotNumber not in bootSlots:
                lines = fileReadLines(file, source=MODULE_NAME)
                if lines:
                    slot = {}
                    for line in lines:
                        if "root=" in line:
                            device = getArgValue(line, "root")
                            if exists(device):
                                slot["device"] = device
                                slot["startupfile"] = basename(file)
                                if "rootsubdir" in line:
                                    BoxInfo.setItem("HasRootSubdir", True)
                                    slot["kernel"] = getArgValue(
                                        line, "kernel")
                                    slot["rootsubdir"] = getArgValue(
                                        line, "rootsubdir")
                                elif "sda" in line:
                                    slot["kernel"] = getArgValue(
                                        line, "kernel")
                                    slot["rootsubdir"] = None
                                else:
                                    slot["kernel"] = "%sp%s" % (device.split(
                                        "p")[0], int(device.split("p")[1]) - 1)
                                bootSlots[int(slotNumber)] = slot
                            break
                else:
                    print(
                        "[MultiBoot] Warning: No content in file '%s' for slot number '%s'!"
                        % (file, slotNumber))
            else:
                print(
                    "[MultiBoot] Warning: Unexpected slot number '%s' in file '%s'!"
                    % (slotNumber, file))
        Console().ePopen((UMOUNT, UMOUNT, tempDir))
        if not ismount(tempDir):
            rmdir(tempDir)
        if not mode12Found and BoxInfo.getItem("canMode12"):
            # The boot device has ancient content and does not contain the correct STARTUP files!
            for slot in range(1, 5):
                bootSlots[slot] = {
                    "device": "/dev/mmcblk0p%s" % (slot * 2 + 1),
                    "startupfile": None
                }
    if bootSlots:
        for slot in sorted(list(bootSlots.keys())):
            print("[MultiBoot] Boot slot %d: %s" %
                  (slot, str(bootSlots[slot])))
    else:
        print("[MultiBoot] No boot slots found.")
    return bootSlots
Example #38
0
def run():
    checkdirectory = os.getcwd()
    directories_checked = []
    keypy_filename = None
    arguments = sys.argv[1:]

    python3, virtualenv = utils.check_python_and_virtualenv(
        None,
        None,
    )

    if len(arguments) > 0:
        if arguments[0] == "--demo" or arguments[0] == "--skeleton":
            try:
                utils.ensure_share_directory_exists()
                if not exists(utils.quickstart_path()):
                    utils.check_call([
                        virtualenv,
                        utils.quickstart_path(), "--no-site-packages", "-p",
                        python3
                    ])
                pip = join(utils.quickstart_path(), "bin", "pip")
                utils.check_call([
                    pip,
                    "install",
                    "pip",
                    "--upgrade",
                ])
                utils.check_call([
                    pip,
                    "install",
                    "hitchqs",
                    "--upgrade",
                ])
                quickstart = abspath(
                    join(utils.quickstart_path(), "bin", "quickstart"))
                os.execve(quickstart, [quickstart] + [
                    arguments[0][2:],
                ] + arguments[1:], utils.execution_env())
                return
            except utils.CalledProcessError:
                rmtree(utils.quickstart_path(), ignore_errors=True)
                sys.exit(1)

    while not ismount(checkdirectory):
        if exists("{0}{1}key.py".format(checkdirectory, os.sep)):
            keypy_filename = "{0}{1}key.py".format(checkdirectory, os.sep)
            break
        elif exists(join(checkdirectory, "hitch", "key.py")):
            keypy_filename = join(checkdirectory, "hitch", "key.py")
            break
        else:
            directories_checked.append(join(checkdirectory, "hitch"))
            directories_checked.append(checkdirectory)
            checkdirectory = abspath(join(checkdirectory, os.pardir))

    if not keypy_filename:
        sys.stderr.write("key.py not found in the following directories:\n\n")
        sys.stderr.write('\n'.join(directories_checked))
        sys.stderr.write(
            "\n\nCreate a key.py file in a convenient project directory to begin.\n"
        )
        sys.exit(1)

    keypy_directory = dirname(keypy_filename)

    gensymlink = abspath(join(keypy_directory, "gen"))

    if len(arguments) > 0:
        if arguments[0] == "--clean":
            if len(arguments) == 1:
                if exists(gensymlink):
                    rmtree(realpath(gensymlink))
                    os.remove(gensymlink)
                    rmtree(abspath(join(keypy_directory, "__pycache__")),
                           ignore_errors=True)
                    sys.exit(0)
                else:
                    print("No genfiles or pycache to clean for this project.")
                    sys.exit(1)

    if exists(gensymlink):
        genpath = realpath(gensymlink)
    else:
        genpath = new_hitch_dir()

    if not exists(genpath):
        makedirs(genpath)
        try:
            utils.check_call([
                virtualenv,
                join(genpath, "hvenv"), "--no-site-packages", "-p", python3
            ])
            utils.check_call(
                [join(genpath, "hvenv", "bin", "pip"), "install", "hitchrun"])
            with open(join(genpath, "hvenv", "linkfile"), 'w') as handle:
                handle.write(keypy_directory)
            os.symlink(genpath, join(keypy_directory, "gen"))
        except utils.CalledProcessError:
            rmtree(genpath, ignore_errors=True)
            sys.exit(1)
    hitchrun = abspath(join(genpath, "hvenv", "bin", "hitchrun"))
    os.execve(hitchrun, [hitchrun] + arguments, utils.execution_env())
Example #39
0
# You can edit these three lines to suit...
test_dir = expanduser('~/0inst-test')  # Where to put test files
version = '0.1.26'  # Version of lazyfs to use

log = file('log', 'w', 1)
print >> log, "Log for zero install test run on %s" % time.ctime()

version = version.replace('.', 'd')
fs = join(test_dir, '0install')
cache = join(test_dir, 'cache')
site = join(test_dir, 'site')
www = join(test_dir, 'www')

os.system('sync')  # Just in case we crash the kernel ;-)

if os.getuid() == 0:
    print "Unit-tests must not be run as root."
    sys.exit()

# Setup the test environment...

if not os.path.isdir(test_dir):
    os.mkdir(test_dir)

if ismount(fs):
    os.system("sudo umount '%s'" % fs)
    assert not ismount(fs)

os.environ['DEBUG_URI_0INSTALL_DIR'] = fs
Example #40
0
def doBackup(c):
    LOG.info("Runing Backup for config %s", c)
    date = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')

    if (c['source'][-1] != '/'):
        c['source'] = c['source'] + "/"

    if (c['target'][-1] != '/'):
        c['target'] = c['target'] + "/"

    target_temp = path.join(c['target'], date + "_incomplete")
    target = path.join(c['target'], date)
    logfile = path.join(c['target'], date + '.log')
    symlink = path.join(c['target'], 'current')

    #Check if mounted
    if (not path.ismount(c['mountpoint'])):
        LOG.error("Target %s is not mounted", c['mountpoint'])
        sys.exit(1)

    #Check target exists and writeable
    if (not path.exists(c['target'])):
        LOG.error("Target %s does not exist", c['target'])
        sys.exit(2)

    if (not path.isdir(c['target'])):
        LOG.error("Target %s is not a directory", c['target'])
        sys.exit(2)

    if (not os.access(c['target'], os.W_OK)):
        LOG.error("Target %s is not writeable", c['target'])

    #Try to find the most recent backup
    dirs = sorted(os.listdir(c['target']), reverse=True)
    olddir = None
    for colddir in dirs:
        if ('incomplete' in colddir):
            continue
        if ('log' in colddir):
            continue
        if ("current" in colddir):
            continue

        olddir = colddir
        break

    if (olddir is None):
        LOG.info("Found no olddir, must be firstbackup")
    else:
        olddir = os.path.join(c['target'], olddir)
        LOG.info("Found olddir %s", olddir)

    #Try to identify drive
    idfile = path.join(c['mountpoint'], '.drive_id')
    if (path.isfile(idfile) and os.access(idfile, os.R_OK)):
        fidfile = open(idfile, 'r')
        driveid = fidfile.readline().strip()
        fidfile.close()
    else:
        driveid = None

    #Build params
    p = [
        "/usr/bin/rsync",
        '-a',  #Archive
        '-v',  #Verbose
        '--stats',  #Stats
        #'-n',  #Dry
        '-x',  #One File System
        '--delete',
        '--delete-excluded',
    ]

    if ('exclude-from' in c):
        p.append('--exclude-from=' + c['exclude-from'])

    if (olddir is not None):
        p.append('--link-dest=' + olddir)

    p.extend([c['source'], target_temp])

    #Opening log-file
    flog = open(logfile, 'w')
    flog.write("$%s\n" % (p))

    #Run Rsync
    LOG.info("Runnning rsync: '%s'", p)

    rsync = subprocess.Popen(p,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.STDOUT)
    while True:
        rsync_line = rsync.stdout.readline()
        exitcode = rsync.poll()
        if (not rsync_line) and (exitcode is not None):
            break
        rsync_line = rsync_line[:-1]
        LOG.debug("%s", rsync_line)
        flog.write(rsync_line + "\n")

    flog.close()
    if (exitcode != 0):
        LOG.error("Rsync failed exitcode was %d", exitcode)
        sys.exit(10)

    LOG.info("Rsync finished")

    #Rename directory
    LOG.info("Renaming %s to %s", target_temp, target)
    os.rename(target_temp, target)

    #Create Symlink
    LOG.info("Creating symlink %s", symlink)
    if (path.islink(symlink)):
        LOG.info("Symlink already exists, deleting")
        os.remove(symlink)
    os.symlink(date, symlink)

    if (driveid is not None):
        #Save stats
        statfile = os.path.join(c['statdir'], driveid + "_" + c['name'])
        LOG.info("Generating stat-file %s", statfile)
        fstats = open(statfile, "w")
        statcmd = "/bin/ls -ldh " + c['target'] + "*/"
        LOG.info("Stat-command is '%s'", statcmd)
        p = subprocess.call(statcmd, stdout=fstats, shell=True)
        LOG.info("Generation returned %d", p)
        if (p != 0):
            LOG.error("Could not generate stat-file %s", statfile)
        fstats.close()