]>
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
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
) + X
+ config
.jid
+ X
36 self
.filename
= pre
+ X
+ "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()]
44 if not os
.path
.exists(pre
):
49 def check(self
, note
):
50 return self
.notes
.count(note
) == 0
52 def append(self
, note
):
54 self
.notes
.append(note
)
57 f
= open(self
.filename
, "w")
58 for note
in self
.notes
:
64 def doSpoolPrepCheck():
65 pre
= os
.path
.abspath(config
.spooldir
) + X
+ config
.jid
+ X
67 print "Checking spool files and stringprepping any if necessary...",
69 for file in os
.listdir(pre
):
71 file = xdb
.unmangle(file).decode("utf-8")
72 filej
= xmlw
.jid
.intern(file).full()
74 file = xdb
.mangle(file)
75 filej
= xdb
.mangle(filej
)
76 if(os
.path
.exists(filej
)):
77 print "Need to move", file, "to", filej
, "but the latter exists!\nAborting!"
80 shutil
.move(pre
+ file, pre
+ filej
)
87 def doHashDirUpgrade():
88 print "Upgrading your XDB structure to use hashed directories for speed...",
91 pre
= os
.path
.join(os
.path
.abspath(config
.spooldir
), config
.jid
) + X
+ "avatars" + X
92 if os
.path
.exists(pre
):
93 for file in os
.listdir(pre
):
95 if os
.path
.isfile(pre
+ file):
96 pre2
= pre
+ file[0:3] + X
97 if not os
.path
.exists(pre2
):
99 shutil
.move(pre
+ file, pre2
+ file)
101 print "File: " + file
105 pre
= os
.path
.join(os
.path
.abspath(config
.spooldir
), config
.jid
) + X
106 if os
.path
.exists(pre
):
107 for file in os
.listdir(pre
):
109 if os
.path
.isfile(pre
+ file) and file != "notes_to_myself":
111 pre2
= pre
+ hash + X
112 if not os
.path
.exists(pre2
):
115 if(os
.path
.exists(pre2
+ file)):
116 print "Need to move", file, "to", pre2
+ file, "but the latter exists!\nAborting!"
119 shutil
.move(pre
+ file, pre2
+ file)
121 print "File: " + file
127 noteList
= ["doSpoolPrepCheck", "doHashDirUpgrade"]
128 noteListF
= [doSpoolPrepCheck
, doHashDirUpgrade
]