disc cataloging for XP

Moderator: MOD_nyhetsgrupper

Svar
singhals

disc cataloging for XP

Legg inn av singhals » 27. november 2006 kl. 17.07

I have an old DOS program called Disc Catalog.

Is there anything similar I can use with XP?

Cheryl

Hugh Watkins

Re: disc cataloging for XP

Legg inn av Hugh Watkins » 27. november 2006 kl. 18.18

singhals wrote:
I have an old DOS program called Disc Catalog.

Is there anything similar I can use with XP?

get the google packages
http://pack.google.com/intl/en/pack_ins ... l=en&gl=us

freebies

desktop search
and
for images Picasa

see
http://googleblog.blogspot.com/2006/01/ ... -work.html

enjoy

Hugh W



--

Beta blogger
http://nanowrimo3.blogspot.com/ visiting my past
http://hughw36-2.blogspot.com/ re-entry
http://snaps4.blogspot.com/" photographs and walks

old blogger
http://hughw36.blogspot.com/ MAIN BLOG

Dennis Lee Bieber

Re: disc cataloging for XP

Legg inn av Dennis Lee Bieber » 27. november 2006 kl. 19.23

On Mon, 27 Nov 2006 11:07:02 -0500, singhals <singhals@erols.com>
declaimed the following in soc.genealogy.computing:

I have an old DOS program called Disc Catalog.

Is there anything similar I can use with XP?

Describe the functions it performed... (printed reports? live

search? label generation? how was input managed?)

{Simple listings of the contents of floppies weren't difficult in
the old days, but who uses floppies regularly these days? CD-R is
getting too small for some data storage -- my /incremental/ /compressed/
backups require multiple DVD-R... And a catalog of 20GB of stuff might
not be all that useful as a single entity.}
--
bieber.genealogy Dennis Lee Bieber
HTTP://home.earthlink.net/~bieber.genealogy/

singhals

Re: disc cataloging for XP

Legg inn av singhals » 27. november 2006 kl. 20.11

Dennis Lee Bieber wrote:

On Mon, 27 Nov 2006 11:07:02 -0500, singhals <singhals@erols.com
declaimed the following in soc.genealogy.computing:


I have an old DOS program called Disc Catalog.

Is there anything similar I can use with XP?


Describe the functions it performed... (printed reports? live
search? label generation? how was input managed?)


INPUT: I fired up the program (by typing catdisc), stuck a
floppy into A: and hit ENTER. The program read the
vol-label, and the file data (name, size, type, date) and
saved it internally on the HD. I provided the vol-num,
which was a simple sequential based on which disc I picked
up next; the same vol-num was hand-entered on a sticky dot
pasted to the disc.

SEARCHES: I could later SEARCH for a file name or type or
date or by vol-label. I never got around to printed reports
and don't actually know if it made any!

{Simple listings of the contents of floppies weren't difficult in
the old days, but who uses floppies regularly these days? CD-R is
getting too small for some data storage -- my /incremental/ /compressed/
backups require multiple DVD-R... And a catalog of 20GB of stuff might
not be all that useful as a single entity.}

Yeah, but I've got 200 or 300 floppies in that catalog; Some
sort of [now, Dennis, don't go and faint!] *organization*
when I dump them onto DVD might be useful? (g)

I am also aware that many of those DOS programs won't run
under XP, which is fine; I just need to know which disc to
pull to use on the laptop that runs DOS.

Cheryl

tim sewell

Re: disc cataloging for XP

Legg inn av tim sewell » 28. november 2006 kl. 0.54

"singhals" <singhals@erols.com> wrote in message
news:IOadnVjdBL24kPbYnZ2dnUVZ_qCdnZ2d@rcn.net...
I have an old DOS program called Disc Catalog.

Is there anything similar I can use with XP?

My son speaks highly of Broken-Cross. He has used it to catalogue ALL
of his CDs and DVDs (at a rough guess, about 300 of them!).

http://bcdm.broken-cross.com/?Lang=enu

Cheers,
--
Tim S.

(Please remove my fairly obvious spamtrap
if you wish to reply by direct email)

Dennis Lee Bieber

Re: disc cataloging for XP

Legg inn av Dennis Lee Bieber » 28. november 2006 kl. 9.29

On Mon, 27 Nov 2006 14:11:43 -0500, singhals <singhals@erols.com>
declaimed the following in soc.genealogy.computing:


INPUT: I fired up the program (by typing catdisc), stuck a
floppy into A: and hit ENTER. The program read the
vol-label, and the file data (name, size, type, date) and
saved it internally on the HD. I provided the vol-num,
which was a simple sequential based on which disc I picked
up next; the same vol-num was hand-entered on a sticky dot
pasted to the disc.

SEARCHES: I could later SEARCH for a file name or type or
date or by vol-label. I never got around to printed reports
and don't actually know if it made any!

Given that simple level, I'd probably "roll-my-own" using Python and

SQLite3. I'd normally prefer to let the database assign the disk number
for each disk added, but presuming one already has numbered disks...
<eh>

Yeah, but I've got 200 or 300 floppies in that catalog; Some
sort of [now, Dennis, don't go and faint!] *organization*
when I dump them onto DVD might be useful? (g)

300 floppies at 1.44MB each is less than 500MB -- they'd all fit on

one old-fashioned CD-R <G>. Organization? Well, you could create a
staging directory on hard-drive for the burn, create a subdirectory for
each disk, copy the contents of each floppy to its assigned directory
(use the disk number), then before burning, use a command window to do a
recursive directory of the staging area, directing the output to a file
in the staging area. Searches could be tedious but done with any text
editor <G>.

dir /x/s >list.txt

Heck -- a very quick and dirty piece of Python (no query/report or
error handling; and the presence of win32api implies it runs under
Windows)

-=-=-=-=-=-=-
from pysqlite2 import dbapi2 as db
import os
import stat
import win32api

cxn = None

def initDB():
global cxn
database = os.path.join(os.environ["USERPROFILE"],
"Application Data",
"pydiskcat.db")
newDB = not os.path.exists(database)
cxn = db.connect(database)
if newDB:
print "Creating new database file: %s" % database
crs = cxn.cursor()
crs.execute("""create table disk (
ID integer primary key,
userNum integer,
volName character,
volSerial integer )""")
crs.execute("""create table file (
ID integer primary key,
volID integer,
fileName character,
filePath character,
date integer,
size integer )""")
crs.close()
cxn.commit()


def finalizeDB():
global cxn
cxn.commit() #precautionary commit
cxn.close()

def scanDisk(drive):
global cxn
drive = drive + ":\\"
raw_input("Place disk into drive %s and press <enter>" % drive)
(vName, vSerial, vMax, vFlags, vFS) =
win32api.GetVolumeInformation(drive)
crs = cxn.cursor()
crs.execute("""select ID, userNum, volName, volSerial from disk
where volName = ? or volSerial = ? """,
(vName, vSerial) )
disks = crs.fetchall()
ans = "a"
if disks:
print "\n***\tVolume name and/or serial number already in
use\t***"
print "User Number Name Serial"
for (id, un, vn, vs) in disks:
print "%11d %-20s%d" % (un, vn, vs)
ans = raw_input("R)eplace all, A)ppend, S)kip: ").lower()[0]
if ans == "r":
print "Deleting old file entries"
for disk in disks:
crs.execute("""delete from file
where volID = ?""",
(disk[0],))
print "Deleting old disk entries"
crs.execute("""delete from disk
where volName = ? or volSerial = ?""",
(vName, vSerial))
if ans == "a" or ans == "r":
userNum = int(raw_input("User Number to assign to this disk? "))
crs.execute("""insert into disk (userNum, volName, volSerial)
values (?, ?, ?)""",
(userNum, vName, vSerial))
crs.execute("select last_insert_rowid()")
volID = crs.fetchone()[0]
print "Scanning files"
fileList = []
for (rt, dirs, fns) in os.walk(drive):
for f in fns:
fpath = os.path.join(rt, f)
st = os.stat(fpath)
fileList.append((volID, f, rt, st[stat.ST_MTIME],
st[stat.ST_SIZE]))
print "Inserting %s file records" % len(fileList)
crs.executemany("""insert into file (volID, fileName, filePath,
date, size)
values (?, ?, ?, ?, ?)""",
fileList)
else:
print "Skipping current disk"
crs.close()
cxn.commit()


def queryDatabase():
print "\n\n***\tNOT IMPLEMENTED YET\t***\n\n"


if __name__ == "__main__":

initDB() #initialize database (define tables if needed)

driveLetter = None #determine the drive to be used
while not driveLetter:
driveLetter = raw_input("Specify floppy drive letter:
").upper()[0]

while True: #main processing
option = raw_input("S)can disk, Q)uery database, E)xit:
").lower()
if option[0] == "s":
scanDisk(driveLetter)
elif option[0] == "q":
queryDatabase()
elif option[0] == "e":
if raw_input("Confirm exit (y/N): ").lower()[0] == "y":
break #exit
else:
print "\n***\tUnrecognized option, please try again\t***\n"

finalizeDB()
-=-=-=-=-=-=-=-
Creating new database file: C:\Documents and Settings\Dennis Lee
Bieber\Application Data\pydiskcat.db
Specify floppy drive letter: a
S)can disk, Q)uery database, E)xit: s
Place disk into drive A:\ and press <enter>
User Number to assign to this disk? 123
Scanning files
Inserting 6 file records
S)can disk, Q)uery database, E)xit: s
Place disk into drive A:\ and press <enter>

*** Volume name and/or serial number already in use ***
User Number Name Serial
123 NONESUCH 2091609331
R)eplace all, A)ppend, S)kip: r
Deleting old file entries
Deleting old disk entries
User Number to assign to this disk? 332
Scanning files
Inserting 6 file records
S)can disk, Q)uery database, E)xit: e
Confirm exit (y/N): y
-=-=-=-=-=-=-=-
C:\Documents and Settings\Dennis Lee Bieber\Application Data>sqlite3
pydiskcat.db
SQLite version 3.3.8
Enter ".help" for instructions
sqlite> .schema
CREATE TABLE disk (
ID integer primary key,
userNum integer,
volName character,
volSerial integer );
CREATE TABLE file (
ID integer primary key,
volID integer,
fileName character,
filePath character,
date integer,
size integer );
sqlite> .mode col
sqlite> .headers on
sqlite> select * from disk;
ID userNum volName volSerial
---------- ---------- ---------- ----------
1 332 NONESUCH 2091609331
sqlite> select * from file;
ID volID fileName filePath date size
---------- ---------- --------------------- ---------- ----------
----------
1 1 Blue Ball Machine.htm A:\ 1131599128
24867
2 1 blank.htm A:\Blue Ba 1131599128
203
3 1 image.gif A:\Blue Ba 1138170598
856385
4 1 js.js A:\Blue Ba 1131599128
1357
5 1 stars_red_45.png A:\Blue Ba 1131599128
354
6 1 votebar.js A:\Blue Ba 1131599128
9943
sqlite> .mode tabs
sqlite> select * from file;
ID volID fileName filePath date size
1 1 Blue Ball Machine.htm A:\ 1131599128 24867
2 1 blank.htm A:\Blue Ball Machine_files 1131599128
203
3 1 image.gif A:\Blue Ball Machine_files 1138170598
856385
4 1 js.js A:\Blue Ball Machine_files 1131599128 1357
5 1 stars_red_45.png A:\Blue Ball Machine_files
1131599128 354
6 1 votebar.js A:\Blue Ball Machine_files 1131599128
9943
sqlite>
--
bieber.genealogy Dennis Lee Bieber
HTTP://home.earthlink.net/~bieber.genealogy/

singhals

Re: disc cataloging for XP

Legg inn av singhals » 28. november 2006 kl. 17.07

Dennis Lee Bieber wrote:

On Mon, 27 Nov 2006 14:11:43 -0500, singhals <singhals@erols.com
declaimed the following in soc.genealogy.computing:



INPUT: I fired up the program (by typing catdisc), stuck a
floppy into A: and hit ENTER. The program read the
vol-label, and the file data (name, size, type, date) and
saved it internally on the HD. I provided the vol-num,
which was a simple sequential based on which disc I picked
up next; the same vol-num was hand-entered on a sticky dot
pasted to the disc.

SEARCHES: I could later SEARCH for a file name or type or
date or by vol-label. I never got around to printed reports
and don't actually know if it made any!


Given that simple level, I'd probably "roll-my-own" using Python and
SQLite3. I'd normally prefer to let the database assign the disk number
for each disk added, but presuming one already has numbered disks...
eh

Yeah, but I've got 200 or 300 floppies in that catalog; Some
sort of [now, Dennis, don't go and faint!] *organization*
when I dump them onto DVD might be useful? (g)


300 floppies at 1.44MB each is less than 500MB -- they'd all fit on
one old-fashioned CD-R <G>. Organization? Well, you could create a
staging directory on hard-drive for the burn, create a subdirectory for
each disk, copy the contents of each floppy to its assigned directory
(use the disk number), then before burning, use a command window to do a
recursive directory of the staging area, directing the output to a file
in the staging area. Searches could be tedious but done with any text
editor <G>.

dir /x/s >list.txt

Heck -- a very quick and dirty piece of Python (no query/report or
error handling; and the presence of win32api implies it runs under
Windows)

-=-=-=-=-=-=-
from pysqlite2 import dbapi2 as db
import os
import stat
import win32api

cxn = None

def initDB():
global cxn
database = os.path.join(os.environ["USERPROFILE"],
"Application Data",
"pydiskcat.db")
newDB = not os.path.exists(database)
cxn = db.connect(database)
if newDB:
print "Creating new database file: %s" % database
crs = cxn.cursor()
crs.execute("""create table disk (
ID integer primary key,
userNum integer,
volName character,
volSerial integer )""")
crs.execute("""create table file (
ID integer primary key,
volID integer,
fileName character,
filePath character,
date integer,
size integer )""")
crs.close()
cxn.commit()


def finalizeDB():
global cxn
cxn.commit() #precautionary commit
cxn.close()

def scanDisk(drive):
global cxn
drive = drive + ":\\"
raw_input("Place disk into drive %s and press <enter>" % drive)
(vName, vSerial, vMax, vFlags, vFS) =
win32api.GetVolumeInformation(drive)
crs = cxn.cursor()
crs.execute("""select ID, userNum, volName, volSerial from disk
where volName = ? or volSerial = ? """,
(vName, vSerial) )
disks = crs.fetchall()
ans = "a"
if disks:
print "\n***\tVolume name and/or serial number already in
use\t***"
print "User Number Name Serial"
for (id, un, vn, vs) in disks:
print "%11d %-20s%d" % (un, vn, vs)
ans = raw_input("R)eplace all, A)ppend, S)kip: ").lower()[0]
if ans == "r":
print "Deleting old file entries"
for disk in disks:
crs.execute("""delete from file
where volID = ?""",
(disk[0],))
print "Deleting old disk entries"
crs.execute("""delete from disk
where volName = ? or volSerial = ?""",
(vName, vSerial))
if ans == "a" or ans == "r":
userNum = int(raw_input("User Number to assign to this disk? "))
crs.execute("""insert into disk (userNum, volName, volSerial)
values (?, ?, ?)""",
(userNum, vName, vSerial))
crs.execute("select last_insert_rowid()")
volID = crs.fetchone()[0]
print "Scanning files"
fileList = []
for (rt, dirs, fns) in os.walk(drive):
for f in fns:
fpath = os.path.join(rt, f)
st = os.stat(fpath)
fileList.append((volID, f, rt, st[stat.ST_MTIME],
st[stat.ST_SIZE]))
print "Inserting %s file records" % len(fileList)
crs.executemany("""insert into file (volID, fileName, filePath,
date, size)
values (?, ?, ?, ?, ?)""",
fileList)
else:
print "Skipping current disk"
crs.close()
cxn.commit()


def queryDatabase():
print "\n\n***\tNOT IMPLEMENTED YET\t***\n\n"


if __name__ == "__main__":

initDB() #initialize database (define tables if needed)

driveLetter = None #determine the drive to be used
while not driveLetter:
driveLetter = raw_input("Specify floppy drive letter:
").upper()[0]

while True: #main processing
option = raw_input("S)can disk, Q)uery database, E)xit:
").lower()
if option[0] == "s":
scanDisk(driveLetter)
elif option[0] == "q":
queryDatabase()
elif option[0] == "e":
if raw_input("Confirm exit (y/N): ").lower()[0] == "y":
break #exit
else:
print "\n***\tUnrecognized option, please try again\t***\n"

finalizeDB()
-=-=-=-=-=-=-=-
Creating new database file: C:\Documents and Settings\Dennis Lee
Bieber\Application Data\pydiskcat.db
Specify floppy drive letter: a
S)can disk, Q)uery database, E)xit: s
Place disk into drive A:\ and press <enter
User Number to assign to this disk? 123
Scanning files
Inserting 6 file records
S)can disk, Q)uery database, E)xit: s
Place disk into drive A:\ and press <enter

*** Volume name and/or serial number already in use ***
User Number Name Serial
123 NONESUCH 2091609331
R)eplace all, A)ppend, S)kip: r
Deleting old file entries
Deleting old disk entries
User Number to assign to this disk? 332
Scanning files
Inserting 6 file records
S)can disk, Q)uery database, E)xit: e
Confirm exit (y/N): y
-=-=-=-=-=-=-=-
C:\Documents and Settings\Dennis Lee Bieber\Application Data>sqlite3
pydiskcat.db
SQLite version 3.3.8
Enter ".help" for instructions
sqlite> .schema
CREATE TABLE disk (
ID integer primary key,
userNum integer,
volName character,
volSerial integer );
CREATE TABLE file (
ID integer primary key,
volID integer,
fileName character,
filePath character,
date integer,
size integer );
sqlite> .mode col
sqlite> .headers on
sqlite> select * from disk;
ID userNum volName volSerial
---------- ---------- ---------- ----------
1 332 NONESUCH 2091609331
sqlite> select * from file;
ID volID fileName filePath date size
---------- ---------- --------------------- ---------- ----------
----------
1 1 Blue Ball Machine.htm A:\ 1131599128
24867
2 1 blank.htm A:\Blue Ba 1131599128
203
3 1 image.gif A:\Blue Ba 1138170598
856385
4 1 js.js A:\Blue Ba 1131599128
1357
5 1 stars_red_45.png A:\Blue Ba 1131599128
354
6 1 votebar.js A:\Blue Ba 1131599128
9943
sqlite> .mode tabs
sqlite> select * from file;
ID volID fileName filePath date size
1 1 Blue Ball Machine.htm A:\ 1131599128 24867
2 1 blank.htm A:\Blue Ball Machine_files 1131599128
203
3 1 image.gif A:\Blue Ball Machine_files 1138170598
856385
4 1 js.js A:\Blue Ball Machine_files 1131599128 1357
5 1 stars_red_45.png A:\Blue Ball Machine_files
1131599128 354
6 1 votebar.js A:\Blue Ball Machine_files 1131599128
9943
sqlite


Whooo! Thanks, Dennis, I'll give it a whirl.

Cheryl

singhals

Re: disc cataloging for XP

Legg inn av singhals » 28. november 2006 kl. 17.07

tim sewell wrote:

"singhals" <singhals@erols.com> wrote in message
news:IOadnVjdBL24kPbYnZ2dnUVZ_qCdnZ2d@rcn.net...

I have an old DOS program called Disc Catalog.

Is there anything similar I can use with XP?


My son speaks highly of Broken-Cross. He has used it to catalogue ALL
of his CDs and DVDs (at a rough guess, about 300 of them!).

http://bcdm.broken-cross.com/?Lang=enu

Thanks, Tim, I'll have a look-see.

Cheryl

john

Re: disc cataloging for XP

Legg inn av john » 28. november 2006 kl. 17.27

singhals wrote:
Dennis Lee Bieber wrote:

On Mon, 27 Nov 2006 11:07:02 -0500, singhals <singhals@erols.com
declaimed the following in soc.genealogy.computing:


I have an old DOS program called Disc Catalog.

Is there anything similar I can use with XP?


Describe the functions it performed... (printed reports? live
search? label generation? how was input managed?)


INPUT: I fired up the program (by typing catdisc), stuck a floppy into
A: and hit ENTER. The program read the vol-label, and the file data
(name, size, type, date) and saved it internally on the HD. I provided
the vol-num, which was a simple sequential based on which disc I picked
up next; the same vol-num was hand-entered on a sticky dot pasted to the
disc.

SEARCHES: I could later SEARCH for a file name or type or date or by
vol-label. I never got around to printed reports and don't actually
know if it made any!

{Simple listings of the contents of floppies weren't difficult in
the old days, but who uses floppies regularly these days? CD-R is
getting too small for some data storage -- my /incremental/ /compressed/
backups require multiple DVD-R... And a catalog of 20GB of stuff might
not be all that useful as a single entity.}

Yeah, but I've got 200 or 300 floppies in that catalog; Some sort of
[now, Dennis, don't go and faint!] *organization* when I dump them onto
DVD might be useful? (g)

I am also aware that many of those DOS programs won't run under XP,
which is fine; I just need to know which disc to pull to use on the
laptop that runs DOS.

Cheryl


You could try Simple Disk Catalog v1.0c
http://201.38.235.5:1080/portal/viewtopic.php?t=25
Has some good use ratings.

Dennis Lee Bieber

Re: disc cataloging for XP

Legg inn av Dennis Lee Bieber » 28. november 2006 kl. 19.03

On Tue, 28 Nov 2006 11:07:39 -0500, singhals <singhals@erols.com>
declaimed the following in soc.genealogy.computing:

Whooo! Thanks, Dennis, I'll give it a whirl.

Remember, I did say it was a quick&dirty job (about two hours

including skimming help files for win32api), primarily to see how
difficult it would be to collect the information. I suspect, given the
initial description, that I should split the extension from the filename
into a separate database column, clean up the formatting of the progress
messages (a few more blank lines to separate prompts from status), and,
of course, add more error handling. Also, I'm only grabbing the
"modification time" -- but could have used creation time, or access
time. Then there is the query side to handle... I'm using the
ActiveState Python 2.4.x, with downloaded pysqlite module (I don't know
if ActiveState has a 2.5.x build yet -- Python 2.5 includes an sqlite3
module as standard).

And I stored the time in internal form -- time.ctime(t) converts to
human readable...
--
bieber.genealogy Dennis Lee Bieber
HTTP://home.earthlink.net/~bieber.genealogy/

Dennis Lee Bieber

WARNING: Long/Source Code! (was: disc cataloging for XP

Legg inn av Dennis Lee Bieber » 29. november 2006 kl. 6.55

On Tue, 28 Nov 2006 11:07:39 -0500, singhals <singhals@erols.com>
declaimed the following in soc.genealogy.computing:



Whooo! Thanks, Dennis, I'll give it a whirl.

Just out of boredom at work (are they watching me? <G>) I tweaked

and added simple query ability...

Watch out for line wrapping... Some commentary at the bottom...

-=-=-=-=-=-=-
"""
DiskCat.py Floppy Disk Cataloging Utility
November 28 2006 dl bieber

While this program does not enforce the cataloging of floppy disks,
permitting the use of any drive letter as the starting root for
cataloging, usage against a hard-drive partition is NOT recommended

"""

import os
import stat
import time
import win32api

from pysqlite2 import dbapi2 as db

class Catalog(object):
def __init__(self):
# locate user's application data directory
database = os.path.join(os.environ["USERPROFILE"],
"Application Data",
"DiskCatalog.db")
# see if the database already exists
newDB = not os.path.exists(database)
# open the database (creates empty file if first time)
self._cxn = db.connect(database)
# initialize the database schema if this is a new file
if newDB:
print "***\tCreating new database:\n\t%s" % database
crs = self._cxn.cursor()
# disk header table
crs.execute("""create table Disk
(
ID integer primary key,
userNumber integer,
volName character,
volSerial integer,
volFS character
) """)
# file information table
crs.execute("""create table File
(
ID integer primary key,
volID integer,
filePath character,
fileName character,
created integer,
modified integer,
size integer
) """)
crs.close()
self._cxn.commit()

def close(self):
# ensure closed connection
self._cxn.commit()
self._cxn.close()

def scanDisk(self, drive):
# ensure drive is ready
junk = raw_input("\nPlace disk into drive %s and press <enter>"
% drive)
# obtain volume information
volume = win32api.GetVolumeInformation(drive)
(vName, vSerial, vMax, vFlags, vFS) = volume
# see if volume name or serial number are already in use
crs = self._cxn.cursor()
crs.execute("""select ID, userNumber, volName, volSerial
from Disk
where volName = ? or volSerial = ?""",
(vName, vSerial))
disks = crs.fetchall() # presume a small number at worst
action = "add" # preset "add" records
# if disks is not empty, we found reused volume names or
serial numbers
if disks:
# header fields
print "\n***\tVolume Name and/or Serial Number are already
in use\n"
print "%11s %1s %-20s %20s %1s" % ("User Number",
"N",
"Name",
"Serial",
"S")
# disk information
for (id, un, vn, vs) in disks:
print "%11s %1s %-20s %20s %1s" % (un,
" *"[vn ==
vName],
vn,
vs,
" *"[vs ==
vSerial])
# get user action: replace will delete previous data (for
all
# listed disks!) and then append new disk data, append
will just
# add a new disk entry (normal behavior -- no conflicts
found),
# skip will take no action with the current disk
ans = raw_input("\nR)eplace all, A)ppend, S)kip disk:
").lower()[0]
if ans == "r": # replace all existing records
# find out how many file records are involved for
confirmation
crs.execute("""select count(*) from File
inner join Disk on Disk.id = File.volID
where volName = ? or volSerial = ?""",
(vName, vSerial))
count = crs.fetchone()[0]
print "***\tThis action will delete data for %s disks
and %s files!" % (len(disks), count)
ans = raw_input("\nConfirm the deletion (y/N):
").lower()[0]
if ans == "y":
# delete file records first
print "\n***\tDeleting file data"
for d in disks:
crs.execute("delete from File where volID = ?",
(d[1],))
print "***\tDeleting disk data"
crs.execute("delete from Disk where volName = ? or
volSerial = ?",
(vName, vSerial))
else:
action = "skip"

# if action is still "add", add records from disk
if action == "add":
userNum = int(raw_input("\nEnter User Number to assign to
this disk: "))
crs.execute("""insert into Disk (userNumber, volName,
volSerial, volFS)
values (?, ?, ?, ?)""",
(userNum, vName, vSerial, vFS))
# get volume ID
crs.execute("select last_insert_rowid()")
volID = crs.fetchone()[0]
# do file scan, in case a hard drive is scanned, use
batches of 100
print "\n***\tScanning for files"
fileList = []
for (rt, dirs, fns) in os.walk(drive):
for f in fns:
fid = os.path.join(rt, f)
st = os.stat(fid)
fileList.append((volID, #disk foreign
key
rt[2:], #path less drive
spec
f, #file name
st[stat.ST_CTIME], #creation time
(internal)
st[stat.ST_MTIME], #modification
time
st[stat.ST_SIZE]))
if len(fileList) == 100:
print "\tInserting batch of 100 file records"
crs.executemany("""insert into File
(volID, filePath, fileName, created,
modified, size)
values (?, ?, ?, ?, ?, ?)""",
fileList)
fileList = []
if len(fileList):
print "\tInserting batch of %s file records" %
len(fileList)
crs.executemany("""insert into File
(volID, filePath, fileName, created, modified, size)
values (?, ?, ?, ?, ?, ?)""",
fileList)
else:
print "\n***\tSkipping current disk"
# close cursor and commit any changes
crs.close()
self._cxn.commit()

def query(self):
crs = self._cxn.cursor()
while True:
# display choices
print """


1)\tFind Disks by disk content
2)\tFind Disks by file content
3)\tFind Files by disk content
4)\tFind Files by file content

E)\tExit Query Module
"""
# get user choice
choice = raw_input("\nSpecify operation choice: ")
if choice and choice.lower()[0] == "e": break
if not choice or not (0 < int(choice) < 5):
print "\n***\tUnrecognized option, please try again\n"
continue # repeat display

choice = int(choice)

if choice in (1, 3):
search = self._diskSelect()
elif choice in (2, 4):
search = self._fileSelect()

if choice in (1, 2):
# output fields
select = ["select distinct userNumber, volName,
volSerial, volFS from Disk"]
if choice == 2:
# search is by file, so need a join
select.append("inner join File on Disk.ID =
File.volID")
select.append("where %s" % search[0])
select.append("order by userNumber, volName")
select = " ".join(select)
# retrieve records
crs.execute(select, search[1])
# display them, paged
lns = 0
format = "%11s %-20s %20s %-10s"
for d in crs:
if (lns % 15) == 0:
print
print format % ( "User Number",
"Volume Name",
"Volume Serial",
"File System" )
print format % ("="*11, "="*20, "="*20, "="*10)
print format % d
lns += 1
if (lns % 15) == 14:
# pause every 15 lines of output
junk = raw_input("\nmore...")

if choice in (3, 4):
# output fields
select = ["select distinct userNumber, fileName,
filePath, created, modified, size from File"]
select.append("inner join Disk on Disk.ID = File.volID")
select.append("where %s" % search[0])
select.append("order by userNumber, fileName, filePath")
select = " ".join(select)
# retrieve records
crs.execute(select, search[1])
# display them, paged
lns = 0
format = "%s\n\t%s\n%6s %-23s\t%-23s %10s"
for (un, fn, fp, crt, mod, sz) in crs:
if (lns % 8) == 0:
print
print format % ( "File Name",
"File Path",
"Disk",
" Created ",
" Modified ",
"Size " )
print "="*78
print format % (fn,
fp,
un,
time.ctime(crt),
time.ctime(mod),
sz)
print
lns += 1
if (lns % 8) == 7:
# pause every 15 lines of output
junk = raw_input("\nmore...")

def _diskSelect(self):
clause = []
terms = []
# collect search terms for disk fields
print """
You will be prompted for each searchable field.
If you do not wish to use that field in a seach, press <enter>.
You must specify a search term to at least one field.
You may specify wildcards by using the % character; for example:
to find any disk whose volume name contains "xyz", use %xyz%
to find any disk whose volume name starts with "a", use a%
Multiple search terms will be taken as term1 OR term2!

"""
while not clause and not terms:
uNum = raw_input("User Number (<enter> to skip): ")
if uNum:
clause.append("userNumber like ?")
terms.append(uNum)
vName = raw_input("Volume Name (<enter> to skip): ")
if vName:
clause.append("volName like ?")
terms.append(vName)
vSerial = raw_input("Volume Serial Number (<enter> to skip):
")
if vSerial:
clause.append("volSerial like ?")
terms.append(vSerial)
vFS = raw_input("Volume File System (<enter> to skip): ")
if vFS:
clause.append("volFS like ?")
terms.append(vFS)
# generate the where clause, and return clause and terms
return (" or ".join(clause), terms)

def _fileSelect(self):
clause = []
terms = []
# collect search terms for disk fields
print """
You will be prompted for each searchable field.
If you do not wish to use that field in a seach, press <enter>.
You must specify a search term to at least one field.
You may specify wildcards by using the % character; for example:
to find any file whose path contains "xyz", use %xyz%
to find any file whose name ends with ".exe", use %.exe
Multiple search terms will be taken as term1 OR term2!

"""
while not clause and not terms:
uNum = raw_input("User Number of disk (<enter> to skip): ")
if uNum:
clause.append("userNumber like ?")
terms.append(uNum)
fPath = raw_input("File Path (<enter> to skip): ")
if fPath:
clause.append("filePath like ?")
terms.append(fPath)
fName = raw_input("File Name (<enter> to skip): ")
if fName:
clause.append("fileName like ?")
terms.append(fName)
fSize = raw_input("File Size Less Than (<enter to skip>): ")
if fSize:
clause.append("size < ?")
terms.append(fSize)
fSize = raw_input("File Size Greater Than (<enter to skip>):
")
if fSize:
clause.append("size > ?")
terms.append(fSize)
# generate the where clause, and return clause and terms
return (" or ".join(clause), terms)

if __name__ == "__main__":
catalog = Catalog()

driveLetter = None
while not driveLetter:
driveLetter = raw_input("\nPlease specify drive letter to use
for scanning: ").upper()[0]

while True:
option = raw_input("\n\nS)can disk, Q)uery Catalog, E)xit:
").lower()[0]
if option == "s":
catalog.scanDisk(driveLetter + ":\\")
elif option == "q":
catalog.query()
elif option == "e":
if raw_input("Confirm exit (y/N): ").lower()[0] == "y":
break
else:
print "\n***\tUnrecognized option, please try again\n"

catalog.close()
-=-=-=-=-=-=-=-

It may not be perfect, still minimal error checking (I'm sort of
relying upon any exception condition to kill the whole program /without/
committing the transaction that was in progress...)

Didn't take too long to, if it didn't skip any, grab the data (31K
files) from an external 120GB drive... And the database was only 6MB...

Should maybe add an option to change the drive used for scanning,
rather than locking that in at the very beginning... And a mod to
determine the highest used "user number", and increment it, if one
leaves that blank during scanning (obviously it should be reported to
the use).
--
bieber.genealogy Dennis Lee Bieber
HTTP://home.earthlink.net/~bieber.genealogy/

Svar

Gå tilbake til «soc.genealogy.computing»