Exemple #1
0
    def cups_printer_show(self, object):
        if object.incomplete:
            self.finished(object.id(), [])
            return

        cmd = "/usr/bin/lpstat -o %s" % object.options["printer"]
        ud.debug(ud.ADMIN, ud.INFO, "CUPS.show: command: %s" % cmd)
        processresult = umct.run_process(cmd, timeout=10000, shell=True, output=True)
        lpstat_o_stdout = processresult["stdout"].readlines()
        ud.debug(ud.ADMIN, ud.INFO, "CUPS.show: lpstat_o_stdout: %s" % lpstat_o_stdout)
        lpstat_o_stdout = tools.parse_lpstat_o(lpstat_o_stdout)

        cmd = "/usr/bin/lpstat -l -p %s" % object.options["printer"]
        ud.debug(ud.ADMIN, ud.INFO, "CUPS.show: command: %s" % cmd)
        processresult = umct.run_process(cmd, timeout=10000, shell=True, output=True)
        buffer = processresult["stdout"].readlines()
        ud.debug(ud.ADMIN, ud.INFO, "CUPS.show: lpstat: %s" % buffer)
        self.finished(object.id(), (lpstat_o_stdout, tools.parse_lpstat_l(buffer)))
        return
Exemple #2
0
	def _web_cups_printer_quota_list( self, object, res ):
		printerdata, quotadata = res.dialog

		info = umcd.List()
		printer = tools.parse_lpstat_l( printerdata )
		attributes = printer[ object.options[ 'printer' ] ]
		headline = _( 'Printer: %s' ) % object.options[ 'printer' ]
		info.add_row( [ _( 'Server' ) + ':', umc.registry[ 'hostname' ] ] )
		info.add_row( [ _( 'Status' ) + ':', attributes[ 'state' ] ] )
		info.add_row( [ _( 'Location' ) + ':', attributes[ 'location' ] ] )
		info.add_row( [ _( 'Description' ) + ':', attributes[ 'description' ] ] )

		# find correct printer
		prnQuota = None
		for x in quotadata:
			if x.printername == object.options[ 'printer' ]:
				prnQuota = x

		lstQ = umcd.List()
		boxes = []
		if prnQuota:
			lstQ.set_header( [ _( 'User' ), _( 'Pages used' ), _( 'Soft limit' ), _( 'Hard limit' ),
							   _( 'Lifetime page counter' ), '' ] )
			for uquota in prnQuota.userlist:
				static_options = { 'user' : uquota.user, 'printer' : object.options[ 'printer' ] }
				chk_button = umcd.Checkbox( static_options = static_options )
				boxes.append( chk_button.id() )

				softlimit = uquota.softlimit
				hardlimit = uquota.hardlimit
				if not softlimit.isdigit():
					if softlimit == 'None':
						softlimit = ''
				if not hardlimit.isdigit():
					if hardlimit == 'None':
						hardlimit = ''

				req = umcp.Command( args = [ 'cups/quota/user/show' ],
									opts =  { 'user' : uquota.user,
												'printer' : object.options[ 'printer' ],
												'pagesoftlimit' : softlimit,
												'pagehardlimit' : hardlimit } )
				req.set_flag( 'web:startup', True )
				req.set_flag( 'web:startup_reload', True )
				req.set_flag( 'web:startup_dialog', True )
				req.set_flag( 'web:startup_format', _( 'Edit print quota for %(user)s' ) )
				lstQ.add_row(  [ umcd.Button( uquota.user, 'cups/user', umcd.Action( req ) ),
								 umcd.Number(uquota.pagecounter), umcd.Number(softlimit),
								 umcd.Number(hardlimit), umcd.Number(uquota.lifetimepagecounter),
								 chk_button ] )

			req = umcp.Command( args = [ ], opts= { 'printer' : object.options[ 'printer' ],
													'user': [] } )
			req_show = umcp.Command( args = [ 'cups/printer/quota/list' ],
									 opts= { 'printer' : object.options[ 'printer' ] } )
			actions = ( umcd.Action( req, boxes, True ), umcd.Action( req_show ) )
			choices = [ ( 'cups/quota/user/reset', _( 'Reset user quota' ) ) ]
			select = umcd.SelectionButton( _( 'Select the operation' ), choices, actions )
			lstQ.add_row( [ umcd.Fill( 5 ), select ] )
		else:
			lstQ.add_row( [ _( 'No quota settings available' ) ] )

		req = umcp.Command( args = [ 'cups/quota/user/show' ],
							opts = { 'printer' : object.options[ 'printer' ] } )
		req.set_flag( 'web:startup', True )
		req.set_flag( 'web:startup_reload', True )
		req.set_flag( 'web:startup_dialog', True )
		req.set_flag( 'web:startup_format', _( 'User quota on %(printer)s' ) )
		lstQ.add_row( [ umcd.Button( _( 'Add quota entry' ), 'actions/add', umcd.Action( req ),
									attributes = { 'colspan' : '3' } ), umcd.Fill( 3 ) ] )
		res.dialog = [ umcd.Frame( [ info, ], _( 'Information' ) ),
						umcd.Frame( [ lstQ ], _( 'Print quota' ) ) ]

		self.revamped( object.id(), res )