1 """
2 Provides a number of dataproviders which are associated with
3 removable devices such as USB keys.
4
5 It also includes classes specific to the ipod.
6 This file is not dynamically loaded at runtime in the same
7 way as the other dataproviders as it needs to be loaded all the time in
8 order to listen to HAL events
9
10 Copyright: John Stowers, 2006
11 License: GPLv2
12 """
13 import os
14 import pickle
15 import logging
16 log = logging.getLogger("modules.iPod")
17
18 import conduit
19 import conduit.dataproviders.DataProvider as DataProvider
20 import conduit.dataproviders.DataProviderCategory as DataProviderCategory
21 import conduit.dataproviders.VolumeFactory as VolumeFactory
22 import conduit.utils as Utils
23 import conduit.datatypes.Note as Note
24 import conduit.datatypes.Contact as Contact
25 import conduit.datatypes.Event as Event
26 import conduit.datatypes.File as File
27
28 MODULES = {
29 "iPodFactory" : { "type": "dataprovider-factory" }
30 }
31
32 try:
33 import gpod
34 LIBGPOD_PHOTOS = gpod.version_info >= (0,6,0)
35 log.info("Module Information: %s" % Utils.get_module_information(gpod, 'version_info'))
36 except ImportError:
37 LIBGPOD_PHOTOS = False
38 log.info("iPod photo support disabled")
39
41 for i in range(1, 10000):
42 filename = prefix + str(i) + postfix
43 uri = os.path.join(base_uri, filename)
44 f = File.File(uri)
45 if not f.exists():
46 break
47
48 temp = Utils.new_tempfile(txt)
49 temp.transfer(uri, True)
50 temp.set_UID(filename)
51 return temp.get_rid()
52
55 if props.has_key("info.parent") and props.has_key("info.parent")!="":
56 prop2 = self._get_properties(props["info.parent"])
57 if prop2.has_key("storage.model") and prop2["storage.model"]=="iPod":
58 return True
59 return False
60
66
79
80
87
89 DataProvider.TwoWay.refresh(self)
90 self.objects = []
91
92
93 if not os.path.exists(self.dataDir):
94 os.mkdir(self.dataDir)
95
96
97
98 for f in os.listdir(self.dataDir):
99 fullpath = os.path.join(self.dataDir, f)
100 if os.path.isfile(fullpath):
101 self.objects.append(f)
102
106
111
112 - def finish(self, aborted, error, conflict):
115
118
120 """
121 Returns the name of a non-existant file on the
122 ipod within directory
123
124 @param directory: Name of the directory within the device root to make
125 the random file in
126 """
127 done = False
128 while not done:
129 f = os.path.join(self.mountPoint,directory,Utils.random_string())
130 if not os.path.exists(f):
131 done = True
132 return f
133
135 """
136 Stores Notes on the iPod.
137 Rather than requiring a perfect transform to and from notes to the
138 ipod note format I also store the original note data in a
139 .conduit directory in the root of the iPod.
140
141 Notes are saved as title.txt and a copy of the raw note is saved as
142 title.note
143
144 LUID is the note title
145 """
146
147 _name_ = "Notes"
148 _description_ = "Sync your iPod notes"
149