Wrote a webkofoto wrapper program that imports webkofoto.py as a
authorJoel Rosdahl <joel@rosdahl.net>
Fri, 19 Mar 2004 21:15:37 +0000 (21:15 +0000)
committerJoel Rosdahl <joel@rosdahl.net>
Fri, 19 Mar 2004 21:15:37 +0000 (21:15 +0000)
module in a kofotoweb package.

Added support for specifying the port to bind to.

Removed webkofoto.cfg; it is now generated on-the-fly by webkofoto.

Build and install webkofoto on POSIX systems, since it seems tricky to
do this automatically on Windows.

Renamed kofoto.css to webkofoto.css.

Set svn:ignore and svn:eol-style properties where appropriate.

Mention CherryPy in INSTALL.

INSTALL
Makefile
setup.py
src/web/Makefile
src/web/Page.cpy
src/web/static/kofoto.css [deleted file]
src/web/static/webkofoto.css [new file with mode: 0644]
src/web/webkofoto [new file with mode: 0755]
src/web/webkofoto.cfg [deleted file]

diff --git a/INSTALL b/INSTALL
index 912af39..f31f88f 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -17,6 +17,10 @@ Dependencies:
 
         http://pysqlite.sourceforge.net
 
+  * CherryPy (for the web client). Found at:
+
+        http://www.cherrypy.org
+
 Installation:
 
     Unix/Windows:
index 3f2b780..267e4be 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -7,6 +7,7 @@ help:
        @echo "install [PREFIX=prefix]"
 
 clean:
+       $(MAKE) -C src/web clean
        rm -rf build
        find . \( -name '*~' -o -name '*.pyc' \) -exec rm -f {} \;
 
index 0a563b7..d5a9a46 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -1,23 +1,45 @@
 #! /usr/bin/env python
 
 from distutils.core import setup
+import os
+
+package_dir = {
+    "": "src/lib",
+    "kofoto": "src/lib/kofoto",
+    "gnomekofoto": "src/gnome/gnomekofoto",
+    }
+packages = [
+    "kofoto",
+    "kofoto.output",
+    "gnomekofoto",
+    ]
+scripts = [
+    "src/cmdline/renameimage",
+    "src/cmdline/kofoto",
+    "src/cmdline/kofoto-upload",
+    "src/gnome/gkofoto",
+    ]
+data_files = [
+    ("share/gnomekofoto/glade", ["src/gnome/glade/gkofoto.glade"]),
+    ("share/gnomekofoto/icons", ["src/gnome/icons/fullscreen-24.png"])
+    ]
+if os.name == "posix":
+    os.system("cd src/web && make")
+    package_dir["kofotoweb"] = "src/web/kofotoweb"
+    packages.append("kofotoweb")
+    scripts.append("src/web/webkofoto")
+    data_files.append(("share/kofotoweb/static", [
+        "src/web/static/webkofoto.css",
+        ]))
+
 setup(
     name="kofoto",
     version="0.0.0",
-    package_dir={
-        "": "src/lib",
-        "kofoto": "src/lib/kofoto",
-        "gnomekofoto": "src/gnome/gnomekofoto"},
-    packages=["kofoto", "kofoto.output", "gnomekofoto"],
+    package_dir=package_dir,
+    packages=packages,
     py_modules=["EXIF"],
-    scripts=[
-        "src/cmdline/renameimage",
-        "src/cmdline/kofoto",
-        "src/cmdline/kofoto-upload",
-        "src/gnome/gkofoto"],
-    data_files=[
-        ("share/gnomekofoto/glade", ["src/gnome/glade/gkofoto.glade"]),
-        ("share/gnomekofoto/icons", ["src/gnome/icons/fullscreen-24.png"])],
+    scripts=scripts,
+    data_files=data_files,
     author="Kofoto developers",
     author_email="10711@lyskom.lysator.liu.se",
     url="http://svn.rosdahl.net/kofoto/kofoto/")
index a0c6c91..091be22 100644 (file)
@@ -1,13 +1,17 @@
 CLASSES = Page Root
 CLASSFILES = $(CLASSES:=.cpy)
 
-all: webkofoto.py
+all: kofotoweb/server.py
 
 run: all
-       python webkofoto.py
+       python webkofoto
 
-webkofoto.py: $(CLASSFILES)
-       cherrypy -O $@ $^
+kofotoweb:
+       mkdir -p $@
+       touch $@/__init__.py
+
+kofotoweb/server.py: kofotoweb $(CLASSFILES)
+       cherrypy -O $@ $(CLASSFILES)
 
 clean:
-       rm -f webkofoto.py *~
+       rm -rf *~ *.py[co] kofotoweb
index 6400eed..2069876 100644 (file)
@@ -7,7 +7,7 @@ mask:
             "http://www.w3.org/TR/xhtml1/DTD/xhtml1-<py-eval="frameset and 'frameset' or 'strict'">.dtd">
         <html xmlns="http://www.w3.org/1999/xhtml">
         <head>
-        <link rel="stylesheet" href="/static/kofoto.css" type="text/css" />
+        <link rel="stylesheet" href="/static/webkofoto.css" type="text/css" />
         </head>
         <py-if="not frameset"><body></py-if>
 
diff --git a/src/web/static/kofoto.css b/src/web/static/kofoto.css
deleted file mode 100644 (file)
index 276f8bd..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-html {
-    color: #000;
-    background: #ddd;
-    font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
-}
-
-a {
-    text-decoration: none;
-}
-
-a:link {
-    color: #000;
-}
-
-a:visited {
-    color: #000;
-}
-
-a:hover {
-    color: #22f;
-}
-
-ul {
-    list-style-type: none;
-    margin-left: 0.4em;
-    margin-top: 0.1em;
-    margin-right: 0.1em;
-    margin-bottom: 0.1em;
-    padding-left: 0em;
-    border-style: solid;
-    border-width: 1px;
-}
-
-ul li {
-    padding-top: 0.2em;
-    padding-bottom: 0.2em;
-    padding-left: 0.2em;
-    border-style: solid;
-    border-width: 1px;
-    border-color: #fff #c4c4d5 #c4c4d5 #fff;
-}
-
-li.odd {
-    background-color: #d2d2d2;
-}
-
-li.even {
-    background-color: #dddddd;
-}
diff --git a/src/web/static/webkofoto.css b/src/web/static/webkofoto.css
new file mode 100644 (file)
index 0000000..276f8bd
--- /dev/null
@@ -0,0 +1,49 @@
+html {
+    color: #000;
+    background: #ddd;
+    font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
+}
+
+a {
+    text-decoration: none;
+}
+
+a:link {
+    color: #000;
+}
+
+a:visited {
+    color: #000;
+}
+
+a:hover {
+    color: #22f;
+}
+
+ul {
+    list-style-type: none;
+    margin-left: 0.4em;
+    margin-top: 0.1em;
+    margin-right: 0.1em;
+    margin-bottom: 0.1em;
+    padding-left: 0em;
+    border-style: solid;
+    border-width: 1px;
+}
+
+ul li {
+    padding-top: 0.2em;
+    padding-bottom: 0.2em;
+    padding-left: 0.2em;
+    border-style: solid;
+    border-width: 1px;
+    border-color: #fff #c4c4d5 #c4c4d5 #fff;
+}
+
+li.odd {
+    background-color: #d2d2d2;
+}
+
+li.even {
+    background-color: #dddddd;
+}
diff --git a/src/web/webkofoto b/src/web/webkofoto
new file mode 100755 (executable)
index 0000000..0af9c16
--- /dev/null
@@ -0,0 +1,92 @@
+#! /usr/bin/env python
+
+import getopt
+import os
+import socket
+import sys
+import tempfile
+
+# Find libraries if installed in ../lib (like in the source tree).
+if os.path.islink(sys.argv[0]):
+    link = os.readlink(sys.argv[0])
+    absloc = os.path.normpath(
+        os.path.join(os.path.dirname(sys.argv[0]), link))
+    bindir = os.path.dirname(absloc)
+else:
+    bindir = os.path.dirname(sys.argv[0])
+sys.path.insert(0, os.path.join(bindir, "..", "lib"))
+datadir = os.path.join(bindir, "..", "share", "kofotoweb")
+if not os.path.exists(datadir):
+    datadir = bindir
+
+import kofoto.shelf
+import kofotoweb.server
+
+######################################################################
+
+defaultPort = 7448
+
+def displayHelp():
+    sys.stdout.write(
+        "Usage: webkofoto [flags]\n"
+        "\n"
+        "Flags:\n"
+        "\n"
+        "    -h, --help         Display this help.\n"
+        "    -p, --port PORT    Listen for connection on port PORT instead of the\n"
+        "                       default (%s).\n"
+        "    -v, --verbose      Print some diagnostics to standard output.\n"
+        "\n"
+        "A URL suitable for pasting into a web browser is printed to standard output.\n" %
+            defaultPort)
+
+port = defaultPort
+verbose = False
+if os.path.isdir("static"):
+    staticLocation = "static"
+else:
+    staticLocation = os.path.join(datadir, "static")
+
+try:
+    optlist, args = getopt.gnu_getopt(
+        sys.argv[1:],
+        "hp:v",
+        ["help", "port=", "verbose="])
+except getopt.GetoptError:
+    printErrorAndExit("Unknown flag. See \"webkofoto --help\" for help.\n")
+for opt, optarg in optlist:
+    if opt in ("-h", "--help"):
+        displayHelp()
+        sys.exit(0)
+    elif opt in ("-p", "--port"):
+        port = int(optarg)
+    elif opt in ("-v", "--verbose"):
+        verbose = True
+
+fd, configfilename = tempfile.mkstemp(".cfg", "webkofoto-")
+configfile = os.fdopen(fd, "w")
+configfile.write("""[server]
+socketPort = %d
+logToScreen = %d
+[staticContent]
+static = %s
+""" % (
+    port,
+    verbose,
+    staticLocation))
+configfile.close()
+
+try:
+    try:
+        print "http://%s:%d" % (socket.getfqdn(), port)
+        kofotoweb.server.run(["webkofoto", "-C", configfilename])
+    except socket.error :
+        sys.stderr.write(
+            "Could not bind to TCP port %d since it's already in use.\n" % port)
+        sys.exit(1)
+    except kofoto.shelf.ShelfLockedError:
+        sys.stderr.write(
+            "Could not open the shelf. Another process is locking it.\n")
+        sys.exit(1)
+finally:
+    os.unlink(configfilename)
diff --git a/src/web/webkofoto.cfg b/src/web/webkofoto.cfg
deleted file mode 100644 (file)
index c32aa87..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-[server]
-socketPort = 7448
-
-[staticContent]
-static = static