]>
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
):
69 file = xdb
.unmangle(file).decode("utf-8")
70 filej
= jid
.JID(file).full()
72 file = xdb
.mangle(file)
73 filej
= xdb
.mangle(filej
)
74 if(os
.path
.exists(filej
)):
75 print "Need to move", file, "to", filej
, "but the latter exists!\nAborting!"
78 shutil
.move(pre
+ file, pre
+ filej
)
82 def doHashDirUpgrade():
83 print "Upgrading your XDB structure to use hashed directories for speed...",
86 pre
= os
.path
.abspath(config
.spooldir
) + "/" + config
.jid
+ "/avatars/"
87 if os
.path
.exists(pre
):
88 for file in os
.listdir(pre
):
89 if os
.path
.isfile(pre
+ file):
90 pre2
= pre
+ file[0:3] + "/"
91 if not os
.path
.exists(pre2
):
93 shutil
.move(pre
+ file, pre2
+ file)
96 pre
= os
.path
.abspath(config
.spooldir
) + "/" + config
.jid
+ "/"
97 if os
.path
.exists(pre
):
98 for file in os
.listdir(pre
):
99 if os
.path
.isfile(pre
+ file) and file != "notes_to_myself":
101 pre2
= pre
+ hash + "/"
102 if not os
.path
.exists(pre2
):
105 if(os
.path
.exists(pre2
+ file)):
106 print "Need to move", file, "to", pre2
+ file, "but the latter exists!\nAborting!"
109 shutil
.move(pre
+ file, pre2
+ file)
115 noteList
= ["doSpoolPrepCheck", "doHashDirUpgrade"]
116 noteListF
= [doSpoolPrepCheck
, doHashDirUpgrade
]