remove old scripts/cgi-bin stuff. They wouldn't work as such with the new version, and replacements can be written while referring to the history
authorTero Marttila <terom@fixme.fi>
Wed, 01 Jul 2009 20:15:08 +0300
changeset 139 d3167c40e7b9
parent 138 130fb8a8dbb9
child 140 7ea9766e33ed
remove old scripts/cgi-bin stuff. They wouldn't work as such with the new version, and replacements can be written while referring to the history
MANIFEST.in
cgi-bin/inc.py
cgi-bin/series.py
cgi-bin/shorturl.py
degal/filesystem.py
degal/utils.py
scripts/detool
scripts/fix_duplicate_shorturls.py
scripts/migrate_shorturls.py
setup.py
--- a/MANIFEST.in	Wed Jul 01 20:03:41 2009 +0300
+++ b/MANIFEST.in	Wed Jul 01 20:15:08 2009 +0300
@@ -1,2 +1,1 @@
 include degal/static/*
-include cgi-bin/*
--- a/cgi-bin/inc.py	Wed Jul 01 20:03:41 2009 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-# config
-
-# location of DeGAL itself
-
-DEGAL_PATH = "/mnt/photos/public"
-
-
-
-if __name__ == '__main__' :
-    raise Exception("Don't access inc.py directly")
-
-# setup env
-
-import sys
-import os, os.path
-
-#def splitn (path, n) :
-#    for i in xrange(0, n) :
-#        path = os.path.split(path)[0]      
-#    
-#    return path
-#        
-#degal_path = splitn(os.path.join(os.getcwd(), __file__), 2)
-
-os.chdir(DEGAL_PATH)
-sys.path.append(DEGAL_PATH)
-
--- a/cgi-bin/series.py	Wed Jul 01 20:03:41 2009 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,211 +0,0 @@
-#!/usr/bin/env python2.4
-#
-# DeGAL - A pretty simple web image gallery
-# Copyright (C) 2007 Tero Marttila
-# http://marttila.de/~terom/degal/
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the
-# Free Software Foundation, Inc.,
-# 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-#
-
-import os
-import cgi
-import Cookie
-
-import inc
-from lib import shorturl, template, utils, settings
-
-#
-# load request params
-#
-vars = cgi.FieldStorage()
-
-# these are interpeted different ways, hence the generic naming
-arg1 = vars["keys"].value
-if 'index' in vars :
-    arg2 = vars["index"].value
-else :
-    arg2 = None
-
-# the cookie with the user's current series
-cookie = Cookie.SimpleCookie(os.environ.get('HTTP_COOKIE', None))
-
-# a special action?
-if arg1 and arg1 in ('add', 'del', 'clear', 'view') or arg2 == 'load' :
-    # load the keys from the cookie
-    if 'series' in cookie :
-        keys = cookie["series"].value.split()
-    else :
-        keys = []
-    
-    if arg2 == 'load' :
-        # set the keys in the user's cookie to those in the URL
-        keys = arg1.split()
-
-    elif arg1 == 'add' and arg2 not in keys :
-        # add a code to the list of keys
-        keys.append(arg2)
-
-    elif arg1 == 'del' and arg2 in keys :
-        # remove a key from the list of keys
-        keys.remove(arg2)
-
-    elif arg1 == 'clear' :
-        # clear out the set of keys
-        keys = []
-
-    elif arg1 == 'view' :
-        # just view them
-        pass
-   
-    # set the series cookie value
-    cookie['series'] = ' '.join(keys)
-    cookie['series']['path'] = '/'
-    
-    # if we have keys, redirect to them, otherwise, back to index we go
-    if keys :
-        redirect_to = "../%s/" % ('+'.join(keys))
-    else :
-        redirect_to = "../.."
-    
-    # do the redirect
-    print "Status: 302"
-    print "Location: %s" % redirect_to
-    print cookie
-    print
-    print "Redirect..."
-else :
-    # we're just viewing
-    keys = arg1.split()
-    
-    # is this "My Series"?
-    my_series = 'series' in cookie and cookie['series'].value.split() == keys
-    
-    index = fname = None
-
-    if arg2 :
-        try :
-            index = int(arg2)
-        except ValueError :
-            fname = arg2
-
-    # our custom Series/Image classes, because they do act slightly differently
-
-    class Series (object) :
-        def __init__ (self, keys) :
-            self.images = []
-            prev = None
-
-            self.image_dict = dict()
-
-            images = shorturl.get_images(keys)
-
-            for index, (key, (dir, fname)) in enumerate(zip(keys, images)) :
-                img = Image(self, key, dir, fname, index)
-                self.images.append(img)
-                self.image_dict[fname] = img
-
-                img.prev = prev
-
-                if prev :
-                    prev.next = img
-
-                prev = img
-
-        def render (self) :
-            if my_series :
-                descr = '<a href="../clear/" rel="nofollow">Clear your series</a>'
-            else :
-                descr = '<a href="load" rel="nofollow">Load as your series</a>'
-   
-            return template.gallery.render(
-                stylesheet_url      = utils.url("style.css", up=2),
-                
-                breadcrumb          = [(utils.url(up=1), "Index"), (utils.url(), "Series")],
-
-                dirs                = None,
-                title               = "Series",
-
-                num_pages           = 1,
-                cur_page            = 0,
-
-                images              = self.images,
-
-                description         = descr,
-
-                shorturl            = None,
-                shorturl_code       = None,
-            )
-    
-    class Image (object) :
-        def __init__ (self, series, key, dir, fname, index) :
-            self.fname = fname
-            self.name = utils.url_join(dir, fname, abs=True)
-            self.html_name = utils.url(fname)
-            self.real_html_name = utils.url_join(dir, fname + ".html", abs=True)
-
-            self.thumb_name = utils.url_join(dir, settings.THUMB_DIR, fname, abs=True)
-            self.preview_name = utils.url_join(dir, settings.PREVIEW_DIR, fname, abs=True)
-
-            self.shorturl = key
-
-            self.prev = self.next = None
-
-        def render (self) :
-            descr = '<span style="font-size: x-small"><a href="%s.html">Standalone image</a></span>' % self.real_html_name
-            
-            if my_series :
-                series_url = utils.url_join("del", self.shorturl, up=1)
-                series_verb = "Remove from"
-            else :
-                series_url = series_verb = ""
-
-            return template.image.render(
-                stylesheet_url      = utils.url("style.css", up=3),
-                
-                breadcrumb          = [(utils.url(up=2), "Index"), (utils.url("."), "Series"), (self.html_name, self.fname)],
-
-                title               = self.fname,
-
-                prev                = self.prev,
-                img                 = self,
-                next                = self.next,
-                
-                description         = descr,
-    
-                img_size            = None,
-                file_size           = None,
-                timestamp           = None,
-                
-                shorturl            = utils.url_join("s", self.shorturl, abs=True),
-                shorturl_code       = self.shorturl,
-                
-                series_url          = series_url,
-                series_verb         = series_verb,
-            )
-    
-    series = Series(keys)
-
-    if fname :
-        html = series.image_dict[fname].render()
-    elif index :
-        html = series.images[index - 1].render()
-    else :
-        html = series.render()
-
-    print "Content-Type: text/html"
-    print
-    print html
-
--- a/cgi-bin/shorturl.py	Wed Jul 01 20:03:41 2009 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +0,0 @@
-#!/usr/bin/env python2.5
-#
-# DeGAL - A pretty simple web image gallery
-# Copyright (C) 2007 Tero Marttila
-# http://marttila.de/~terom/degal/
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the
-# Free Software Foundation, Inc.,
-# 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-#
-
-import inc
-from lib import shorturl, req
-
-key = req.get_str('key')
-index = req.get_int('index', None)
-
-path = shorturl.html_path(key)
-
-if path :
-    print "Status: 302"
-    print "Location: ../%s" % path
-    print
-    print "../%s" % path
-
-else :
-    print "Status: 404"
-    print
-    print "404"
-
--- a/degal/filesystem.py	Wed Jul 01 20:03:41 2009 +0300
+++ b/degal/filesystem.py	Wed Jul 01 20:15:08 2009 +0300
@@ -397,6 +397,7 @@
         The first and last nodes may be Files, but all other objects must be Directories.
 
         XXX: better to keep Paths symbolic/relative?
+        XXX: welcome to Circular Reference Hell, a place has been reserved for you
     """
 
     def __init__ (self, *nodes) :
--- a/degal/utils.py	Wed Jul 01 20:03:41 2009 +0300
+++ b/degal/utils.py	Wed Jul 01 20:15:08 2009 +0300
@@ -84,6 +84,7 @@
     
     for attr in attrs :
         if attr in obj.__dict__ :
+            # this will drop refcounts and free resources, so it may take some execution time
             del obj.__dict__[attr]
 
 def first (iterable) :
--- a/scripts/detool	Wed Jul 01 20:03:41 2009 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,106 +0,0 @@
-#!/usr/bin/env python2.4
-#
-# DeGAL - A pretty simple web image gallery
-# Copyright (C) 2007 Tero Marttila
-# http://marttila.de/~terom/degal/
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the
-# Free Software Foundation, Inc.,
-# 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-#
-
-from lib import settings
-from lib.log import misc as log
-from lib.utils import path_join
-import os, os.path, logging
-
-def move (options, args) :
-    if len(args) < 2 :
-        raise Exception("Must give one or more source files, and a destination dir")
-    
-    dest = args.pop(-1)
-    srcs = args
-    
-    if not os.path.isdir(dest) :
-        raise Exception("Given destination '%s' is not a directory" % dest)
-    
-    for subdir in (settings.THUMB_DIR, settings.PREVIEW_DIR) :
-        path = os.path.join(dest, subdir)
-        
-        if not os.path.exists(path) :
-            log.info("mkdir %s" % path)
-            os.mkdir(path)
-    
-    for src in srcs :
-        if not os.path.isfile(src) :
-            raise Exception("Given source file '%s' is not a valid file" % src)
-            
-        for (pre, post) in (
-            (None, None),
-            (settings.THUMB_DIR, None),
-            (settings.PREVIEW_DIR, None),
-            (None, '.html'),
-        ) :
-            dir, fname = os.path.split(src)
-            
-            if post :
-                fname += post
-            
-            src_path = path_join(dir, pre, fname)
-            dst_path = path_join(dest, pre, fname)
-            
-            if os.path.isfile(src_path) :
-                if not options.overwite and os.path.exists(dst_path) :
-                    log.warning("%s exists; skipping %s" % (dst_path, src_path))
-                log.info("%s -> %s" % (src_path, dst_path))
-                os.rename(src_path, dst_path)
-    
-def help (options, args) :
-    print "Available commands:"
-    
-    for name, func in COMMANDS.iteritems() :
-        print "\t%s" % name
-    
-COMMANDS = dict(
-    move    = move,
-    mv      = move,
-    help    = help,
-)
-    
-if __name__ == '__main__' :
-    from optparse import OptionParser
-    
-    parser = OptionParser(usage="usage: %prog <command> [options] [args ...]", version=settings.VERSION)
-    
-    parser.add_option("-q", "--quiet", dest="verbose", default=True)
-    parser.add_option("-i", "--careful", dest="overwrite", help="Do not overwrite files", default=True)
-    
-    options, args = parser.parse_args()
-    
-    if options.verbose :
-        log.setLevel(logging.INFO)
-    else :
-        log.setLevel(logging.ERROR)
-    
-    if not args :
-        parser.error("Must supply a command. See `detool.py help` for a list of commands")
-    
-    command = args.pop(0).lower()
-    
-    if command not in COMMANDS :
-        parser.error("Unknown command '%s'. Try `detool.py help`" % command)
-    
-    func = COMMANDS[command]
-    
-    func(options, args)
\ No newline at end of file
--- a/scripts/fix_duplicate_shorturls.py	Wed Jul 01 20:03:41 2009 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,33 +0,0 @@
-from lib import shorturl
-
-db = shorturl.DB(read_only=False)
-
-ids = dict()
-
-newid = db.db['_id']
-
-for key in db.db.keys() :
-    if key.startswith('_') :
-        continue
-
-    if len(key) == 1 :
-        print "key %s is too short!?" % key
-        del db.db[key]
-
-        continue
-    
-    print "%s:" % key, 
-    id = shorturl.key2int(key)
-
-    if id in ids :
-        newkey = shorturl.int2key(newid)
-        newid += 1
-
-        print "%d -> %s, -> %s" % (id, ids[id], newkey)
-
-        db.db[newkey] = db.db[key]
-        del db.db[key]
-    else :
-        print "ok"
-        ids[id] = key
-
--- a/scripts/migrate_shorturls.py	Wed Jul 01 20:03:41 2009 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,53 +0,0 @@
-from lib import shorturl, db
-
-sdb = shorturl.DB()
-
-def gen () :
-    count = 0
-
-    for key in sdb.db.keys() :
-        if key.startswith("_") :
-            continue
-        
-        print "%6s" % key,
-
-        value = sdb.db[key]
-
-        if not isinstance(value, tuple) or len(value) != 3 :
-            print "CORRUPT VALUE!!!"
-            continue
-
-        type, dirpath, fname = value
-
-        id = shorturl.key2int(key)
-        dirpath = dirpath.lstrip('.').lstrip('/')
-
-        if type == "img" :
-            print "img"
-            continue    # already imported images
-
-            print "img %6d %50s %10s" % (id, dirpath, fname)
-
-            yield id, dirpath, fname
-
-        else :
-
-            print "dir %6d %50s" % (id, dirpath)
-
-            yield id, dirpath, ''
-
-        count += 1
-
-        if count % 500 == 0 :
-            print count
-
-
-print "Starting import..."
-
-c = db.insert_many("""
-    INSERT OR IGNORE INTO nodes VALUES (?, ?, ?)
-""", gen())
-
-print "Done!"
-
-print "%d rows affected" % c
--- a/setup.py	Wed Jul 01 20:03:41 2009 +0300
+++ b/setup.py	Wed Jul 01 20:15:08 2009 +0300
@@ -29,7 +29,5 @@
 
     scripts         = [
         'bin/degal',
-        'scripts/fix_duplicate_shorturls.py', 'scripts/migrate_shorturls.py',
-        'cgi-bin/series.py', 'cgi-bin/shorturl.py',
     ],
 )