]>
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
7 if(utils
.checkTwisted()):
8 from twisted
.words
.protocols
.jabber
import jid
10 from tlib
.jabber
import jid
22 notes
= NotesToMyself()
25 noteListF
[noteList
.index(note
)]()
29 print "An error occurred during one of the automatic data update routines. Please report this bug."
35 pre
= os
.path
.abspath(config
.spooldir
) + "/" + config
.jid
+ "/"
36 self
.filename
= pre
+ "/notes_to_myself"
39 if os
.path
.exists(self
.filename
):
40 f
= open(self
.filename
, "r")
41 self
.notes
= [x
.strip() for x
in f
.readlines()]
43 elif not os
.path
.exists(pre
):
48 def check(self
, note
):
49 return self
.notes
.count(note
) == 0
51 def append(self
, note
):
53 self
.notes
.append(note
)
56 f
= open(self
.filename
, "w")
57 for note
in self
.notes
:
63 def doSpoolPrepCheck():
64 pre
= os
.path
.abspath(config
.spooldir
) + "/" + config
.jid
+ "/"
66 print "Checking spool files and stringprepping any if necessary...",
68 for file in os
.listdir(pre
):
70 file = xdb
.unmangle(file).decode("utf-8")
71 filej
= jid
.JID(file).full()
73 file = xdb
.mangle(file)
74 filej
= xdb
.mangle(filej
)
75 if(os
.path
.exists(filej
)):
76 print "Need to move", file, "to", filej
, "but the latter exists!\nAborting!"
79 shutil
.move(pre
+ file, pre
+ filej
)
86 def doHashDirUpgrade():
87 print "Upgrading your XDB structure to use hashed directories for speed...",
90 pre
= os
.path
.abspath(config
.spooldir
) + "/" + config
.jid
+ "/avatars/"
91 if os
.path
.exists(pre
):
92 for file in os
.listdir(pre
):
94 if os
.path
.isfile(pre
+ file):
95 pre2
= pre
+ file[0:3] + "/"
96 if not os
.path
.exists(pre2
):
98 shutil
.move(pre
+ file, pre2
+ file)
100 print "File: " + file
104 pre
= os
.path
.abspath(config
.spooldir
) + "/" + config
.jid
+ "/"
105 if os
.path
.exists(pre
):
106 for file in os
.listdir(pre
):
108 if os
.path
.isfile(pre
+ file) and file != "notes_to_myself":
110 pre2
= pre
+ hash + "/"
111 if not os
.path
.exists(pre2
):
114 if(os
.path
.exists(pre2
+ file)):
115 print "Need to move", file, "to", pre2
+ file, "but the latter exists!\nAborting!"
118 shutil
.move(pre
+ file, pre2
+ file)
120 print "File: " + file
126 noteList
= ["doSpoolPrepCheck", "doHashDirUpgrade"]
127 noteListF
= [doSpoolPrepCheck
, doHashDirUpgrade
]