Merge lp:~kiddo/recipe-manager/xdg-dirs into lp:recipe-manager

Proposed by Jeff Fortin Tam
Status: Merged
Merged at revision: 8
Proposed branch: lp:~kiddo/recipe-manager/xdg-dirs
Merge into: lp:recipe-manager
Diff against target: 144 lines (+37/-11) (has conflicts)
6 files modified
librecipemanager/edit_dialog.py (+5/-2)
librecipemanager/globals.py (+10/-2)
librecipemanager/main_window.py (+5/-0)
librecipemanager/recipe.py (+1/-1)
librecipemanager/recipe_cell_renderer.py (+6/-2)
librecipemanager/utils.py (+10/-4)
Text conflict in librecipemanager/main_window.py
To merge this branch: bzr merge lp:~kiddo/recipe-manager/xdg-dirs
Reviewer Review Type Date Requested Status
Daniel G. Taylor Approve
Review via email: mp+36947@code.launchpad.net

Description of the change

This implements saving the recipes into the user's home directory according to the XDG spec. I have tested this branch and it seems to work for me. Please test, check that the code makes sense, and merge it.

To post a comment you must log in.
Revision history for this message
Daniel G. Taylor (danielgtaylor) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== renamed file 'photos/default.jpg' => 'default_photo.jpg'
2=== modified file 'librecipemanager/edit_dialog.py'
3--- librecipemanager/edit_dialog.py 2010-09-21 14:48:47 +0000
4+++ librecipemanager/edit_dialog.py 2010-09-29 03:38:39 +0000
5@@ -30,7 +30,7 @@
6 import gobject
7 import gtk, gtk.glade, gtk.gdk
8
9-from globals import GLADE_FILE, PHOTO_DIR, MEASURES
10+from globals import GLADE_FILE, PHOTO_DIR, DEFAULT_PHOTO, MEASURES
11 from recipe import Ingredient
12
13 class RecipeEditDialog:
14@@ -95,7 +95,10 @@
15 if recipe:
16 self.name.set_text(recipe.name)
17 self.desc.get_buffer().set_text(recipe.description)
18- self.photo.set_filename(os.path.join(PHOTO_DIR, recipe.photo))
19+ if recipe.photo:
20+ self.photo.set_filename(os.path.join(PHOTO_DIR, recipe.photo))
21+ else:
22+ self.photo.set_filename(DEFAULT_PHOTO)
23 self.cuisine.set_active(recipe.cuisine)
24 self.course.set_active(recipe.course)
25 self.servings.set_value(recipe.servings)
26
27=== modified file 'librecipemanager/globals.py'
28--- librecipemanager/globals.py 2010-09-21 14:48:47 +0000
29+++ librecipemanager/globals.py 2010-09-29 03:38:39 +0000
30@@ -27,15 +27,23 @@
31
32 import os, os.path
33 import sys
34+import xdg.BaseDirectory as xdg_dirs # Freedesktop directories spec
35
36 # The main directory where e.g. interface files are stored
37 DATA_DIR = os.path.abspath(os.path.dirname(sys.argv[0]))
38
39 # The directory where recipe photos are stored
40-PHOTO_DIR = os.path.join(DATA_DIR, "photos")
41+PHOTO_DIR = os.path.join(xdg_dirs.xdg_data_home, "recipe-manager", "photos")
42+if not os.path.isdir(PHOTO_DIR):
43+ os.makedirs(PHOTO_DIR)
44+
45+# The path for the default image when recipe.photo == None
46+DEFAULT_PHOTO = os.path.join(DATA_DIR, "default_photo.jpg")
47
48 # The directory where recipe xml files are stored
49-RECIPE_DIR = os.path.join(DATA_DIR, "recipes")
50+RECIPE_DIR = os.path.join(xdg_dirs.xdg_data_home, "recipe-manager", "recipes")
51+if not os.path.isdir(RECIPE_DIR):
52+ os.makedirs(RECIPE_DIR)
53
54 # The directory where themes are stored
55 THEME_DIR = os.path.join(DATA_DIR, "themes")
56
57=== modified file 'librecipemanager/main_window.py'
58--- librecipemanager/main_window.py 2010-09-29 03:24:14 +0000
59+++ librecipemanager/main_window.py 2010-09-29 03:38:39 +0000
60@@ -34,8 +34,13 @@
61 import xml.parsers.expat
62
63 from globals import GLADE_FILE, CONFIG_PATH, RECIPE_DIR, PHOTO_DIR, \
64+<<<<<<< TREE
65 CUISINES, COURSES, MEASURES
66 from utils import config_get, create_menu_item, archive_from_recipe, extract_recipe_archive
67+=======
68+ DEFAULT_PHOTO, CUISINES, COURSES, MEASURES
69+from utils import config_get, create_menu_item, archive_from_recipe
70+>>>>>>> MERGE-SOURCE
71 from recipe import Recipe
72 from widgets import RecipeList
73 from view_dialog import RecipeViewDialog
74
75=== modified file 'librecipemanager/recipe.py'
76--- librecipemanager/recipe.py 2010-09-21 14:48:47 +0000
77+++ librecipemanager/recipe.py 2010-09-29 03:38:39 +0000
78@@ -109,7 +109,7 @@
79 def __init__(self, filename=None):
80 self.name = "New Recipe"
81 self.description = "Description"
82- self.photo = "default.jpg"
83+ self.photo = None
84 self.cuisine = 0
85 self.course = 0
86 self.servings = 1
87
88=== modified file 'librecipemanager/recipe_cell_renderer.py'
89--- librecipemanager/recipe_cell_renderer.py 2010-09-21 21:08:57 +0000
90+++ librecipemanager/recipe_cell_renderer.py 2010-09-29 03:38:39 +0000
91@@ -30,7 +30,7 @@
92 import gtk
93 import pango
94
95-from globals import PHOTO_DIR
96+from globals import PHOTO_DIR, DEFAULT_PHOTO
97 from utils import create_layout, draw_photo_with_border
98
99 class RecipeCellRenderer(gtk.GenericCellRenderer):
100@@ -93,7 +93,11 @@
101 """
102 default_size = widget.get_style().font_desc.get_size() / pango.SCALE
103
104- filename = os.path.join(PHOTO_DIR, self.recipe.photo)
105+ #FIXME: This method is called WAY too often. Put a print and see.
106+ if self.recipe.photo:
107+ filename = os.path.join(PHOTO_DIR, self.recipe.photo)
108+ else:
109+ filename = DEFAULT_PHOTO
110 photo = gtk.gdk.pixbuf_new_from_file_at_size(filename, self._photo_size,
111 self._photo_size)
112
113
114=== modified file 'librecipemanager/utils.py'
115--- librecipemanager/utils.py 2010-09-21 21:46:33 +0000
116+++ librecipemanager/utils.py 2010-09-29 03:38:39 +0000
117@@ -33,7 +33,7 @@
118 import math
119 import tarfile
120
121-from globals import CONFIG_PATH, RECIPE_DIR, PHOTO_DIR
122+from globals import CONFIG_PATH, RECIPE_DIR, PHOTO_DIR, DEFAULT_PHOTO
123
124 _config = None
125
126@@ -240,9 +240,15 @@
127 when being imported.
128 """
129 archive = tarfile.open(filename, "w:gz")
130- os.chdir(PHOTO_DIR)
131- archive.add(os.path.basename(recipe.photo),
132- os.path.join("photos", os.path.basename(recipe.photo)))
133+
134+ # FIXME: Not sure if we should actually add a picture if == None
135+ if recipe.photo:
136+ os.chdir(PHOTO_DIR)
137+ photo_to_add = os.path.basename(recipe.photo)
138+ else:
139+ photo_to_add = DEFAULT_PHOTO
140+ archive.add(photo_to_add,
141+ os.path.join("photos", photo_to_add))
142 os.chdir(RECIPE_DIR)
143 archive.add(os.path.basename(recipe.filename),
144 os.path.join("recipes", os.path.basename(recipe.filename)))

Subscribers

People subscribed via source and target branches