[Tutor] Generators

2007-07-19 Thread Doug Glenn

Greetings all,

Please forgive my instrusion with some simple questions.  I don't have any
formal training in programming so I have to get some guidance to some
terminology from time to time.  What is a generator and what is its purpose?

I am planning on building a DVD catalog utility for Linux in Python, or at
least that is my ultimate goal in starting out.  The only one I have found
is buggy and does not work on my system.  So the only other alternative is
to write one myself.  Because I plan on releasing it with the source when I
get done I would prefer to have it as polished as I can make it :)  I look
dumb enough on my own thank you!

So I may have a quite few questions as I move along regarding databases and
connectivity along with a possible way to mount a CDROM or any other media
as needed either authenticated or unauthenticated depending on the system
settings in the fstable.  Obviously if user is not in there then I will have
to sudo to root to mount the drive in order to read it.  Then we have
sorting.  It doesn;t make sense to toss this into a database willy nilly if
I don't so some sorting on it beforehand by type.  I am open to suggestions.

So thank you all in advance for your time and your patience!
Warm regards,
--
Doug Glenn
FORUM Information Systems, LLC
http://foruminfosystems.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python program design

2007-07-20 Thread Doug Glenn

I have a question on program design.  The program will be a catalog of
portable media (DVD, CD, flash drive, floppy, etc).  I am currently in the
preliminary stages of design and I currently would like to get input on what
the best method would be for initially gathering the data and what format it
should take.

I plan on using the os.walk function to iterate a scan through the media.
This returns a set of three variables in a list that will change each
iteration until the scan completes.

I don't know anything at all about database design or the most efficient
method of gathering the data and then inputing it into the database.  In
order to optimize this part of the design I wanted to get some input from
the masters. It is better to get it right the first time then go back and
fix it later.

Since os.walk will generate a unique set of data each interation through the
directory structure I must append the data from each pass into a 'master'
array or list.  In order to identify the media later I will have to get the
disk label and the disk ID as the primary identifiers for the compiled
data.

Each iteration of the directories on the media I will create a list like
this :
root = current directory being scanned - contains single directory
dirs = subdirectories under the current root - contains names of all
directories
files = filenames - contains all the files in the current working directory.

I need to generate the following additional information on each file during
each interation.
size = size of file
type = file extension

My initial test example is something like this:
import os
from os.path import join, getsize
for root, dirs, files in os.walk(device):  # device name from config file

Then I would need to get the file size (but this is giving me an error at
the moment)
   for name in files:
   s = sum(getsize(join(root, name)
   print s  (syntax error here. I have not figured it out yet. There
are spaces in the path/filename combo)
  (code to parse the file extension here)

Back to the data though, should I create something like these while reading
the media and prior to inserting it into the database?
[disk label, disk id [root[dir[file,size,type, permissions in a
dictionary or tuple? or use a list?

or flat in a dictionary, tuple or list like
[disk label, disk id, root,dir,filename,size,type,permissions]

When it has completed the scan I want to insert it into the database with
the following fields
disk label, disk id, root directory, path, filename, file size, file type,
original file permissions, and comment field.  (Does anyone thing I should
have any other fields? Suggestions welcome)

Thank you in advance.  If this is off topic, please reply off the list and
let me know.
--
Doug Glenn
FORUM Information Systems, LLC
http://foruminfosystems.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python program design

2007-07-24 Thread Doug Glenn

On 7/23/07, Tiger12506 <[EMAIL PROTECTED]> wrote:


The line should be
s = getsize(join(root, name))

which will print the file size for each "name in files"



I got it a bit later. It didn't like me trying to apply it in a print
statement but if I assigned it first and the printed it, no issue.



You may wish to build a dict inside your dict.

{(discID, discLbl): {'dir': '...',
 'filename': '...",
etc.



That was my thinking also. I just don't know enough about databases to know
if I should shove the data raw into the DB or do some sorting first.



I don't know how you want to use it, but keeping the root directory is not
very useful. If you ever want to transfer your files to another computer



If I were cataloging hard drives I would tend to agree.  But this is for
removable media and backups so "anything goes", especially since I would
like to GPL it later and noobs will be using it so I can't make assumptions
on their behavior :)   I may stick everything in a sub directory to help
organize it, but using my CD creator program I just tend to drag and drop
them as I see them.

Thanks for the input!


--
Doug Glenn
FORUM Information Systems, LLC
http://foruminfosystems.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor