]>
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 if not os
.path
.isfile(file):
73 file = xdb
.unmangle(file).decode("utf-8")
74 filej
= xmlw
.jid
.intern(file).full()
76 file = xdb
.mangle(file)
77 filej
= xdb
.mangle(filej
)
78 if(os
.path
.exists(filej
)):
79 print "Need to move", file, "to", filej
, "but the latter exists!\nAborting!"
82 shutil
.move(pre
+ file, pre
+ filej
)
89 def doHashDirUpgrade():
90 print "Upgrading your XDB structure to use hashed directories for speed...",
93 pre
= os
.path
.join(os
.path
.abspath(config
.spooldir
), config
.jid
) + X
+ "avatars" + X
94 if os
.path
.exists(pre
):
95 for file in os
.listdir(pre
):
97 if os
.path
.isfile(pre
+ file):
98 pre2
= pre
+ file[0:3] + X
99 if not os
.path
.exists(pre2
):
101 shutil
.move(pre
+ file, pre2
+ file)
103 print "File: " + file
107 pre
= os
.path
.join(os
.path
.abspath(config
.spooldir
), config
.jid
) + X
108 if os
.path
.exists(pre
):
109 for file in os
.listdir(pre
):
111 if os
.path
.isfile(pre
+ file) and file != "notes_to_myself":
113 pre2
= pre
+ hash + X
114 if not os
.path
.exists(pre2
):
117 if(os
.path
.exists(pre2
+ file)):
118 print "Need to move", file, "to", pre2
+ file, "but the latter exists!\nAborting!"
121 shutil
.move(pre
+ file, pre2
+ file)
123 print "File: " + file
129 noteList
= ["doSpoolPrepCheck", "doHashDirUpgrade"]
130 noteListF
= [doSpoolPrepCheck
, doHashDirUpgrade
]