Beispiel #1
0
	def run(self, params, args):
		(clean, dir, updatedb, dryrun, username, password) = self.fillParams([
			('clean', 'n'),
			('dir', '/export/stack/pallets'),
			('updatedb', 'y'),
			('dryrun', 'n'),
			('username', None),
			('password', None),
			])

		#Validate username and password
		#need to provide either both or none
		if username and not password:
			raise UsageError(self, 'must supply a password with the username')
		if password and not username:
			raise UsageError(self, 'must supply a username with the password')

		clean = self.str2bool(clean)
		updatedb = self.str2bool(updatedb)
		self.dryrun = self.str2bool(dryrun)
		if self.dryrun:
			updatedb = False
			self.out = sys.stderr
		else:
			self.out = sys.stdout

		self.mountPoint = '/mnt/cdrom'
		if not os.path.exists(self.mountPoint):
			os.makedirs(self.mountPoint)

		# Get a list of all the iso files mentioned in
		# the command line. Make sure we get the complete 
		# path for each file.
			
		isolist = []
		network_pallets = []
		disk_pallets    = []
		network_isolist = []
		for arg in args:
			if arg.startswith(('http', 'ftp')) and arg.endswith('.iso'):
				network_isolist.append(arg)
				continue
			elif arg.startswith(('http', 'ftp')):
				network_pallets.append(arg)
				continue
			arg = os.path.join(os.getcwd(), arg)
			if os.path.exists(arg) and arg.endswith('.iso'):
				isolist.append(arg)
			elif os.path.isdir(arg):
				disk_pallets.append(arg)
			else:
				msg = "Cannot find %s or %s is not an ISO image"
				raise CommandError(self, msg % (arg, arg))

		if self.dryrun:
			self.beginOutput()
		if not isolist and not network_pallets and not disk_pallets and not network_isolist:
			#
			# no files specified look for a cdrom
			#
			rc = os.system('mount | grep %s' % self.mountPoint)
			if rc == 0:
				self.copy(clean, dir, updatedb, self.mountPoint)
			else:
				raise CommandError(self, 'no pallets provided and /mnt/cdrom is unmounted')

		for iso in network_isolist:
			#determine the name of the iso file and get the destined path
			filename = os.path.basename(urlparse(iso).path)
			local_path = '/'.join([os.getcwd(),filename])

			try:
				# passing True will display a % progress indicator in stdout
				local_path = fetch(iso, username, password, True)
			except FetchError as e:
				raise CommandError(self, e)

			cwd = os.getcwd()
			os.system('mount -o loop %s %s > /dev/null 2>&1' % (local_path, self.mountPoint))
			self.copy(clean, dir, updatedb, iso)
			os.chdir(cwd)
			os.system('umount %s > /dev/null 2>&1' % self.mountPoint)
			print('cleaning up temporary files ...')
			p = subprocess.run(['rm', filename])

		if isolist:
			#
			# before we mount the ISO, make sure there are no active
			# mounts on the mountpoint
			#
			file = open('/proc/mounts')

			for line in file.readlines():
				l = line.split()
				if l[1].strip() == self.mountPoint:
					cmd = 'umount %s' % self.mountPoint
					cmd += ' > /dev/null 2>&1'
					subprocess.run([ cmd ], shell=True)

			for iso in isolist:	# have a set of iso files
				cwd = os.getcwd()
				os.system('mount -o loop %s %s > /dev/null 2>&1' % (iso, self.mountPoint))
				self.copy(clean, dir, updatedb, iso)
				os.chdir(cwd)
				os.system('umount %s > /dev/null 2>&1' % self.mountPoint)
			
		if network_pallets:
			for pallet in network_pallets:
				self.runImplementation('network_pallet', (clean, dir, pallet, updatedb))
		
		if disk_pallets:
			for pallet in disk_pallets:
				self.runImplementation('disk_pallet', (clean, dir, pallet, updatedb))

		self.endOutput(header=['name', 'version', 'release', 'arch', 'os'], trimOwner=False)

		# Clear the old packages
		self.clean_ludicrous_packages()
Beispiel #2
0
    def run(self, params, args):
        cartfile, url, urlfile, dldir, authfile, donly, username, password = \
         self.fillParams([('file', None),
           ('url', None),
           ('urlfile', None),
           ('downloaddir', '/tmp'),
           ('authfile', None),
           ('downloadonly', False),
           ('username', None),
           ('password', None),
           ])

        #Validate username and password
        #need to provide either both or none
        if username and not password:
            raise UsageError(self, 'must supply a password with the username')
        if password and not username:
            raise UsageError(self, 'must supply a username with the password')

        carts = args
        cart_url = None
        # check if we are creating a new cart
        if url == urlfile == cartfile == authfile == None:
            if not len(carts):
                raise ArgRequired(self, 'cart')
            else:
                for cart in carts:
                    # check if the cartfile is actally a url that we should download
                    # if it is, we download it then set the cartfile to the local file
                    if cart.startswith(('http://', 'ftp://', 'https://')):
                        print(f'downloading {cart} ...')
                        try:
                            # passing True will display a % progress indicator in stdout
                            cartfile = fetch(cart, username, password, True)
                        except FetchError as e:
                            raise CommandError(self, e)
                        print('adding cart...')
                        cart_url = cart
                    else:
                        self.add_cart(cart)

        # If there's a filename, check it.
        if cartfile == None:
            pass
        elif Path(cartfile).exists() == True \
         and Path(cartfile).is_file() == True:
            # If there is a filename, make sure it's a tar gz file.
            if self.check_cart(cartfile) == True:
                # if the file has not been downloaded from the internet
                # pass along the local path
                if not cart_url:
                    cart_url = os.path.abspath(cartfile)
                self.add_cart_file(cartfile, cart_url)
                # now we cleanup the cart file if we donwloaded it
                if cart_url.startswith(('http', 'ftp')):
                    p = subprocess.run(['rm', cartfile])
            else:
                msg = '%s is not a cart.' % cartfile
                raise CommandError(self, msg)
        else:
            msg = '%s was not found.' % cartfile
            raise CommandError(self, msg)

        # do the network cart if url or urlfile or authfile exist.
#			base,urlfiles,user,passwd = self.get_auth_info(authfile)
        if url != None or urlfile != None or authfile != None:
            if authfile != None:
                base,urlfiles,user,passwd = \
                 self.get_auth_info(authfile)
            # then add_cart_file to them.
            urls = self.get_urls(url, urlfile, dldir, authfile)
            for url in urls:
                url = url.strip('\n')
                cartfile = os.path.basename(url)
                dest = '%s/%s' % (dldir, cartfile)
                self.download_url(url, dest, cartfile, user, passwd)
                if self.str2bool(donly) != True:
                    self.add_cart_file(dest)

        # Fix all the perms all the time.
        self.fix_perms()
Beispiel #3
0
	def run(self, params, args):
		cartfile, url, urlfile, dldir, authfile, donly, username, password = \
			self.fillParams([('file', None),
					('url', None),
					('urlfile', None),
					('downloaddir', '/tmp'),
					('authfile', None),
					('downloadonly', False),
					('username', None),
					('password', None),
					])

		#Validate username and password
		#need to provide either both or none
		if username and not password:
			raise UsageError(self, 'must supply a password with the username')
		if password and not username:
			raise UsageError(self, 'must supply a username with the password')

		carts = args
		cart_url = None
		# check if we are creating a new cart
		if url == urlfile == cartfile == authfile == None:
			if not len(carts):
				raise ArgRequired(self, 'cart')
			else:
				for cart in carts:
					# check if the cartfile is actally a url that we should download
					# if it is, we download it then set the cartfile to the local file
					if cart.startswith(('http://', 'ftp://', 'https://')):
						print(f'downloading {cart} ...')
						try:
							# passing True will display a % progress indicator in stdout
							cartfile = fetch(cart, username, password, True)
						except FetchError as e:
							raise CommandError(self, e)
						print('adding cart...')
						cart_url = cart
					else:
						self.add_cart(cart)

		# If there's a filename, check it.
		if cartfile == None:
			pass
		elif Path(cartfile).exists() == True \
			and Path(cartfile).is_file() == True:
		# If there is a filename, make sure it's a tar gz file.
			if self.check_cart(cartfile) == True:
				# if the file has not been downloaded from the internet
				# pass along the local path
				if not cart_url:
					cart_url = os.path.abspath(cartfile)
				self.add_cart_file(cartfile, cart_url)
				# now we cleanup the cart file if we donwloaded it
				if cart_url.startswith(('http', 'ftp')):
					p = subprocess.run(['rm', cartfile])
			else:
				msg = '%s is not a cart.' % cartfile
				raise CommandError(self,msg)
		else:
			msg = '%s was not found.' % cartfile
			raise CommandError(self,msg)

		# do the network cart if url or urlfile or authfile exist.
#			base,urlfiles,user,passwd = self.get_auth_info(authfile)
		if url != None or urlfile != None or authfile != None:
			if authfile != None:
				base,urlfiles,user,passwd = \
					self.get_auth_info(authfile)
			# then add_cart_file to them.
			urls = self.get_urls(url,urlfile,dldir,authfile)
			for url in urls:
				url = url.strip('\n')
				cartfile = os.path.basename(url)
				dest = '%s/%s' % (dldir,cartfile)
				self.download_url(url, dest, cartfile, user, passwd)
				if self.str2bool(donly) != True:
					self.add_cart_file(dest)

		# Fix all the perms all the time.
		self.fix_perms()
Beispiel #4
0
	def run(self, params, args):
		(clean, dir, updatedb, dryrun, username, password) = self.fillParams([
			('clean', 'n'),
			('dir', '/export/stack/pallets'),
			('updatedb', 'y'),
			('dryrun', 'n'),
			('username', None),
			('password', None),
			])

		#Validate username and password
		#need to provide either both or none
		if username and not password:
			raise UsageError(self, 'must supply a password with the username')
		if password and not username:
			raise UsageError(self, 'must supply a username with the password')

		clean = self.str2bool(clean)
		updatedb = self.str2bool(updatedb)
		self.dryrun = self.str2bool(dryrun)
		if self.dryrun:
			updatedb = False
			self.out = sys.stderr
		else:
			self.out = sys.stdout

		self.mountPoint = '/mnt/cdrom'
		tempMountPoint = tempfile.TemporaryDirectory()
		if not os.path.exists(self.mountPoint):
			try:
				os.makedirs(self.mountPoint)
			except OSError:
				self.mountPoint = tempMountPoint.name

		# Get a list of all the iso files mentioned in
		# the command line. Make sure we get the complete 
		# path for each file.
			
		isolist = []
		network_pallets = []
		disk_pallets    = []
		network_isolist = []
		for arg in args:
			if arg.startswith(('http', 'ftp')) and arg.endswith('.iso'):
				network_isolist.append(arg)
				continue
			elif arg.startswith(('http', 'ftp')):
				network_pallets.append(arg)
				continue
			arg = os.path.join(os.getcwd(), arg)
			if os.path.exists(arg) and arg.endswith('.iso'):
				isolist.append(arg)
			elif os.path.isdir(arg):
				disk_pallets.append(arg)
			else:
				msg = "Cannot find %s or %s is not an ISO image"
				raise CommandError(self, msg % (arg, arg))

		if self.dryrun:
			self.beginOutput()
		if not isolist and not network_pallets and not disk_pallets and not network_isolist:
			#
			# no files specified look for a cdrom
			#
			rc = os.system('mount | grep %s' % self.mountPoint)
			if rc == 0:
				self.copy(clean, dir, updatedb, self.mountPoint)
			else:
				raise CommandError(self, 'no pallets provided and /mnt/cdrom is unmounted')

		for iso in network_isolist:
			#determine the name of the iso file and get the destined path
			filename = os.path.basename(urlparse(iso).path)
			local_path = '/'.join([os.getcwd(),filename])

			try:
				# passing True will display a % progress indicator in stdout
				local_path = fetch(iso, username, password, True)
			except FetchError as e:
				raise CommandError(self, e)

			cwd = os.getcwd()
			os.system('mount -o loop %s %s > /dev/null 2>&1' % (local_path, self.mountPoint))
			self.copy(clean, dir, updatedb, iso)
			os.chdir(cwd)
			os.system('umount %s > /dev/null 2>&1' % self.mountPoint)
			print('cleaning up temporary files ...')
			p = subprocess.run(['rm', filename])

		if isolist:
			#
			# before we mount the ISO, make sure there are no active
			# mounts on the mountpoint
			#
			file = open('/proc/mounts')

			for line in file.readlines():
				l = line.split()
				if l[1].strip() == self.mountPoint:
					cmd = 'umount %s' % self.mountPoint
					cmd += ' > /dev/null 2>&1'
					subprocess.run([ cmd ], shell=True)

			for iso in isolist:	# have a set of iso files
				cwd = os.getcwd()
				os.system('mount -o loop %s %s > /dev/null 2>&1' % (iso, self.mountPoint))
				self.copy(clean, dir, updatedb, iso)
				os.chdir(cwd)
				os.system('umount %s > /dev/null 2>&1' % self.mountPoint)
			
		if network_pallets:
			for pallet in network_pallets:
				self.runImplementation('network_pallet', (clean, dir, pallet, updatedb))
		
		if disk_pallets:
			for pallet in disk_pallets:
				self.runImplementation('disk_pallet', (clean, dir, pallet, updatedb))

		self.endOutput(header=['name', 'version', 'release', 'arch', 'os'], trimOwner=False)

		# Clear the old packages
		self.clean_ludicrous_packages()
Beispiel #5
0
    def run(self, args):
        '''
		Iterate through args, and if arg is an iso on a remote filesystem,
		fetch it, save it to tempdirY, and mount it in another tempdirZ.

		Adds callbacks to delete tempdirY/arg and unmount tempdirZ

		args is a dictionary
		{
			arg_X: {
				canonical_arg: full_path_to_arg,
				exploded_path: tempdir
				},
		}
		'''

        # strategy:
        # check if remote path
        # check if iso
        # fetch iso and save to temporary location on local filesystem
        # mount iso to tempdir

        for arg in args:
            canon_arg = args[arg]['canonical_arg']
            tempdir = args[arg]['exploded_path']

            if not canon_arg.startswith(('https://', 'http://', 'ftp://')):
                continue
            if not canon_arg.endswith('.iso'):
                continue

            try:
                remote_filename = pathlib.Path(
                    urllib.parse.urlparse(canon_arg).path).name
                # passing True will display a % progress indicator in stdout
                local_path = fetch(canon_arg, self.owner.username,
                                   self.owner.password, True,
                                   f'{tempdir}/{remote_filename}')
            except FetchError as e:
                raise CommandError(self, e)

            # make a second tempdir to actually mount the iso in.
            # this is what we will return to add pallet
            tmp_mnt_dir = tempfile.mkdtemp()

            fi = pathlib.Path(local_path)
            if not fi.is_file():
                raise CommandError(
                    self,
                    f'Error fetching {fi}: not recognized as an iso file')

            try:
                self.owner.mount(local_path, tmp_mnt_dir)
            except CommandError:
                # mount can fail and that's fine, but we want to clean up if it does
                raise
            finally:
                # cleanup the downloaded iso junk
                # NOTE: cleanups happen in reverse order of insertion
                # due to the ordering explicitly call umount, so it happens before the iso unlink
                self.owner.deferred.callback(pathlib.Path(tmp_mnt_dir).rmdir)
                self.owner.deferred.callback(
                    pathlib.Path(f'{local_path}').unlink)
                self.owner.deferred.callback(self.owner.umount, local_path,
                                             tmp_mnt_dir)

            args[arg]['exploded_path'] = tmp_mnt_dir