]>
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
18 notes
= NotesToMyself()
21 noteListF
[noteList
.index(note
)]()
25 print "An error occurred during one of the automatic data update routines. Please report this bug."
31 pre
= os
.path
.abspath(config
.spooldir
) + "/" + config
.jid
+ "/"
32 self
.filename
= pre
+ "/notes_to_myself"
35 if os
.path
.exists(self
.filename
):
36 f
= open(self
.filename
, "r")
37 self
.notes
= [x
.strip() for x
in f
.readlines()]
39 elif not os
.path
.exists(pre
):
44 def check(self
, note
):
45 return self
.notes
.count(note
) == 0
47 def append(self
, note
):
49 self
.notes
.append(note
)
52 f
= open(self
.filename
, "w")
53 for note
in self
.notes
:
59 def doSpoolPrepCheck():
60 pre
= os
.path
.abspath(config
.spooldir
) + "/" + config
.jid
+ "/"
62 print "Checking spool files and stringprepping any if necessary...",
64 for file in os
.listdir(pre
):
66 file = xdb
.unmangle(file).decode("utf-8")
67 filej
= utils
.jid(file).full()
69 file = xdb
.mangle(file)
70 filej
= xdb
.mangle(filej
)
71 if(os
.path
.exists(filej
)):
72 print "Need to move", file, "to", filej
, "but the latter exists!\nAborting!"
75 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
):
90 if os
.path
.isfile(pre
+ file):
91 pre2
= pre
+ file[0:3] + "/"
92 if not os
.path
.exists(pre2
):
94 shutil
.move(pre
+ file, pre2
+ file)
100 pre
= os
.path
.abspath(config
.spooldir
) + "/" + config
.jid
+ "/"
101 if os
.path
.exists(pre
):
102 for file in os
.listdir(pre
):
104 if os
.path
.isfile(pre
+ file) and file != "notes_to_myself":
106 pre2
= pre
+ hash + "/"
107 if not os
.path
.exists(pre2
):
110 if(os
.path
.exists(pre2
+ file)):
111 print "Need to move", file, "to", pre2
+ file, "but the latter exists!\nAborting!"
114 shutil
.move(pre
+ file, pre2
+ file)
116 print "File: " + file
122 noteList
= ["doSpoolPrepCheck", "doHashDirUpgrade"]
123 noteListF
= [doSpoolPrepCheck
, doHashDirUpgrade
]