def update_filename(self, result, parent_index, filename): dirname, basename = os.path.split(filename) dirname = ensure_unicode(dirname) basename = ensure_unicode(basename) message = u"%s: %s\n%s: %s\n" \ % (_('In'), dirname, _('File'), basename) self.update(result, parent_index * self.child_max, newmsg=message) self.sleep()
def get_image_infos(paths, info_file, extensions, recursive): """Get all image info dictionaries from a mix of folder and file paths. :param paths: file and/or folderpaths :type paths: list of strings :param extensions: extensions (without ``.``) :type extensions: list of strings :param recursive: include subfolders :type recursive: bool :returns: list of image file info :rtype: list of dictionaries .. see also:: :func:`get_image_infos_from_folder` """ image_infos = [] for path in paths: path = os.path.abspath(path.strip()) if os.path.isfile(path): #single image file info = {'folderindex': 0} info.update(info_file.dump(path)) image_infos.append(info) elif os.path.isdir(path): #folder of image files image_infos.extend(get_image_infos_from_folder( path, info_file, extensions, recursive)) else: #not a file or folder?! probably does not exist send.frame_show_error('Sorry, "%s" is not a valid path.' \ % ensure_unicode(path)) return [] image_infos.sort(key=operator.itemgetter('path')) return image_infos
def fix_python_path(phatch_python_path=None): if not phatch_python_path: phatch_python_path = os.path.dirname( os.path.dirname(os.path.abspath(__file__))) if not(phatch_python_path in [ensure_unicode(x) for x in sys.path]): sys.path.insert(0, phatch_python_path) return phatch_python_path
def log_warning(message, input, action=None): """Writer warning message to log file. Helper function for :func:`flush_log`, :func:`process_error`. :param message: error message :type message: string :param input: input image :type input: string :returns: error log details :rtype: string """ global WARNING_LOG_COUNTER if WARNING_LOG_COUNTER == None: # doctests return if action: action = action.label details = ensure_unicode( WARN_MESSAGE % { 'number': WARNING_LOG_COUNTER + 1, 'message': message, 'input': input, 'action': action, }) logging.warn( unicode(details.encode(ENCODING, 'replace'), ENCODING, 'replace')) WARNING_LOG_COUNTER += 1 return details
def fix_python_path(phatch_python_path=None): if not phatch_python_path: phatch_python_path = os.path.dirname( os.path.dirname(os.path.abspath(__file__))) if not (phatch_python_path in [ensure_unicode(x) for x in sys.path]): sys.path.insert(0, phatch_python_path) return phatch_python_path
def log_error(message, input='*', action=None, show=True, exception=False): """Writer error message to log file. Helper function for :func:`flush_log`, :func:`process_error`. :param message: error message :type message: string :param input: input image :type input: string :returns: error log details :rtype: string """ global ERROR_LOG_COUNTER if ERROR_LOG_COUNTER == None: # doctests return if action: action = pprint.pformat(action.dump()) if exception: traceback_details = ensure_unicode(traceback.format_exc()) else: traceback_details = '' message = ensure_unicode(message) details = ensure_unicode( ERROR_MESSAGE % { 'number': ERROR_LOG_COUNTER + 1, 'message': message, 'input': input, 'action': action, 'details': traceback_details, }) logging.error( unicode(details.encode(ENCODING, 'replace'), ENCODING, 'replace')) ERROR_LOG_COUNTER += 1 if show: # keep this for last as in console mode phatch quits on an error send.frame_show_error(message) return details
def apply_action_to_photo(action, photo, read_only_settings, cache, image_file, result): """Apply a single action to a photo. It uses :func:`log_error` for non fatal errors or :func:`process_error` for serious errors. The settings are read only as the actions don't have permission to change them. :param action: action :type action: :class:`core.models.Action` :param photo: photo :type photo: :class:`core.pil.Photo` :param read_only_settings: read only settings :type read_only_settings: :class:`lib.odict.ReadOnlyDict` :param cache: cache for data which is usefull across photos :type cache: dictionary :param image_file: filename reference during error logging :type image_file: string :param result: settings for dialog (eg ``stop_for_errors``) :type result: dictionary """ try: photo = action.apply(photo, read_only_settings, cache) result['skip'] = False result['abort'] = False #log non fatal errors/warnings flush_log(photo, image_file, action) return photo, result except Exception, details: flush_log(photo, image_file, action) folder, image = os.path.split(ensure_unicode(image_file)) reason = exception_to_unicode(details) message = u'%s\n%s\n%s' % ( _("Can not apply action %(a)s on image '%(i)s' in folder:")\ % {'a': _(action.label), 'i': image}, folder, reason, ) return process_error(photo, message, image_file, action, result, ignore=True)
def apply_action_to_photo(action, photo, read_only_settings, cache, image_file, result): """Apply a single action to a photo. It uses :func:`log_error` for non fatal errors or :func:`process_error` for serious errors. The settings are read only as the actions don't have permission to change them. :param action: action :type action: :class:`core.models.Action` :param photo: photo :type photo: :class:`core.pil.Photo` :param read_only_settings: read only settings :type read_only_settings: :class:`lib.odict.ReadOnlyDict` :param cache: cache for data which is usefull across photos :type cache: dictionary :param image_file: filename reference during error logging :type image_file: string :param result: settings for dialog (eg ``stop_for_errors``) :type result: dictionary """ try: photo = action.apply(photo, read_only_settings, cache) result['skip'] = False result['abort'] = False #log non fatal errors/warnings flush_log(photo, image_file, action) return photo, result except Exception, details: flush_log(photo, image_file, action) folder, image = os.path.split(ensure_unicode(image_file)) reason = exception_to_unicode(details) message = u'%s\n%s\n\n%s' % ( _("Can not apply action %(a)s on image '%(i)s' in folder:")\ % {'a': _(action.label), 'i': image}, folder, reason, ) return process_error(photo, message, image_file, action, result, ignore=True)
def get_command(self, values): def rename(old, new): x = values[old] values[new] = x del values[old] for new, old in [ ('rotation_x', 'camera_roll'), ('rotation_y', 'camera_vertical_rotation'), ('rotation_z', 'camera_horizontal_rotation'), ]: rename(old, new) arg_list = [] for extra_option in (self.options + self.extra_options): delim_name = extra_option.lower().replace(' ', '_') arg_list.extend([delim_name, ensure_unicode(values[delim_name])]) return [values['blender'], '-b', values['blend'], '-P', values['runner'], '--', ] + arg_list
def to_english(x): _x = _r(ensure_unicode(x)) if x != _x: return _x return RE_EXPR.sub(_expr_to_english, x)
def OnGetItemText(self, item, col): return ensure_unicode(self.data.get(item, col))
def compile_sub_expr(expr): return ensure_unicode( eval(preprocess(expr.group(1)), _globals, _locals))