]>
code.delx.au - pymsnt/blob - src/housekeep.py
1 # Copyright 2005 James Bunton <james@delx.cjb.net>
2 # Licensed for distribution under the GPL version 2, check COPYING for details
4 from twisted
.words
.protocols
.jabber
.jid
import internJID
23 notes
= NotesToMyself()
26 noteListF
[noteList
.index(note
)]()
30 print "An error occurred during one of the automatic data update routines. Please report this bug."
36 pre
= os
.path
.abspath(config
.spooldir
) + X
+ config
.jid
+ X
37 self
.filename
= pre
+ X
+ "notes_to_myself"
40 if os
.path
.exists(self
.filename
):
41 f
= open(self
.filename
, "r")
42 self
.notes
= [x
.strip() for x
in f
.readlines()]
45 if not os
.path
.exists(pre
):
50 def check(self
, note
):
51 return self
.notes
.count(note
) == 0
53 def append(self
, note
):
55 self
.notes
.append(note
)
58 f
= open(self
.filename
, "w")
59 for note
in self
.notes
:
65 def doSpoolPrepCheck():
66 pre
= os
.path
.abspath(config
.spooldir
) + X
+ config
.jid
+ X
68 print "Checking spool files and stringprepping any if necessary...",
70 for file in os
.listdir(pre
):
72 if not os
.path
.isfile(file):
74 file = xdb
.unmangle(file).decode("utf-8")
75 filej
= internJID(file).full()
77 file = xdb
.mangle(file)
78 filej
= xdb
.mangle(filej
)
79 if(os
.path
.exists(filej
)):
80 print "Need to move", file, "to", filej
, "but the latter exists!\nAborting!"
83 shutil
.move(pre
+ file, pre
+ filej
)
90 def doHashDirUpgrade():
91 print "Upgrading your XDB structure to use hashed directories for speed...",
94 pre
= os
.path
.join(os
.path
.abspath(config
.spooldir
), config
.jid
) + X
+ "avatars" + X
95 if os
.path
.exists(pre
):
96 for file in os
.listdir(pre
):
98 if os
.path
.isfile(pre
+ file):
99 pre2
= pre
+ file[0:3] + X
100 if not os
.path
.exists(pre2
):
102 shutil
.move(pre
+ file, pre2
+ file)
104 print "File: " + file
108 pre
= os
.path
.join(os
.path
.abspath(config
.spooldir
), config
.jid
) + X
109 if os
.path
.exists(pre
):
110 for file in os
.listdir(pre
):
112 if os
.path
.isfile(pre
+ file) and file != "notes_to_myself":
114 pre2
= pre
+ hash + X
115 if not os
.path
.exists(pre2
):
118 if(os
.path
.exists(pre2
+ file)):
119 print "Need to move", file, "to", pre2
+ file, "but the latter exists!\nAborting!"
122 shutil
.move(pre
+ file, pre2
+ file)
124 print "File: " + file
129 def doMD5HashDirUpgrade():
130 print "Moving the avatar directory from msn.host.com up to the spool directory."
132 pre
= os
.path
.join(os
.path
.abspath(config
.spooldir
), config
.jid
) + X
133 if os
.path
.exists(pre
+ "avatars"):
134 # Remove the avatars dir that gets created when we import
135 # legacy/glue.py (it only contains the defaultAvatar)
136 shutil
.rmtree(os
.path
.join(config
.spooldir
, "avatars"))
137 shutil
.move(pre
+ "avatars", os
.path
.join(config
.spooldir
, "avatars"))
139 print "Could not move your cached avatars directory automatically. It is safe to delete it, the avatars will be recreated as necessary."
142 print "Upgrading your spool directory to use md5 hashes."
144 dirlist
= os
.listdir(pre
)
145 dir, hash, file = "","",""
148 if not os
.path
.isdir(pre
+ dir) or dir == "avatars" or len(dir) == 3:
151 for file in os
.listdir(pre2
):
152 if not os
.path
.isfile(pre2
+ file):
154 hash = xdb
.makeHash(os
.path
.splitext(file)[0])
155 if not os
.path
.exists(pre
+ hash):
156 os
.makedirs(pre
+ hash)
157 shutil
.move(pre2
+ file, pre
+ hash + X
+ file)
160 print "Error in migration", pre
, dir, hash, file, str(e
)
165 noteList
= ["doSpoolPrepCheck", "doHashDirUpgrade", "doMD5HashDirUpgrade"]
166 noteListF
= [doSpoolPrepCheck
, doHashDirUpgrade
, doMD5HashDirUpgrade
]