[Subversion] / CityKid / citykid / commands.py  

View of /CityKid/citykid/commands.py

Parent Directory | Revision Log
Revision: 2124 - (download) (as text)
Sun Apr 9 19:46:34 2006 UTC (18 years ago) by pje
File size: 3930 byte(s)
Another attempt to fix the screwed-up import
# debugging prelude
import sys, pdb, traceback
sys.excepthook = lambda *x: (traceback.print_exception(*x), pdb.pm())
# end debugging prelude

from peak.api import *
from citykid import data
import os


class bunch(object):
    def __init__(self,items):
        self.__dict__ = dict(items)

    def __repr__(self):
        return "bunch(%r)" % (self.__dict__.keys(),)

























class CityApp(commands.AbstractCommand):

    fileURL = binding.Make(
        lambda self: "ref:ado@dsn:Provider=Microsoft.Jet.OLEDB.4.0;"
            "Data Source="+os.path.realpath(self.parsed_args[0])
    )

    db = binding.Obtain(naming.Indirect('fileURL'))

    items = binding.Make(data.ItemDM)
    templateDM = binding.Make(data.TemplateDM)

    language = 'English'
    family   = 'Kid'

    ixLanguage = binding.Make(
        lambda self: (
            ~self.db(
                "select ixLanguage from tblLanguage"
                " where sLanguage=? and fDeleted=0",
                (self.language,)
            )
        )[0]
    )

    ixFamily = binding.Make(
        lambda self: (
            ~self.db(
                "select ixTemplateFamily from tblTemplateFamily"
                " where sName=? and fDeleted=0",
                (self.family,)
            )
        )[0]
    )

    vars = binding.Make(
        lambda self: bunch(self.db("select sName, sValue from tblVariables"))
    )



    templates = binding.Make(
        lambda self: bunch(
            [(k,self.templateDM[v])
                for k,v in self.db(
                    "select sName,ixTemplateStructure"
                    " from tblTemplateStructure where fDeleted=0"
                )
            ]
        )
    )































class CityKid(CityApp):

    usage = """Usage: citykid filename.cty [itemnumber]
"""

    dispatch.as(binding.Make)
    def itemNo(self):
        if len(self.parsed_args)>1:
            try:
                return int(self.parsed_args[1])
            except ValueError:
                raise commands.InvocationError(
                    "Item # must be an integer", self.parsed_args[1]
                )

    def _checkArgs(self):
        args = self.parsed_args
        if len(args)<1 or len(args)>2:
            raise commands.InvocationError(
                "Must supply a CityDesk filename and optional item #"
            )
        
    def _run(self):
        self._checkArgs()
        storage.begin(self)
        item = self.items.get(self.itemNo)
        print "item path = ", item.path
        #print "children:"
        #for item in self.items.where(ixParent=self.itemNo):
        #    print item
        #print
        #print "vars", self.vars.test
        
        storage.abort(self)
        pdb.set_trace()








class CityBlog(CityKid):

    usage = """Usage: cityblog filename.cty itemnumber blogId user password
"""
    def _run(self):
        try:
            try:
                fname, itemNo, blogId, user, pw = self.parsed_args
            except ValueError:
                return self._invocationError("Five arguments are required")
                
            
            storage.begin(self)
    
            article = self.items.get(self.itemNo)
            if not isinstance(article, data.Article) or article.extra2:
                return self._invocationError(
                    "%s: Not an unpublished article" % article.path
                )
               
            print "uploading", article.path
    
            from citykid.blogger import Blog, Post
            p = Post(
                str(article.headline), str(article.body).encode('utf8'),
                article.modified
            )
            Blog(blogId, user, pw).add(p)
    
            article.extra2 = p.postId
            article.publishAs = p.postURL.split('/')[-1].split('.')[0]
    
            storage.commit(self)
        finally:
            pdb.set_trace()
            






cvs-admin@eby-sarna.com

Powered by ViewCVS 1.0-dev

ViewCVS and CVS Help