Welcome, guest | Sign In | My Account | Store | Cart

If you have ever started a program and never finished it, then you may recognize the code below for what it is: an experiment begun but not completed, meant to allow viewing pictures on a server. It is included here as an exercise for the reader to complete and is committed for archival to be run under Python 2.5 or later versions.

Python, 59 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# INCOMPLETE

from cPickle import dump, load
from os import basename
from os.path import exists, isdir, join
from sys import argv
from Zcgi import *

image_extentions = '.bmp', '.gif', '.jpg', '.png'

def main():
    # Default Settings
    title = 'Image Viewer'
    image = ''
    action = basename(argv[0])
    back = ''
    forward = ''
    hidden = ''
    if dictionary is None:
        # Nothing To Do
        pass
    elif dictionary.had_key('directory'):
        # Something To Do
        if not dictionary.has_key('hidden'):
            # Just Began Viewing
            if isdir(dictionary['directory']):
                # Check For Pickle
                image_pickle = join(dictionary['directory'], 'image.pickle')
                if exists(image_pickle):
                    # Load Directory Listing
                    dir_data = load(file(image_pickle))
                else:
                    # Create Directory Listing
                    dir_data = update_image_pickle(dictionary['directory'])
                    # START HERE
                image = WHAT_TO_DECIDE_HERE
            else:
                # Post Error Message
                dictionary['directory'] = 'No Such Directory'
        else:
            # Find Next Image
    show_form(title, image, action, back, forward, hidden)

def show_form(*form_settings):
    print_html('''<html>
\t<head>
\t\t<title>
\t\t\t%s
\t\t</title>
\t</head>
\t<body>
\t\t<center>%s
\t\t\t<form action="%s">
\t\t\t\t<input type="text" name="directory" size="50"><br>
\t\t\t\t%s<input type="submit" name="browse" value="Browse">%s%s
\t\t\t</form>
\t\t</center>
\t</body>
</html>''' % form_settings)

The Zcgi module can be found in recipe 475112.