Example #1
0
 def __init__(self,
              rd,
              recipes,
              out,
              one_file=True,
              ext='txt',
              conv=None,
              imgcount=1,
              progress_func=None,
              exporter=exporter,
              exporter_kwargs={},
              padding=None):
     """Output all recipes in recipes into a document or multiple
     documents. if one_file, then everything is in one
     file. Otherwise, we treat 'out' as a directory and put
     individual recipe files within it."""
     self.timer = TimeAction('exporterMultirec.__init__()')
     self.rd = rd
     self.recipes = recipes
     self.out = out
     self.padding = padding
     self.one_file = one_file
     Pluggable.__init__(self, [BaseExporterMultiRecPlugin])
     SuspendableThread.__init__(self, self.name)
     if progress_func:
         print 'Argument progress_func is obsolete and will be ignored:', progress_func
     self.ext = ext
     self.exporter = exporter
     self.exporter_kwargs = exporter_kwargs
     self.fractions = self.exporter_kwargs.get('fractions',
                                               convert.FRACTIONS_ASCII)
     self.DEFAULT_ENCODING = self.exporter.DEFAULT_ENCODING
     self.one_file = one_file
Example #2
0
 def __init__(
     self,
     rd,
     recipes,
     out,
     one_file=True,
     ext="txt",
     conv=None,
     imgcount=1,
     progress_func=None,
     exporter=exporter,
     exporter_kwargs={},
     padding=None,
 ):
     """Output all recipes in recipes into a document or multiple
     documents. if one_file, then everything is in one
     file. Otherwise, we treat 'out' as a directory and put
     individual recipe files within it."""
     self.timer = TimeAction("exporterMultirec.__init__()")
     self.rd = rd
     self.recipes = recipes
     self.out = out
     self.padding = padding
     self.one_file = one_file
     Pluggable.__init__(self, [BaseExporterMultiRecPlugin])
     SuspendableThread.__init__(self, self.name)
     if progress_func:
         print "Argument progress_func is obsolete and will be ignored:", progress_func
     self.ext = ext
     self.exporter = exporter
     self.exporter_kwargs = exporter_kwargs
     self.fractions = self.exporter_kwargs.get("fractions", convert.FRACTIONS_ASCII)
     self.DEFAULT_ENCODING = self.exporter.DEFAULT_ENCODING
     self.one_file = one_file
Example #3
0
    def __init__(
        self,
        rd=None,  # OBSOLETE
        total=0,
        prog=None,  # OBSOLETE
        do_markup=True,
        conv=None,
        rating_converter=None,
        name="importer",
    ):
        """rd is our recipeData instance.

        Total is used to keep track of progress.

        do_markup should be True if instructions and modifications
        come to us unmarked up (i.e. if we need to escape < and &,
        etc. -- this might be False if importing e.g. XML).
        """

        timeaction = TimeAction("importer.__init__", 10)
        if not conv:
            self.conv = convert.get_converter()
        self.id_converter = {}  # a dictionary for tracking named IDs
        self.total = total
        if prog or rd:
            import traceback

            traceback.print_stack()
            if prog:
                print "WARNING: ", self, "handed obsolete parameter prog=", prog
            if rd:
                print "WARNING: ", self, "handed obsolete parameter rd=", rd
        self.do_markup = do_markup
        self.count = 0
        self.rd = get_recipe_manager()
        self.rd_orig_ing_hooks = self.rd.add_ing_hooks
        self.added_recs = []
        self.added_ings = []
        # self.rd_orig_hooks = self.rd.add_hooks
        self.rd.add_ing_hooks = []
        # self.rd.add_hooks = []
        self.position = 0
        self.group = None
        # allow threaded calls to pause
        self.suspended = False
        # allow threaded calls to be terminated (this
        # has to be implemented in subclasses).
        self.terminated = False
        # Our rating converter -- if we've been handed a class, we
        # assume our caller will handle doing the
        # conversion. Otherwise we do it ourselves.
        if rating_converter:
            self.rating_converter = rating_converter
            self.do_conversion = False
        else:
            self.rating_converter = RatingConverter()
            self.do_conversion = True
        self.km = keymanager.get_keymanager()
        timeaction.end()
        SuspendableThread.__init__(self, name=name)
Example #4
0
 def __init__ (self, rd, recipes, out, one_file=True,
               ext='txt',
               conv=None,
               imgcount=1,
               exporter=exporter,
               exporter_kwargs={},
               padding=None):
     """Output all recipes in recipes into a document or multiple
     documents. if one_file, then everything is in one
     file. Otherwise, we treat 'out' as a directory and put
     individual recipe files within it."""
     self.timer=TimeAction('exporterMultirec.__init__()')
     self.rd = rd
     self.recipes = recipes
     self.out = out
     self.padding=padding
     self.one_file = one_file
     Pluggable.__init__(self,[BaseExporterMultiRecPlugin])
     SuspendableThread.__init__(self,self.name)
     self.ext = ext
     self.exporter = exporter
     self.exporter_kwargs = exporter_kwargs
     self.fractions = self.exporter_kwargs.get('fractions',
                                               convert.FRACTIONS_ASCII)
     self.DEFAULT_ENCODING = self.exporter.DEFAULT_ENCODING
     self.one_file = one_file
Example #5
0
    def __init__(
            self,
            rd=None,  # OBSOLETE
            total=0,
            prog=None,  # OBSOLETE
            do_markup=True,
            conv=None,
            rating_converter=None,
            name='importer'):
        """rd is our recipeData instance.

        Total is used to keep track of progress.

        do_markup should be True if instructions and modifications
        come to us unmarked up (i.e. if we need to escape < and &,
        etc. -- this might be False if importing e.g. XML).
        """

        timeaction = TimeAction('importer.__init__', 10)
        if not conv: self.conv = convert.get_converter()
        self.id_converter = {}  # a dictionary for tracking named IDs
        self.total = total
        if prog or rd:
            import traceback
            traceback.print_stack()
            if prog:
                print('WARNING: ', self, 'handed obsolete parameter prog=',
                      prog)
            if rd:
                print('WARNING: ', self, 'handed obsolete parameter rd=', rd)
        self.do_markup = do_markup
        self.count = 0
        self.rd = get_recipe_manager()
        self.rd_orig_ing_hooks = self.rd.add_ing_hooks
        self.added_recs = []
        self.added_ings = []
        #self.rd_orig_hooks = self.rd.add_hooks
        self.rd.add_ing_hooks = []
        #self.rd.add_hooks = []
        self.position = 0
        self.group = None
        # allow threaded calls to pause
        self.suspended = False
        # allow threaded calls to be terminated (this
        # has to be implemented in subclasses).
        self.terminated = False
        # Our rating converter -- if we've been handed a class, we
        # assume our caller will handle doing the
        # conversion. Otherwise we do it ourselves.
        if rating_converter:
            self.rating_converter = rating_converter
            self.do_conversion = False
        else:
            self.rating_converter = RatingConverter()
            self.do_conversion = True
        self.km = keymanager.get_keymanager()
        timeaction.end()
        SuspendableThread.__init__(self, name=name)
Example #6
0
    def __init__(
        self,
        rd,
        r,
        out,
        conv=None,
        imgcount=1,
        order=["image", "attr", "ings", "text"],
        attr_order=DEFAULT_ATTR_ORDER,
        text_attr_order=DEFAULT_TEXT_ATTR_ORDER,
        do_markup=True,
        use_ml=False,
        convert_attnames=True,
        fractions=convert.FRACTIONS_ASCII,
    ):
        """Instantiate our exporter.

        conv is a preexisting convert.converter() class
        imgcount is a number we use to start counting our exported images.
        order is a list of our core elements in order: 'image','attr','text' and 'ings'
        attr_order is a list of our attributes in the order we should export them:
                   title, category, cuisine, servings, source, rating, preptime, cooktime
        text_attr_order is a list of our text attributes.
        do_markup is a flag; if true, we interpret tags in text blocks by calling
                  self.handle_markup to e.g. to simple plaintext renderings of tags.
        use_ml is a flag; if true, we escape strings we output to be valid *ml
        convert_attnames is a flag; if true, we hand write_attr a translated attribute name
                         suitable for printing or display. If not, we just hand it the standard
                         attribute name (this is a good idea if a subclass needs to rely on the
                         attribute name staying consistent for processing, since converting attnames
                         will produce locale specific strings.
        """
        self.attr_order = attr_order
        self.text_attr_order = text_attr_order
        self.out = out
        self.r = r
        self.rd = rd
        self.do_markup = do_markup
        self.fractions = fractions
        self.use_ml = use_ml
        self.convert_attnames = convert_attnames
        if not conv:
            conv = convert.get_converter()
        self.conv = conv
        self.imgcount = imgcount
        self.images = []
        self.order = order
        Pluggable.__init__(self, [BaseExporterPlugin])
        SuspendableThread.__init__(self, self.name)
Example #7
0
    def __init__(
        self,
        rd,
        r,
        out,
        conv=None,
        imgcount=1,
        order=['image', 'attr', 'ings', 'text'],
        attr_order=DEFAULT_ATTR_ORDER,
        text_attr_order=DEFAULT_TEXT_ATTR_ORDER,
        do_markup=True,
        use_ml=False,
        convert_attnames=True,
        fractions=convert.FRACTIONS_ASCII,
    ):
        """Instantiate our exporter.

        conv is a preexisting convert.converter() class
        imgcount is a number we use to start counting our exported images.
        order is a list of our core elements in order: 'image','attr','text' and 'ings'
        attr_order is a list of our attributes in the order we should export them:
                   title, category, cuisine, servings, source, rating, preptime, cooktime
        text_attr_order is a list of our text attributes.
        do_markup is a flag; if true, we interpret tags in text blocks by calling
                  self.handle_markup to e.g. to simple plaintext renderings of tags.
        use_ml is a flag; if true, we escape strings we output to be valid *ml
        convert_attnames is a flag; if true, we hand write_attr a translated attribute name
                         suitable for printing or display. If not, we just hand it the standard
                         attribute name (this is a good idea if a subclass needs to rely on the
                         attribute name staying consistent for processing, since converting attnames
                         will produce locale specific strings.
        """
        self.attr_order = attr_order
        self.text_attr_order = text_attr_order
        self.out = out
        self.r = r
        self.rd = rd
        self.do_markup = do_markup
        self.fractions = fractions
        self.use_ml = use_ml
        self.convert_attnames = convert_attnames
        if not conv: conv = convert.get_converter()
        self.conv = conv
        self.imgcount = imgcount
        self.images = []
        self.order = order
        Pluggable.__init__(self, [BaseExporterPlugin])
        SuspendableThread.__init__(self, self.name)
Example #8
0
    def __init__(self,
                 rd,
                 recipes,
                 out,
                 one_file=True,
                 create_file=True,
                 ext='txt',
                 conv=None,
                 imgcount=1,
                 exporter=exporter,
                 exporter_kwargs={},
                 padding=None):
        """Output all recipes in recipes into a document or multiple
        documents. if one_file, then everything is in one
        file. Otherwise, we treat 'out' as a directory and put
        individual recipe files within it.

        @param out: The name of the output file or directory

        @param one_file: If True works in one_file mode. For this the class will
                    create the file which is accessible by self.ofi
                    If this is set to False a directory will be created and the
                    name of the directory will be passed via self.outdir and self.ofi

        @param create_file: If this parameter is True the files will be created
                    otherwise to create the file is up to the user.
        """
        self.timer = TimeAction('exporterMultirec.__init__()')
        self.rd = rd
        self.recipes = recipes
        self.out = out
        self.outdir = out
        self.padding = padding
        self.one_file = one_file
        Pluggable.__init__(self, [BaseExporterMultiRecPlugin])
        SuspendableThread.__init__(self, self.name)
        self.ext = ext
        self.exporter = exporter
        self.exporter_kwargs = exporter_kwargs
        self.fractions = self.exporter_kwargs.get('fractions',
                                                  convert.FRACTIONS_ASCII)
        self.DEFAULT_ENCODING = self.exporter.DEFAULT_ENCODING
        self.one_file = one_file
        self.create_file = create_file
Example #9
0
    def __init__(self, rd, recipes, out, one_file=True, create_file=True,
                 ext='txt',
                 conv=None,
                 imgcount=1,
                 exporter=exporter,
                 exporter_kwargs={},
                 padding=None):
        """Output all recipes in recipes into a document or multiple
        documents. if one_file, then everything is in one
        file. Otherwise, we treat 'out' as a directory and put
        individual recipe files within it.

        @param out: The name of the output file or directory

        @param one_file: If True works in one_file mode. For this the class will
                    create the file which is accessible by self.ofi
                    If this is set to False a directory will be created and the
                    name of the directory will be passed via self.outdir and self.ofi

        @param create_file: If this parameter is True the files will be created
                    otherwise to create the file is up to the user.
        """
        self.timer=TimeAction('exporterMultirec.__init__()')
        self.rd = rd
        self.recipes = recipes
        self.out = out
        self.outdir = out
        self.padding=padding
        self.one_file = one_file
        Pluggable.__init__(self,[BaseExporterMultiRecPlugin])
        SuspendableThread.__init__(self,self.name)
        self.ext = ext
        self.exporter = exporter
        self.exporter_kwargs = exporter_kwargs
        self.fractions = self.exporter_kwargs.get('fractions',
                                                  convert.FRACTIONS_ASCII)
        self.DEFAULT_ENCODING = self.exporter.DEFAULT_ENCODING
        self.one_file = one_file
        self.create_file = create_file