Changeset 5e70cc2
- Timestamp:
- Jan 21, 2012, 7:57:40 PM (12 years ago)
- Branches:
- no-cups
- Children:
- 7e29e6a
- Parents:
- 33528b4
- git-author:
- Jessica B. Hamrick <jhamrick@…> (01/21/12 19:57:40)
- git-committer:
- Jessica B. Hamrick <jhamrick@…> (01/21/12 19:57:40)
- Location:
- server/lib/gutenbach/server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
server/lib/gutenbach/server/errors.py
r951ab1b r5e70cc2 13 13 14 14 class InvalidPrinterStateException(Exception): 15 errstr = { 16 3: "idle", 17 4: "processing", 18 5: "stopped" 19 } 20 15 21 def __init__(self, state): 16 self.state = hex(state)22 self.state = int(state) 17 23 def __str__(self): 18 return "Invalid printer state: %s" % self.state 24 return "Invalid printer state: %s (%s)" % \ 25 (self.errstr[self.state], hex(self.state)) 19 26 20 27 class InvalidJobStateException(Exception): -
server/lib/gutenbach/server/printer.py
r33528b4 r5e70cc2 136 136 @sync 137 137 def state(self): 138 if self. current_job is not None:139 returnStates.PROCESSING140 elif len(self.pending_jobs) == 0:141 returnStates.IDLE138 if self.is_running and self.current_job is not None: 139 state = States.PROCESSING 140 elif self.is_running and len(self.pending_jobs) == 0: 141 state = States.IDLE 142 142 else: 143 return States.STOPPED 143 state = States.STOPPED 144 return state 144 145 145 146 @property … … 161 162 162 163 @sync 164 def assert_running(self): 165 if not self.is_running: 166 raise RuntimeError, "%s not started" % str(self) 167 168 @sync 163 169 def start_job(self): 170 self.assert_running() 164 171 if not self.paused and self.current_job is None: 165 172 try: … … 175 182 @sync 176 183 def complete_job(self): 184 self.assert_running() 177 185 if not self.paused and self.current_job is not None: 178 186 try: … … 185 193 @sync 186 194 def get_job(self, job_id): 195 self.assert_running() 187 196 if job_id not in self.jobs: 188 197 raise InvalidJobException(job_id) … … 195 204 @property 196 205 def printer_uri_supported(self): 206 self.assert_running() 197 207 return ipp.PrinterUriSupported(self.uri) 198 208 @printer_uri_supported.setter 199 209 def printer_uri_supported(self, val): 210 self.assert_running() 200 211 raise ipp.errors.AttributesNotSettable("printer-uri-supported") 201 212 202 213 @property 203 214 def uri_authentication_supported(self): 215 self.assert_running() 204 216 return ipp.UriAuthenticationSupported("none") 205 217 @uri_authentication_supported.setter 206 218 def uri_authentication_supported(self, val): 219 self.assert_running() 207 220 raise ipp.errors.AttributesNotSettable("uri-authentication-supported") 208 221 209 222 @property 210 223 def uri_security_supported(self): 224 self.assert_running() 211 225 return ipp.UriSecuritySupported("none") 212 226 @uri_security_supported.setter 213 227 def uri_security_supported(self, val): 228 self.assert_running() 214 229 raise ipp.errors.AttributesNotSettable("uri-security-supported") 215 230 216 231 @property 217 232 def printer_name(self): 233 self.assert_running() 218 234 return ipp.PrinterName(self.name) 219 235 @printer_name.setter 220 236 def printer_name(self, val): 237 self.assert_running() 221 238 raise ipp.errors.AttributesNotSettable("printer-name") 222 239 223 240 @property 224 241 def printer_state(self): 242 self.assert_running() 225 243 return ipp.PrinterState(self.state) 226 244 @printer_state.setter 227 245 def printer_state(self, val): 246 self.assert_running() 228 247 raise ipp.errors.AttributesNotSettable("printer-state") 229 248 230 249 @property 231 250 def printer_state_reasons(self): 251 self.assert_running() 232 252 return ipp.PrinterStateReasons("none") 233 253 @printer_state_reasons.setter 234 254 def printer_state_reasons(self, val): 255 self.assert_running() 235 256 raise ipp.errors.AttributesNotSettable("printer-state-reasons") 236 257 237 258 @property 238 259 def ipp_versions_supported(self): 260 self.assert_running() 239 261 return ipp.IppVersionsSupported(*self.config['ipp-versions']) 240 262 @ipp_versions_supported.setter 241 263 def ipp_versions_supported(self, val): 264 self.assert_running() 242 265 raise ipp.errors.AttributesNotSettable("ipp-versions-supported") 243 266 … … 245 268 @property 246 269 def operations_supported(self): 270 self.assert_running() 247 271 return ipp.OperationsSupported(ipp.OperationCodes.GET_JOBS) 248 272 @operations_supported.setter 249 273 def operations_supported(self, val): 274 self.assert_running() 250 275 raise ipp.errors.AttributesNotSettable("operations-supported") 251 276 252 277 @property 253 278 def charset_configured(self): 279 self.assert_running() 254 280 return ipp.CharsetConfigured("utf-8") # XXX 255 281 @charset_configured.setter 256 282 def charset_configured(self, val): 283 self.assert_running() 257 284 raise ipp.errors.AttributesNotSettable("charset-configured") 258 285 259 286 @property 260 287 def charset_supported(self): 288 self.assert_running() 261 289 return ipp.CharsetSupported("utf-8") # XXX 262 290 @charset_supported.setter 263 291 def charset_supported(self, val): 292 self.assert_running() 264 293 raise ipp.errors.AttributesNotSettable("charset-supported") 265 294 266 295 @property 267 296 def natural_language_configured(self): 297 self.assert_running() 268 298 return ipp.NaturalLanguageConfigured("en-us") 269 299 @natural_language_configured.setter 270 300 def natural_language_configured(self, val): 301 self.assert_running() 271 302 raise ipp.errors.AttributesNotSettable("natural-language-configured") 272 303 273 304 @property 274 305 def generated_natural_language_supported(self): 306 self.assert_running() 275 307 return ipp.GeneratedNaturalLanguageSupported("en-us") 276 308 @generated_natural_language_supported.setter 277 309 def generated_natural_language_supported(self, val): 310 self.assert_running() 278 311 raise ipp.errors.AttributesNotSettable("generated-natural-language-supported") 279 312 280 313 @property 281 314 def document_format_default(self): 315 self.assert_running() 282 316 return ipp.DocumentFormatDefault("application/octet-stream") 283 317 @document_format_default.setter 284 318 def document_format_default(self, val): 319 self.assert_running() 285 320 raise ipp.errors.AttributesNotSettable("document-format-default") 286 321 287 322 @property 288 323 def document_format_supported(self): 324 self.assert_running() 289 325 return ipp.DocumentFormatSupported("application/octet-stream", "audio/mp3") 290 326 @document_format_supported.setter 291 327 def document_format_supported(self, val): 328 self.assert_running() 292 329 raise ipp.errors.AttributesNotSettable("document-format-supported") 293 330 294 331 @property 295 332 def printer_is_accepting_jobs(self): 333 self.assert_running() 296 334 return ipp.PrinterIsAcceptingJobs(True) 297 335 @printer_is_accepting_jobs.setter 298 336 def printer_is_accepting_jobs(self, val): 337 self.assert_running() 299 338 raise ipp.errors.AttributesNotSettable("printer-is-accepting-jobs") 300 339 301 340 @property 302 341 def queued_job_count(self): 342 self.assert_running() 303 343 return ipp.QueuedJobCount(len(self.active_jobs)) 304 344 @queued_job_count.setter 305 345 def queued_job_count(self, val): 346 self.assert_running() 306 347 raise ipp.errors.AttributesNotSettable("queued-job-count") 307 348 308 349 @property 309 350 def pdl_override_supported(self): 351 self.assert_running() 310 352 return ipp.PdlOverrideSupported("not-attempted") 311 353 @pdl_override_supported.setter 312 354 def pdl_override_supported(self, val): 355 self.assert_running() 313 356 raise ipp.errors.AttributesNotSettable("pdl-override-supported") 314 357 315 358 @property 316 359 def printer_up_time(self): 360 self.assert_running() 317 361 return ipp.PrinterUpTime(int(time.time()) - self.time_created) 318 362 @printer_up_time.setter 319 363 def printer_up_time(self, val): 364 self.assert_running() 320 365 raise ipp.errors.AttributesNotSettable("printer-up-time") 321 366 322 367 @property 323 368 def compression_supported(self): 369 self.assert_running() 324 370 return ipp.CompressionSupported("none") 325 371 @compression_supported.setter 326 372 def compression_supported(self, val): 373 self.assert_running() 327 374 raise ipp.errors.AttributesNotSettable("compression-supported") 328 375 329 376 @property 330 377 def multiple_operation_time_out(self): 378 self.assert_running() 331 379 return ipp.MultipleOperationTimeOut(240) 332 380 @multiple_operation_time_out.setter 333 381 def multiple_operation_time_out(self, val): 382 self.assert_running() 334 383 raise ipp.errors.AttributesNotSettable("multiple-operation-time-out") 335 384 336 385 @property 337 386 def multiple_document_jobs_supported(self): 387 self.assert_running() 338 388 return ipp.MultipleDocumentJobsSupported(False) 339 389 @multiple_document_jobs_supported.setter 340 390 def multiple_document_jobs_supported(self, val): 391 self.assert_running() 341 392 raise ipp.errors.AttributesNotSettable("multiple-document-jobs-supported") 342 393 … … 346 397 347 398 def job_id(self, job_id): 399 self.assert_running() 348 400 job = self.get_job(job_id) 349 401 return ipp.JobId(job.id) 350 402 351 403 def job_name(self, job_id): 404 self.assert_running() 352 405 job = self.get_job(job_id) 353 406 return ipp.JobName(job.name) 354 407 355 408 def job_originating_user_name(self, job_id): 409 self.assert_running() 356 410 job = self.get_job(job_id) 357 411 return ipp.JobOriginatingUserName(job.creator) 358 412 359 413 def job_k_octets(self, job_id): 414 self.assert_running() 360 415 job = self.get_job(job_id) 361 416 return ipp.JobKOctets(job.size) 362 417 363 418 def job_state(self, job_id): 419 self.assert_running() 364 420 job = self.get_job(job_id) 365 421 return ipp.JobState(job.state) 366 422 367 423 def job_printer_uri(self, job_id): 424 self.assert_running() 368 425 job = self.get_job(job_id) 369 426 return ipp.JobPrinterUri(self.uri) … … 373 430 ###################################################################### 374 431 432 @sync 375 433 def print_job(self, document, document_name=None, document_format=None, 376 434 document_natural_language=None, requesting_user_name=None, 377 435 compression=None, job_name=None, job_k_octets=None): 436 437 self.assert_running() 378 438 379 439 # create the job … … 396 456 return job_id 397 457 458 @sync 398 459 def verify_job(self, document_name=None, document_format=None, 399 460 document_natural_language=None, requesting_user_name=None, 400 461 compression=None, job_name=None, job_k_octets=None): 462 463 self.assert_running() 401 464 402 465 job_id = self._next_job_id … … 409 472 del job 410 473 474 @sync 411 475 def get_jobs(self, requesting_user_name=None, which_jobs=None, 412 476 requested_attributes=None): 413 477 478 self.assert_running() 479 414 480 # Filter by the which-jobs attribute 415 481 if which_jobs is None: … … 436 502 return job_attrs 437 503 504 @sync 438 505 def print_uri(self): 439 pass 440 506 self.assert_running() 507 508 @sync 441 509 def create_job(self, requesting_user_name=None, job_name=None, 442 510 job_k_octets=None): 511 512 self.assert_running() 443 513 444 514 job_id = self._next_job_id … … 462 532 """ 463 533 534 self.assert_running() 464 535 if not self.paused: 465 536 if self.current_job is not None and self.current_job.is_playing: … … 475 546 """ 476 547 548 self.assert_running() 477 549 if self.paused: 478 550 if self.current_job is not None: … … 483 555 @sync 484 556 def get_printer_attributes(self, requested_attributes=None): 557 self.assert_running() 485 558 if requested_attributes is None: 486 559 requested = self.printer_attributes … … 495 568 @sync 496 569 def set_printer_attributes(self, job_id, attributes): 570 self.assert_running() 497 571 for attr in attributes: 498 572 try: … … 503 577 @sync 504 578 def cancel_job(self, job_id, requesting_user_name=None): 579 self.assert_running() 505 580 job = self.get_job(job_id) 506 581 try: … … 516 591 last_document=None): 517 592 593 self.assert_running() 518 594 job = self.get_job(job_id) 519 595 job.spool(document) … … 524 600 requesting_user_name=None, compression=None, 525 601 last_document=None): 602 603 self.assert_running() 526 604 job = self.get_job(job_id) 527 605 # XXX: need to validate URI … … 531 609 @sync 532 610 def get_job_attributes(self, job_id, requested_attributes=None): 611 612 self.assert_running() 533 613 if requested_attributes is None: 534 614 requested = self.job_attributes … … 543 623 @sync 544 624 def set_job_attributes(self, job_id, attributes): 625 626 self.assert_running() 545 627 job = self.get_job(job_id) 546 628 for attr in attributes: … … 554 636 @sync 555 637 def restart_job(self, job_id, requesting_user_name=None): 638 639 self.assert_running() 556 640 job = self.get_job(job_id) 557 641 try: … … 570 654 # completes, this one will go next 571 655 656 self.assert_running() 572 657 job = self.get_job(job_id) 573 658 job.priority = 1 # XXX we need to actually do something
Note: See TracChangeset
for help on using the changeset viewer.