コード例 #1
0
ファイル: test_exporters.py プロジェクト: takluyver/gourmet
 def setup_db(self):
     print('rm.dbargs[file]=', rm.dbargs['file'])
     self.db = rm.RecipeManager(**rm.dbargs)
     if self.db.fetch_len(self.db.recipe_table) == 0:
         raise Exception("No recipes in database.")
     self.mult_export_args = {
         'rd': self.db,
         'rv': self.db.fetch_all(self.db.recipe_table),
         'conv': None,
         'prog': None,
         'extra_prefs': {}
     }
コード例 #2
0
def dump_old_data():

    try:
        import gourmet
    except ImportError:
        sys.path.append(os.path.join(os.path.sep + 'usr', 'share'))
        try:
            import gourmet
        except:
            print 'No previous gourmet installation found.'
            return

    import gourmet.recipeManager as recipeManager  # The *old* Gourmet

    # We need to get our upgradeHandler from the *new* Gourmet...
    gourmet_base_path = os.path.split(
        os.path.split(os.path.abspath(__file__))[0])[0]
    sys.path.append(os.path.join(gourmet_base_path, 'src', 'lib'))
    print 'just added', sys.path[-1]
    import glob
    import upgradeHandler

    #for mkdata in glob.glob('/home/*/.gourmet/recipes.mk'):
    for mkdata in [
            '/home/tom/Projects/grm-db-experiments/src/lib/exporters/reference_setup/recipes.mk'
    ]:
        print 'Dumping old recipe database', mkdata, '...'
        stat = os.stat(mkdata)
        uid, gid = stat.st_uid, stat.st_gid
        recipeManager.dbargs['file'] = mkdata
        try:
            recipeManager.RecipeManager(**recipeManager.dbargs)
        except:
            print 'Unable to load old database in ', mkdata
            continue
        se = upgradeHandler.SimpleExporter()
        ofi = os.path.join(os.path.split(mkdata)[0], 'GOURMET_DATA_DUMP')
        se.write_data(file(ofi, 'w'))
        del se
        del recipeManager
        os.chown(ofi, uid, gid)
        os.chown(mkdata, uid, gid)
        print 'Saved data in backup file ', ofi
        print 'Data will be imported on first start of the new Gourmet by the appropriate user.'
コード例 #3
0
                kwargs[column] = s
            vw = self.get_vw(kwargs, extras_search)
        self.change_view(vw)

    def _get_value_(self, row, attr):
        return getattr(row, attr)

    def _get_slice_(self, bottom, top):
        try:
            return [[r] +
                    [self._get_value_(r, col) for col in self.columns[1:]]
                    for r in self.view[bottom:top]]
        except:
            print('_get_slice_ failed with', bottom, top)
            raise


if __name__ == '__main__':
    import gourmet.recipeManager as rm
    rd = rm.RecipeManager()
    nie = NutritionInfoIndex(rd,
                             ingredients=[
                                 'cilantro', 'tomato', 'basil', 'water',
                                 'onion, red', 'onion, white', 'scallion',
                                 'hare'
                             ])
    nie.window.show()
    nie.window.connect('delete-event', Gtk.main_quit)
    #nie.show_index_page()
    Gtk.main()
コード例 #4
0
ファイル: nutrition.py プロジェクト: eginhard/gourmet
    def recursive_length(self):
        """Return number of contained nutrition info objects, recursing any embedded lists.
        """
        n = 0
        for x in range(len(self)):
            obj = self[x]
            if isinstance(obj, NutritionInfoList):
                n += obj.recursive_length()
            else:
                n += 1
        return n


if __name__ == '__main__':
    import gourmet.recipeManager as rm
    db = rm.RecipeManager(**rm.dbargs)
    import gourmet.convert
    conv = gourmet.convert.converter()
    from . import nutritionGrabberGui
    nutritionGrabberGui.check_for_db(db)
    nd = NutritionData(db, conv)


def foo():
    from gourmet import convert

    class SimpleInterface:
        def __init__(self, nd):
            self.ACTIONS = {
                'Add ingredient': self.add_ingredient,
                'Add key info': self.add_key,
コード例 #5
0
def load_recmanager():
    return recipeManager.RecipeManager(**recipeManager.dbargs)
コード例 #6
0
                xml.sax.saxutils.escape(str(content)))
            col_el.appendChild(textNode)


if __name__ == '__main__':
    import tempfile
    #     print 'Dump file...'
    #     e = SimpleExporter()
    #     ofi = tempfile.mktemp('.gourmet_dump')
    #     print 'Dumping to ',ofi
    #     outfi = file(ofi,'w')
    #     e.write_data(outfi)
    #     outfi.close()
    #     print 'Load file from',ofi,'...'
    recipeManager.dbargs['file'] = tempfile.mktemp('.db')
    rm = recipeManager.RecipeManager(**recipeManager.dbargs)
    ofi = '/tmp/tmpCB4E9M.gourmet_dump'
    from gtk_extras import dialog_extras as de
    import gtk
    pd = de.ProgressDialog()
    pd.show()

    def prog(n):
        pd.set_progress(n, 'Importing old data into new database.')
        while gtk.events_pending():
            gtk.main_iteration()

    import_backup_file(rm, ofi, prog)
    print 'Done!'
    pd.hide()
    while gtk.events_pending():