personal document mgmt system idea
Sandy Norton
sandskyfly at hotmail.com
Wed Jan 21 05:01:29 EST 2004
John Roth wrote :
> I wouldn't put the individual files in a data base - that's what
> file systems are for. The exception is small files (and by the
> time you say ".doc" in MS Word, it's now longer a small
> file) where you can save substantial space by consolidating
> them.
There seems to be consensus that I shouldn't store files in the
database. This makes sense as filesystems seem to be optimized for,
um, files (-;
As I want to get away from deeply nested directories, I'm going to
test two approaches:
1. store everything in a single folder and hash each file name to give
a unique id
2. create a directory structure based upon a calendar year and store
the daily downloads automatically.
I can finally use some code I'd written before for something like this
purpose:
<code>
from pprint import pprint
import os
import calendar
class Calendirs:
months = {
1 : 'January',
2 : 'February',
3 : 'March',
4 : 'April',
5 : 'May',
6 : 'June',
7 : 'July',
8 : 'August',
9 : 'September',
10 : 'October',
11 : 'November',
12 : 'December'
}
wkdays = {
0 : 'Monday',
1 : 'Tuesday',
2 : 'Wednesday',
3 : 'Thursday',
4 : 'Friday',
5 : 'Saturday',
6 : 'Sunday'
}
def __init__(self, year):
self.year = year
def calendir(self):
'''returns list of calendar matrices'''
mc = calendar.monthcalendar
cal = [(self.year, m) for m in range(1,13)]
return [mc(y,m) for (y, m) in cal]
def yearList(self):
res=[]
weekday = calendar.weekday
m = 0
for month in self.calendir():
lst = []
m += 1
for week in month:
for day in week:
if day:
day_str = Calendirs.wkdays[weekday(self.year,
m, day)]
lst.append( (str(m)+'.'+Calendirs.months[m],
str(day)+'.'+day_str) )
res.append(lst)
return res
def make(self):
for month in self.yearList():
for m, day in month:
path = os.path.join(str(self.year), m, day)
os.makedirs(path)
Calendirs(2004).make()
</code>
I don't know which method will perform better or be more usable...
testing testing testing.
regards,
Sandy
More information about the Python-list
mailing list