Changeset 33ea505 for server/lib/gutenbach/server/printer.py
- Timestamp:
- Jan 11, 2012, 6:58:43 PM (12 years ago)
- Branches:
- no-cups
- Children:
- 09790fe
- Parents:
- 4126d3d
- git-author:
- Jessica B. Hamrick <jhamrick@…> (01/11/12 18:58:43)
- git-committer:
- Jessica B. Hamrick <jhamrick@…> (01/11/12 18:58:43)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
server/lib/gutenbach/server/printer.py
r34a4e5d r33ea505 1 from . import InvalidJobException, InvalidPrinterStateException, InvalidJobStateException2 from . importJob1 from .errors import InvalidJobException, InvalidPrinterStateException, InvalidJobStateException 2 from .job import GutenbachJob 3 3 from gutenbach.ipp import PrinterStates as States 4 4 import gutenbach.ipp as ipp … … 17 17 18 18 # for IPP 19 attributes = [19 printer_attributes = [ 20 20 "printer-uri-supported", 21 21 "uri-authentication-supported", … … 41 41 ] 42 42 43 job_attributes = [ 44 "job-id", 45 "job-name", 46 "job-originating-user-name", 47 "job-k-octets", 48 "job-state", 49 "job-printer-uri" 50 ] 51 43 52 operations = [ 44 53 "print-job", 45 "complete-job", 46 "start-job", 47 "get-job", 54 "validate-job", 48 55 "get-jobs", 56 "print-uri", 57 "create-job", 58 "pause-printer", 59 "resume-printer", 60 "get-printer-attributes", 61 "set-printer-attributes", 62 "cancel-job", 63 "send-document", 64 "send-uri", 65 "get-job-attributes", 66 "set-job-attributes", 67 "restart-job", 68 "promote-job" 49 69 ] 50 70 … … 73 93 def __str__(self): 74 94 return "<Printer '%s'>" % self.name 75 76 ######################################################################77 ### Properties ###78 ######################################################################79 80 @property81 def uris(self):82 uris = ["ipp://localhost:8000/printers/" + self.name,83 "ipp://localhost/printers/" + self.name]84 return uris85 86 @property87 def uri(self):88 return self.uris[0]89 90 @property91 def state(self):92 with self.lock:93 if self.current_job is not None:94 val = States.PROCESSING95 elif len(self.pending_jobs) == 0:96 val = States.IDLE97 else:98 val = States.STOPPED99 return val100 101 @property102 def active_jobs(self):103 with self.lock:104 jobs = self.pending_jobs[:]105 if self.current_job is not None:106 jobs.insert(0, self.current_job.id)107 return jobs108 109 ######################################################################110 ### Methods ###111 ######################################################################112 95 113 96 def run(self): … … 124 107 sys.exit(1) 125 108 time.sleep(0.1) 109 110 ###################################################################### 111 ### Properties ### 112 ###################################################################### 113 114 @property 115 def uris(self): 116 uris = ["ipp://localhost:8000/printers/" + self.name, 117 "ipp://localhost/printers/" + self.name] 118 return uris 119 120 @property 121 def uri(self): 122 return self.uris[0] 123 124 @property 125 def state(self): 126 with self.lock: 127 if self.current_job is not None: 128 val = States.PROCESSING 129 elif len(self.pending_jobs) == 0: 130 val = States.IDLE 131 else: 132 val = States.STOPPED 133 return val 134 135 @property 136 def active_jobs(self): 137 with self.lock: 138 jobs = self.pending_jobs[:] 139 if self.current_job is not None: 140 jobs.insert(0, self.current_job.id) 141 return jobs 142 143 ###################################################################### 144 ### Methods ### 145 ###################################################################### 126 146 127 147 def start_job(self): … … 150 170 self.current_job = None 151 171 152 def stop(self):153 pass154 155 172 def get_job(self, job_id): 156 173 with self.lock: … … 249 266 return ipp.MultipleDocumentJobsSupported(False) 250 267 268 ###################################################################### 269 ### Job IPP Attributes ### 270 ###################################################################### 271 272 def job_id(self, job_id): 273 job = self.get_job(job_id) 274 return ipp.JobId(job.id) 275 276 def job_name(self, job_id): 277 job = self.get_job(job_id) 278 return ipp.JobName(job.name) 279 280 def job_originating_user_name(self, job_id): 281 job = self.get_job(job_id) 282 return ipp.JobOriginatingUserName(job.creator) 283 284 def job_k_octets(self, job_id): 285 job = self.get_job(job_id) 286 return ipp.JobKOctets(job.size) 287 288 def job_state(self, job_id): 289 job = self.get_job(job_id) 290 return ipp.JobState(job.state) 291 292 def job_printer_uri(self, job_id): 293 job = self.get_job(job_id) 294 return ipp.JobPrinterUri(self.uri) 251 295 252 296 ###################################################################### … … 260 304 pass 261 305 262 def get_jobs(self, requesting_user_name="", which_jobs=None): 306 def get_jobs(self, requesting_user_name=None, which_jobs=None, 307 requested_attributes=None): 308 263 309 # Filter by the which-jobs attribute 264 310 if which_jobs is None: … … 278 324 else: 279 325 user_jobs = [job for job in jobs if job.creator == requesting_user_name] 280 281 return user_jobs 326 327 # Get the attributes of each job 328 job_attrs = [self.get_job_attributes( 329 job.id, requested_attributes=requested_attributes) for job in user_jobs] 330 331 return job_attrs 282 332 283 333 def print_uri(self): … … 288 338 self._next_job_id += 1 289 339 290 job = Job(job_id, 291 self, 292 creator=requesting_user_name, 293 name=job_name, 294 size=job_k_octets) 340 job = GutenbachJob( 341 job_id, 342 creator=requesting_user_name, 343 name=job_name) 295 344 296 345 self.jobs[job_id] = job 297 346 self.pending_jobs.append(job_id) 298 347 299 return job 348 return job_id 300 349 301 350 def pause_printer(self): … … 307 356 def get_printer_attributes(self, requested_attributes=None): 308 357 if requested_attributes is None: 309 requested = self. attributes358 requested = self.printer_attributes 310 359 else: 311 requested = [a for a in self.attributes if a in requested_attributes] 360 requested = [a for a in self.printer_attributes \ 361 if a in requested_attributes] 312 362 313 363 _attributes = [attr.replace("-", "_") for attr in requested] … … 317 367 def set_printer_attributes(self): 318 368 pass 369 370 def cancel_job(self, job_id, requesting_user_name=None): 371 job = self.get_job(job_id) 372 try: 373 job.cancel() 374 except InvalidJobStateException: 375 # XXX 376 raise 377 378 def send_document(self, job_id, document, document_name=None, 379 document_format=None, document_natural_language=None, 380 requesting_user_name=None, compression=None, 381 last_document=None): 382 383 job = self.get_job(job_id) 384 job.spool(document, username=requesting_user_name) 385 386 def send_uri(self): 387 pass 388 389 def get_job_attributes(self, job_id, requested_attributes=None): 390 if requested_attributes is None: 391 requested = self.job_attributes 392 else: 393 requested = [a for a in self.job_attributes \ 394 if a in requested_attributes] 395 396 _attributes = [attr.replace("-", "_") for attr in requested] 397 attributes = [getattr(self, attr)(job_id) for attr in _attributes] 398 return attributes 399 400 def set_job_attributes(self): 401 pass 402 403 def restart_job(self): 404 pass 405 406 def promote_job(self): 407 pass
Note: See TracChangeset
for help on using the changeset viewer.