]>
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
20 notes
= NotesToMyself()
23 noteListF
[noteList
.index(note
)]()
27 print "An error occurred during one of the automatic data update routines. Please report this bug."
33 pre
= os
.path
.abspath(config
.spooldir
) + "/" + config
.jid
+ "/"
34 self
.filename
= pre
+ "/notes_to_myself"
37 if os
.path
.exists(self
.filename
):
38 f
= open(self
.filename
, "r")
39 self
.notes
= [x
.strip() for x
in f
.readlines()]
42 if not os
.path
.exists(pre
):
47 def check(self
, note
):
48 return self
.notes
.count(note
) == 0
50 def append(self
, note
):
52 self
.notes
.append(note
)
55 f
= open(self
.filename
, "w")
56 for note
in self
.notes
:
62 def doSpoolPrepCheck():
63 pre
= os
.path
.abspath(config
.spooldir
) + "/" + config
.jid
+ "/"
65 print "Checking spool files and stringprepping any if necessary...",
67 for file in os
.listdir(pre
):
69 file = xdb
.unmangle(file).decode("utf-8")
70 filej
= xmlw
.jid
.intern(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
)
85 def doHashDirUpgrade():
86 print "Upgrading your XDB structure to use hashed directories for speed...",
89 pre
= os
.path
.abspath(config
.spooldir
) + "/" + config
.jid
+ "/avatars/"
90 if os
.path
.exists(pre
):
91 for file in os
.listdir(pre
):
93 if os
.path
.isfile(pre
+ file):
94 pre2
= pre
+ file[0:3] + "/"
95 if not os
.path
.exists(pre2
):
97 shutil
.move(pre
+ file, pre2
+ file)
103 pre
= os
.path
.abspath(config
.spooldir
) + "/" + config
.jid
+ "/"
104 if os
.path
.exists(pre
):
105 for file in os
.listdir(pre
):
107 if os
.path
.isfile(pre
+ file) and file != "notes_to_myself":
109 pre2
= pre
+ hash + "/"
110 if not os
.path
.exists(pre2
):
113 if(os
.path
.exists(pre2
+ file)):
114 print "Need to move", file, "to", pre2
+ file, "but the latter exists!\nAborting!"
117 shutil
.move(pre
+ file, pre2
+ file)
119 print "File: " + file
125 noteList
= ["doSpoolPrepCheck", "doHashDirUpgrade"]
126 noteListF
= [doSpoolPrepCheck
, doHashDirUpgrade
]