This repository has been archived by the owner on Dec 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy path_ticket.py
191 lines (147 loc) · 5.19 KB
/
_ticket.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
"""Copyright 2016 Google Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Model that represents the CloudJobTicket that's used to submit print jobs to the
Google Cloud Print Service /submit interface.
CloudJobTicket will provide methods to set the various fields of a job ticket:
"""
class CloudJobTicket(object):
"""Represents the print job specifications sent to the printer on
job submission."""
def __init__(self, version = '1.0'):
"""Get a reference to a logger object.
Args:
version: string, gcp version
"""
self.val = {}
self.val['print'] = {}
self.val['version'] = version
def AddColorOption(self, color_type):
"""
Specify the print job's color scheme
Args:
color_type: string, STANDARD_COLOR or STANDARD_MONOCHROME
"""
self.val['print']['color'] = {'type': color_type}
def AddCopiesOption(self, num_copies):
"""
Specify the number of copies to print
Args:
num_copies: integer, number of copies to print
"""
self.val['print']['copies'] = {'copies': num_copies}
def AddDuplexOption(self, duplex_type):
"""
Specify the duplexing type of the print job
Args:
duplex_type: string, NO_DUPLEX, LONG_EDGE, or SHORT_EDGE
"""
self.val['print']['duplex'] = {'type': duplex_type}
def AddPageOrientationOption(self, orientation_type):
"""
Specify the page orientation of the print job
Args:
orientation_type: string, PORTRAIT, LANDSCAPE, or AUTO
"""
self.val['print']['page_orientation'] = {'type': orientation_type}
def AddDpiOption(self, horizontal_dpi, vertical_dpi):
"""
Specify the DPI for the print job
Args:
horizontal_dpi: integer, horizontal dpi
vertical_dpi : integer, vertical dpi
"""
self.val['print']['dpi'] = {'horizontal_dpi': horizontal_dpi,
'vertical_dpi': vertical_dpi}
def AddMarginOption(self, top, right, bottom, left):
"""
Specify the margins for the print job
Args:
top, int, top margin in microns
right, int, right margin in microns
bottom, int, bottom margin in microns
left, int, left margin in microns
"""
self.val['print']['margins'] = {'top_microns': top,
'right_microns': right,
'bottom_microns': bottom,
'left_microns': left}
def AddSizeOption(self, height_microns, width_microns):
"""
Specify the size of the print job
Args:
height_microns: integer, height in microns
width_microns : integer, width in microns
"""
self.val['print']['media_size'] = {'height_microns': height_microns,
'width_microns': width_microns}
def AddReverseOption(self):
"""
Enable the reverse print option
"""
self.val['print']['reverse_order'] = {'reverse_order': True}
def AddFitToPageOption(self, type):
"""
Specify the size of the print job
Args:
type: string, NO_FITTING, FIT_TO_PAGE, GROW_TO_PAGE, SHRINK_TO_PAGE,
or FILL_PAGE
"""
self.val['print']['fit_to_page'] = {'type': type}
def AddPageRangeOption(self, start, end = None):
"""
Specify a range of pages to print
Args:
start: integer, Beginning of the print interval (inclusive)
end : integer, The last page of the range to print (inclusive).
If not specified, all pages after 'start' are printed
"""
# If this is the first page range for this CJT, start with an empty array;
# otherwise, get the existing array
page_ranges = ([] if 'page_range' not in self.val['print'] else
self.val['print']['page_range']['interval'])
new_range = {'start': start}
if end is not None:
new_range['end']= end
page_ranges.append(new_range)
self.val['print']['page_range']= {'interval': page_ranges}
class GCPConstants(object):
"""A class that holds constants that are used in a GCP"""
#
# CJT (Cloud Job Ticket) constants
#
# Color scheme
MONOCHROME = 'STANDARD_MONOCHROME'
COLOR = 'STANDARD_COLOR'
# Page orientation
LANDSCAPE = 'LANDSCAPE'
PORTRAIT = 'PORTRAIT'
# Duplexing
LONG_EDGE = 'LONG_EDGE'
SHORT_EDGE = 'SHORT_EDGE'
# Page fit
NO_FIT = 'NO_FITTING'
FIT = 'FIT_TO_PAGE'
GROW = 'GROW_TO_PAGE'
SHRINK = 'SHRINK_TO_PAGE'
FILL = 'FILL_PAGE'
# A4 size in microns
A4_HEIGHT = 297000
A4_WIDTH = 210000
#
# CJS (Cloud Job State) constants
#
DRAFT = 'DRAFT'
HELD = 'HELD'
QUEUED = 'QUEUED'
IN_PROGRESS = 'IN_PROGRESS'
STOPPED = 'STOPPED'
DONE = 'DONE'
ABORTED = 'ABORTED'