Merge lp:~joshbrown/photostory/0.9_to_0.95 into lp:~photostory/photostory/import

Proposed by Josh Brown
Status: Merged
Merged at revision: 2
Proposed branch: lp:~joshbrown/photostory/0.9_to_0.95
Merge into: lp:~photostory/photostory/import
Diff against target: 62 lines (+24/-28)
1 file modified
photostory_0.9_to_0.95.py (+24/-28)
To merge this branch: bzr merge lp:~joshbrown/photostory/0.9_to_0.95
Reviewer Review Type Date Requested Status
Joel Auterson Approve
Review via email: mp+49842@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Josh Brown (joshbrown) wrote :

Excellent work writing the script Joel, however I have made a few minor changes that should make the script cleaner and more compact; I'd be grateful if you could double-check that my version works and then merge it in. I also think that the main branch (currently <import>) should perhaps be re-created under a less ambiguous name (such as <0.9_to_0.95>), although this isn't hugely important as I don't expect the branch to be in use for a long amount of time.

Revision history for this message
Joel Auterson (joel-auterson) wrote :

Josh - how exactly does this reformat? The files come out looking the same, correct?

Revision history for this message
Josh Brown (joshbrown) wrote :

The files should come out in the specified YYYY-MM-DD.png format. The main change is the way in which this formatting is handled, in this version it's handled in a single line:

filename = '{0}{1:04d}-{2:02d}-{3:02d}.png'.format(NEWdb, year, month, day)

Revision history for this message
Joel Auterson (joel-auterson) wrote :

Very clever, I wouldn't have thought of doing that.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== renamed file 'photostory_import.py' => 'photostory_0.9_to_0.95.py'
2--- photostory_import.py 2011-02-15 10:24:41 +0000
3+++ photostory_0.9_to_0.95.py 2011-02-15 17:26:19 +0000
4@@ -1,34 +1,30 @@
5-#!/usr/bin/python
6-
7-#Photostory 0.95 - Importer for previous versions
8-#by Joel Auterson (joel.auterson@googlemail.com)
9-#http://www.launchpad.net/photostory
10-
11-import cPickle
12-import os
13-import os.path
14-import shutil
15+#!/usr/bin/env python
16+
17+# Photostory 0.9 -> 0.95 Data Converter
18+# by Joel Auterson (joel.auterson@googlemail.com)
19+# http://launchpad.net/photostory
20+
21+# The format with which data is stored has been changed in Photostory 0.95.
22+# Users must manually run this script before uninstalling Photostory 0.9 to
23+# move and reformat their data as the new 0.95 format.
24+
25+import os, cPickle, shutil
26+
27+OLDdb = '/usr/share/photostory/data/db'
28+NEWdb = os.path.expanduser('~/.photostory/photos/')
29
30 # If the `~/.photostory/photos` directory doesn't exist, create it:
31-if not os.path.exists(os.path.expanduser('~/.photostory/photos')):
32- os.makedirs(os.path.expanduser('~/.photostory/photos'))
33-
34-db = cPickle.load(open('/usr/share/photostory/data/db', 'rb'))
35-n = 0
36-
37-while (n < len(db)):
38+if not os.path.exists(NEWdb): os.makedirs(NEWdb)
39+
40+db = cPickle.load(open(OLDdb, 'rb'))
41+
42+# Move and rename each photo to `~/.photostory/photos/YYYY-MM-DD.png`:
43+for n in range(len(db)):
44 dateTuple = db.keys()[n]
45 year = dateTuple[0]
46 month = dateTuple[1] + 1
47 day = dateTuple[2]
48-
49- if (month < 10):
50- month = "0" + str(month)
51- if (day < 10):
52- day = "0" + str(day)
53-
54- theFile = os.path.expanduser("~/.photostory/photos/") + str(year) + "-" + str(month) + "-" + str(day) + ".png"
55- shutil.copy(db[dateTuple], theFile)
56- n = n + 1
57-
58-print 'Done.'
59+ filename = '{0}{1:04d}-{2:02d}-{3:02d}.png'.format(NEWdb, year, month, day)
60+ shutil.copy(db[dateTuple], filename)
61+
62+print 'Reformatting complete.'

Subscribers

People subscribed via source and target branches

to all changes: