def get_info_libtiff(filename): """Get tiff info of a file with ``tiffinfo``, which needs to be installed on your system. :param filename: name of tiff image file :type filename: string :returns: info about the file :rtype: dict """ result = {} def set(key, value): key = 'libtiff.' + key.lower().replace(' ', '.') if not (key in result): result[key] = value source, err = system.shell((TIFFINFO, filename)) for match in RE_TIFF_FIELD.finditer(source): value = match.group(2) again = RE_TIFF_FIELD_IMAGE.search(value) if again: set('Image %s' % again.group(1), again.group(2)) set(match.group(1), value[:again.start()]) else: set(match.group(1), value) if not result: raise IOError('Not a TIFF or MDI file, bad magic number.') result['compression'] = \ TIFF_COMPRESSION[result['libtiff.compression.scheme']] return result
def open_image_with_command(filename, command, app, extension="png", temp_ext=None): """Open with an external command (such as Inkscape, dcraw, imagemagick). :param filename: filename, from which a temporary filename will be derived :type filename: string :param command: conversion command with optional temp file interpolation :type command: string :param extension: file type :type extension: string :param temp_ext: if a temp file can not be specified to the command (eg dcraw), give the file extension of the command output :type temp_ext: string """ temp = None temp_file = None if temp_ext: # eg dcraw temp_file = os.path.splitext(filename)[0] + "." + temp_ext else: # imagemagick, ... if not extension.startswith("."): extension = "." + extension temp = system.TempFile(extension) temp_file = temp.path command.append(temp_file) try: output, error = system.shell(command) if os.path.exists(temp_file): image = Image.open(temp_file) image.load() # otherwise temp file can't be deleted image.info["Convertor"] = app return image finally: if temp: temp.close(force_remove=False) elif temp_ext and os.path.exists(temp_file): os.remove(temp_file) message = _("Could not open image with %s.") % app + "\n\n%s: %s\n\n%s: %s\n\n%s: %s" % ( _("Command"), command, _("Output"), output, _("Error"), error, ) raise IOError(message)
def open_image_with_command(filename, command, app, extension='png', temp_ext=None): """Open with an external command (such as Inkscape, dcraw, imagemagick). :param filename: filename, from which a temporary filename will be derived :type filename: string :param command: conversion command with optional temp file interpolation :type command: string :param extension: file type :type extension: string :param temp_ext: if a temp file can not be specified to the command (eg dcraw), give the file extension of the command output :type temp_ext: string """ temp = None temp_file = None if temp_ext: # eg dcraw temp_file = os.path.splitext(filename)[0] + '.' + temp_ext else: # imagemagick, ... if not extension.startswith('.'): extension = '.' + extension temp = system.TempFile(extension) temp_file = temp.path command.append(temp_file) try: output, error = system.shell(command) if os.path.exists(temp_file): image = Image.open(temp_file) image.load() # otherwise temp file can't be deleted image.info['Convertor'] = app return image finally: if temp: temp.close(force_remove=False) elif temp_ext and os.path.exists(temp_file): os.remove(temp_file) message = _('Could not open image with %s.') % app + \ '\n\n%s: %s\n\n%s: %s\n\n%s: %s' % \ (_('Command'), command, _('Output'), output, _('Error'), error) raise IOError(message)
def save_libtiff(image, filename, compression=None, **options): """Saves a tiff compressed file with tiffcp. :param image: PIL image :type image: Image.Image :param filename: name of tiff image file :type filename: string :param compression: g3, g4, jpeg, lzw, tiff_lzw :type compression: string :returns: log message :rtype: string """ if compression in ['raw', 'none']: image.save(filename, 'tiff', **options) return '' if compression is None: compression = image.info['compression'] elif compression in ['g3', 'g4'] and image.mode != '1': image = image.convert('1') if compression == 'jpeg': option = ['-r', '16'] if image.mode == 'RGBA': image = image.convert('RGB') else: option = [] if compression == 'tiff_lzw': compression = 'lzw' temp = system.TempFile() try: image.save(temp.path, 'tiff', **options) input = [TIFFCP, temp.path, '-c', compression] if option: input.extend(option) input.append(filename) out, err = system.shell(input) finally: temp.close() if out or err: return 'Subprocess "tiffcp"\ninput:\n%s\noutput:\n%s%s\n'\ % (input, out, err) return ''
def save_libtiff(image, filename, compression=None, **options): """Saves a tiff compressed file with tiffcp. :param image: PIL image :type image: Image.Image :param filename: name of tiff image file :type filename: string :param compression: g3, g4, jpeg, lzw, tiff_lzw :type compression: string :returns: log message :rtype: string """ if compression in ["raw", "none"]: image.save(filename, "tiff", **options) return "" if compression is None: compression = image.info["compression"] elif compression in ["g3", "g4"] and image.mode != "1": image = image.convert("1") if compression == "jpeg": option = ["-r", "16"] if image.mode == "RGBA": image = image.convert("RGB") else: option = [] if compression == "tiff_lzw": compression = "lzw" temp = system.TempFile() try: image.save(temp.path, "tiff", **options) input = [TIFFCP, temp.path, "-c", compression] if option: input.extend(option) input.append(filename) out, err = system.shell(input) finally: temp.close() if out or err: return 'Subprocess "tiffcp"\ninput:\n%s\noutput:\n%s%s\n' % (input, out, err) return ""
import system system.shell(True)
#Increment counter counter+=1 #time.sleep(0.01) prev = current display.orientation(90) drawNickname() # Terminal menu import term, term_menu cfg_term_menu = machine.nvs_get_u8('splash', 'term_menu') # Show a menu on the serial port instead of a prompt if cfg_term_menu == None: cfg_term_menu = True # If not set the menu is shown if cfg_term_menu: umenu = term_menu.UartMenu(None, None, False) umenu.main() pass else: print("Welcome!") print("The homescreen and it's services are currently being run.") print("Press CTRL+C to reboot directly to a Python prompt.") wait = True while wait: c = machine.stdin_get(1,1) if c == "\x03" or c == "\x04": # CTRL+C or CTRL+D wait = False stopThreads = True system.shell()
def _start_shell(): print("Type 'exit' to continue with the installation, 'exit 1' to abort") try: system.shell() except exceptions.CalledProcessError: raise exceptions.AbortOperation