Print shipping ticket
 ID = ticket ID
 Output: PDF or JPG
499595
def print_single(id, output = "pdf")
      timenow      = Time.current.strftime("%Y%m%d_-_%H%M")
      resource_url = "#{@base_uri}/envios/#{id}/etiqueta?access_token=#{@access_token}&formato=#{output}"
      begin
        response = RestClient.get resource_url
        send_data(response, :filename => "etiqueta_-_#{timenow}.pdf", :disposition => "attachment", :type => "application/pdf")
      rescue e
        return JSON.parse(e.response, object_class: OpenStruct)
      end
    end
154078
def print_info(ds, ds_path=None):
    ""

    if ds_path is None:
        bname = ''
    else:
        bname = basename(ds_path)

    dashes = '-' * len(bname)
    print('\n{}\n{}\n{:full}'.format(dashes, bname, ds))

    return
296608
def print_trip_table(document):
    
    headers = [
        'Alt.',
        'Name',
        'Time',
        'Track',
        'Direction',
        'Dest.',
        'Track',
        'Arrival']
    table = []
    altnr = 0
    for alternative in document:
        altnr += 1
        first_trip_in_alt = True
        if not isinstance(alternative['Leg'], list):
            alternative['Leg'] = [alternative['Leg']]
        for part in alternative['Leg']:
            orig = part['Origin']
            dest = part['Destination']
            row = [
                altnr if first_trip_in_alt else None,
                part['name'],
                orig['rtTime'] if 'rtTime' in orig else orig['time'],
                orig['track'],
                part['direction'] if 'direction' in part else None,
                dest['name'],
                dest['track'],
                dest['rtTime'] if 'rtTime' in dest else dest['time'],
                ]
            table.append(row)
            first_trip_in_alt = False
    print(tabulate.tabulate(table, headers))
272819
def print_out(self, value, indent=None, format_options=None, asap=False):
        
        if indent is None:
            indent = '>   '

        text = indent + str(value)

        if format_options is None:
            format_options = 'gray'

        if self._style_prints and format_options:

            if not isinstance(format_options, dict):
                format_options = {'color_fg': format_options}

            text = format_print_text(text, **format_options)

        command = 'iprint' if asap else 'print'
        self._set(command, text, multi=True)

        return self
181382
def printer(self):
        """"""
        print " ID " + repr(self.id)
        if self.type == 0:
            print " Tag: - "
            print " Start State - "
        elif self.type == 1:
            print " Push " + repr(self.sym)
        elif self.type == 2:
            print " Pop State " + repr(self.sym)
        elif self.type == 3:
            print " Read State " + repr(self.sym)
        elif self.type == 4:
            print " Stop State " + repr(self.sym)
        for j in self.trans:
            if len(self.trans[j]) > 1 or (len(self.trans[j]) == 1):
                for symbol in self.trans[j]:
                    print " On Symbol " + repr(symbol) + " Transition To State " + repr(j)
655891
def line_print(self):
        
        inv_types = {v: k for k, v in defines.Types.items()}

        if self._code is None:
            self._code = defines.Codes.EMPTY.number

        msg = "From {source}, To {destination}, {type}-{mid}, {code}-{token}, ["\
            .format(source=self._source, destination=self._destination, type=inv_types[self._type], mid=self._mid,
                    code=defines.Codes.LIST[self._code].name, token=self._token)
        for opt in self._options:
            msg += "{name}: {value}, ".format(name=opt.name, value=opt.value)
        msg += "]"
        if self.payload is not None:
            if isinstance(self.payload, dict):
                tmp = list(self.payload.values())[0][0:20]
            else:
                tmp = self.payload[0:20]
            msg += " {payload}...{length} bytes".format(payload=tmp, length=len(self.payload))
        else:
            msg += " No payload"
        return msg
984555
def parse(self, ticket):
        
        if len(ticket) < self._min_ticket_size():
            raise TicketParseError(ticket, 'Invalid ticket length')

        digest_len = self._hash.digest_size * 2
        digest = ticket[:digest_len]

        try:
            time_len = 8
            time = int(ticket[digest_len:digest_len + time_len], 16)
        except:
            raise TicketParseError(ticket, 'Invalid time field')

        parts = ticket[digest_len + time_len:].split('!')
        if len(parts) != 3:
            raise TicketParseError(ticket, 'Missing parts')

        user_id = ulp.unquote(parts[0])
        tokens = ()
        if parts[1]:
            tokens = tuple((ulp.unquote(t) for t in parts[1].split(',')))

        user_data = ulp.unquote(parts[2])

        return TicketInfo(digest, user_id, tokens, user_data, time)
190810
def cli(env, identifier, path, name):
    """"""
    mgr = SoftLayer.TicketManager(env.client)

    ticket_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'ticket')

    if path is None:
        raise exceptions.ArgumentError("Missing argument --path")

    if not os.path.exists(path):
        raise exceptions.ArgumentError("%s not exist" % path)

    if name is None:
        name = os.path.basename(path)

    attached_file = mgr.upload_attachment(ticket_id=ticket_id,
                                          file_path=path,
                                          file_name=name)
    env.fout("File attached: \n%s" % attached_file)
1051900
def _printable_id_code(self):
        
        code = str(self.id_code)
        while len(code) < self._code_size:
            code = '0' + code

        return code
977014
def verify_ticket(self, ticket):
        
        params = [('ticket', ticket), ('service', self.service_url)]
        url = (urllib_parse.urljoin(self.server_url, 'validate') + '?' +
               urllib_parse.urlencode(params))
        page = requests.get(
            url,
            stream=True,
            verify=self.verify_ssl_certificate
        )
        try:
            page_iterator = page.iter_lines(chunk_size=8192)
            verified = next(page_iterator).strip()
            if verified == 'yes':
                return next(page_iterator).strip(), None, None
            else:
                return None, None, None
        finally:
            page.close()
619929
def prt_tsv(prt, data_nts, **kws):
    """"""
    # User-controlled printing options
    prt_tsv_hdr(prt, data_nts, **kws)
    return prt_tsv_dat(prt, data_nts, **kws)
51408
def get_bounding_box_list_render_image(pdf_file_name, input_doc):
    """"""

    program_to_use = "pdftoppm" # default to pdftoppm
    if args.gsRender: program_to_use = "Ghostscript"

    # Threshold value set in range 0-255, where 0 is black, with 191 default.
    if not args.threshold: args.threshold = 191
    threshold = args.threshold
    if not args.numSmooths: args.numSmooths = 0
    if not args.numBlurs: args.numBlurs = 0

    temp_dir = ex.program_temp_directory # use the program default; don't delete dir!

    temp_image_file_root = os.path.join(temp_dir, ex.temp_file_prefix + "PageImage")
    if args.verbose:
        print("\nRendering the PDF to images using the " + program_to_use + " program,"
              "\nthis may take a while...")

    # Do the rendering of all the files.
    render_pdf_file_to_image_files(pdf_file_name, temp_image_file_root, program_to_use)

    # Currently assuming that sorting the output will always put them in correct order.
    outfiles = sorted(glob.glob(temp_image_file_root + "*"))

    if args.verbose:
        print("\nAnalyzing the page images with PIL to find bounding boxes,"
              "\nusing the threshold " + str(args.threshold) + "."
              "  Finding the bounding box for page:\n")

    bounding_box_list = []

    for page_num, tmp_image_file_name in enumerate(outfiles):
        curr_page = input_doc.getPage(page_num)

        # Open the image in PIL.  Retry a few times on fail in case race conditions.
        max_num_tries = 3
        time_between_tries = 1
        curr_num_tries = 0
        while True:
            try:
                # PIL for some reason fails in Python 3.4 if you open the image
                # from a file you opened yourself.  Works in Python 2 and earlier
                # Python 3.  So original code is commented out, and path passed.
                #
                # tmpImageFile = open(tmpImageFileName)
                # im = Image.open(tmpImageFile)
                im = Image.open(tmp_image_file_name)
                break
            except (IOError, UnicodeDecodeError) as e:
                curr_num_tries += 1
                if args.verbose:
                    print("Warning: Exception opening image", tmp_image_file_name,
                          "on try", curr_num_tries, "\nError is", e, file=sys.stderr)
                # tmpImageFile.close() # see above comment
                if curr_num_tries > max_num_tries: raise # re-raise exception
                time.sleep(time_between_tries)

        # Apply any blur or smooth operations specified by the user.
        for i in range(args.numBlurs):
            im = im.filter(ImageFilter.BLUR)
        for i in range(args.numSmooths):
            im = im.filter(ImageFilter.SMOOTH_MORE)

        # Convert the image to black and white, according to a threshold.
        # Make a negative image, because that works with the PIL getbbox routine.

        if args.verbose:
            print(page_num+1, end=" ") # page num numbering from 1
        # Note that the point method calls the function on each pixel, replacing it.
        #im = im.point(lambda p: p > threshold and 255) # create a positive image
        #im = im.point(lambda p: p < threshold and 255)  # create a negative image
        # Below code is easier to understand than tricky use of "and" in evaluation.
        im = im.point(lambda p: 255 if p < threshold else 0)  # create a negative image

        if args.showImages:
            im.show() # usually for debugging or param-setting

        # Calculate the bounding box of the negative image, and append to list.
        bounding_box = calculate_bounding_box_from_image(im, curr_page)
        bounding_box_list.append(bounding_box)

        # Clean up the image files after they are no longer needed.
        # tmpImageFile.close() # see above comment
        os.remove(tmp_image_file_name)

    if args.verbose:
        print()
    return bounding_box_list
963911
def ticket_form_show(self, id, **kwargs):
        ""
        api_path = "/api/v2/ticket_forms/{id}.json"
        api_path = api_path.format(id=id)
        return self.call(api_path, **kwargs)
28000
def _printer(self, *out, **kws):
        """"""
        flush = kws.pop('flush', True)
        fileh = kws.pop('file', self.writer)
        sep = kws.pop('sep', ' ')
        end = kws.pop('sep', '\n')

        print(*out, file=fileh, sep=sep, end=end)
        if flush:
            fileh.flush()
625556
def ticket_related(self, id, **kwargs):
        ""
        api_path = "/api/v2/tickets/{id}/related.json"
        api_path = api_path.format(id=id)
        return self.call(api_path, **kwargs)
408094
def cli(env, title, subject_id, body, hardware_identifier, virtual_identifier, priority):
    """"""
    ticket_mgr = SoftLayer.TicketManager(env.client)

    if body is None:
        body = click.edit('\n\n' + ticket.TEMPLATE_MSG)
    created_ticket = ticket_mgr.create_ticket(
        title=title,
        body=body,
        subject=subject_id,
        priority=priority)

    if hardware_identifier:
        hardware_mgr = SoftLayer.HardwareManager(env.client)
        hardware_id = helpers.resolve_id(hardware_mgr.resolve_ids, hardware_identifier, 'hardware')
        ticket_mgr.attach_hardware(created_ticket['id'], hardware_id)

    if virtual_identifier:
        vs_mgr = SoftLayer.VSManager(env.client)
        vs_id = helpers.resolve_id(vs_mgr.resolve_ids, virtual_identifier, 'VS')
        ticket_mgr.attach_virtual_server(created_ticket['id'], vs_id)

    env.fout(ticket.get_ticket_results(ticket_mgr, created_ticket['id']))
730843
def admin_print
      return if !user_is_allowed('orders', 'edit')    
       
      pdf = OrderPdf.new
      pdf.order = Order.find(params[:id])             
      send_data pdf.to_pdf, :filename => "order_#{pdf.order.id}.pdf", :type => "application/pdf", :disposition => "inline"
      
      #@order = Order.find(params[:id])
      #render :layout => 'caboose/admin'
    end