示例#1
0
def getzip(code, noerror=False):
    try:
        code = str(int(code.strip()[:5]))
        while len(code) < 5:  # preceding 0's
            code = '0' + code
    except:
        if noerror:
            return
        from cantools.util import error
        error("invalid zip code: %s" % (code, ))
    zipcode = ZipCode.query().filter(ZipCode.code == code).get()
    if not zipcode:
        if config.map:  # old configuration style
            city, state, county = fetch(config.map.zipdomain,
                                        path="/%s" % (code, ),
                                        asjson=True)
        else:  # use mkpi-style ctmap.zip.domain
            city, state, county = fetch("%s/geo?action=zip&code=%s" %
                                        (config.ctmap.zip.domain, code),
                                        ctjson=True)
        zipcode = ZipCode(code=code, city=city, state=state, county=county)
        zipcode.put()
    if config.ctmap.zip.latlng and not zipcode.latitude:
        zipcode.latlng()
    return zipcode
 def __init__(self,
              pname=None,
              cantools_path=HOME,
              web_backend="dez",
              refresh_symlinks=False):
     if not pname and not refresh_symlinks:
         pname = raw_input("project name? ")
     log("Initializing %s Project: %s" %
         (web_backend, pname or "(refresh)"))
     self.pname = pname
     self.ctroot = os.path.join(cantools_path, "cantools", "cantools")
     if not os.path.exists(self.ctroot):
         error(
             "failed to establish cantools root",
             "We tried: %s" % (self.ctroot, ),
             "This directory does not contain cantools.",
             "You can download cantools at https://github.com/bubbleboy14/cantools",
             "Please pass the path to your local copy of cantools via the -c flag."
         )
     self.web_backend = web_backend
     self.refresh_symlinks = refresh_symlinks
     if not refresh_symlinks:
         self.build_dirs()
         self.make_files()
     self.vcignore()
     self.generate_symlinks()
     log("done! goodbye.", 1)
def go():
	parser = OptionParser("ctstart [--web_backend=BACKEND] [--port=PORT] [--datastore=DS_PATH]")
	parser.add_option("-w", "--web_backend", dest="web_backend", default=config.web.server,
		help="web backend. options: dez, gae. (default: %s)"%(config.web.server,))
	parser.add_option("-p", "--port", dest="port", default=config.web.port,
		help="select your port (default=%s)"%(config.web.port,))
	parser.add_option("-a", "--admin_port", dest="admin_port", default=config.admin.port,
		help="select your port (default=%s)"%(config.admin.port,))
	parser.add_option("-d", "--datastore", dest="datastore", default=config.db.main,
		help="select your datastore file (default=%s)"%(config.db.main,))
	options, args = parser.parse_args()

	config.web.update("port", int(options.port))
	config.admin.update("port", int(options.admin_port))

	if options.web_backend == "gae":
		import subprocess
		cmd = 'dev_appserver.py . --host=%s --port=%s --admin_port=%s --datastore_path=%s'%(config.web.host,
			options.port, options.admin_port, options.datastore)
		print cmd
		subprocess.call(cmd, shell=True)
	elif options.web_backend == "dez":
		from cantools.web import run_dez_webserver
		run_dez_webserver()
	else:
		error("invalid web_backend: %s"%(options.web_backend,))
def go():
	if config.web.server != "dez":
		error("ctindex only available for dez projects")
	log("indexing foreignkey references throughout database")
	import model # load schema
	for kind, references in refmap().items():
		log("processing table: %s"%(kind,), important=True)
		for reference, keys in references.items():
			batch(keys, do_batch, reference)
	tcount = sum(counts.values()) - counts["_counters"]
	log("refreshed %s rows and updated %s counters"%(tcount, counts["_counters"]), important=True)
	log("goodbye")
示例#5
0
	def getstart(self, f, start=None):
		i = self.page.find(f, start)
		i2 = None
		if '"' in f:
			i2 = self.page.find(f.replace('"', "'"), start)
		elif "'" in f:
			i2 = self.page.find(f.replace("'", '"'), start)
		if i2 and i2 != -1:
			if i == -1 or i > i2:
				i = i2
		if i == -1:
			error("can't find %s"%(f,))
		return i
def go():
    if config.web.server != "dez":
        error("ctindex only available for dez projects")
    log("indexing foreignkey references throughout database")
    import model  # load schema
    for kind, references in refmap().items():
        log("processing table: %s" % (kind, ), important=True)
        for reference, keys in references.items():
            batch(keys, do_batch, reference)
    tcount = sum(counts.values()) - counts["_counters"]
    log("refreshed %s rows and updated %s counters" %
        (tcount, counts["_counters"]),
        important=True)
    log("goodbye")
def encodestrings(text):
    start = nextQuote(text) + 1
    while start != 0:
        end = nextQuote(text, start)
        if end == -1:
            error(
                "parse", "unclosed quote: character %s" % (start - 1, ),
                "this quote: %s" %
                (text[start:start + config.parse_error_segment_length], ),
                text)
        word = ''.join(
            ["\\%s" % (oct(ord(ch))[1:], ) for ch in list(text[start:end])])
        if "\\134" not in word:  # don't re-escape!
            text = text[:start] + word + text[end:]
        start = nextQuote(text, start + len(word) + 1) + 1
    return text
def processhtml(html):
    html = html.replace("{", "&#123").replace("}", "&#125").replace(
        "</body>", "%s</body>" % (config.noscript, ))
    firststart = start = end = html.find(config.js.flag)
    js = []
    while start != -1:
        start += config.js.offset
        end = html.find('"', start)
        if end == -1:
            error("no closing quote in this file: %s" % (html, ))
        js.append(html[start:end].strip("/"))
        start = html.find(config.js.flag, end)
    log("js: %s" % (js, ), 1)
    if start == end:
        return html, ""
    return html[:firststart] + "{jsspot}" + html[end +
                                                 config.js.endoffset:], js
def build(nothing, dirname, fnames):
    """
    This parses an html file, squishes together the javascript, scans
    through for dynamic imports (CT.require statements), injects modules
    wherever necessary, and sticks the result in a big <script> tag.
    """
    if ".svn" in dirname:
        return
    for bd in config.build.compiled_dirs.values():
        checkdir(bd)
    for fname in bfiles(dirname, fnames):
        for mode, compdir in config.build.compiled_dirs.items():
            fulldir = dirname.replace(config.build.dynamic_dir, compdir)
            frompath = os.path.join(dirname, fname)
            topath = os.path.join(fulldir, fname)
            data = read(frompath)
            log('building: %s -> %s' % (frompath, topath), important=True)
            checkdir(fulldir)
            if "fonts" in dirname or not fname.endswith(".html"):
                log('copying non-html file', 1)
            else:
                txt, js = processhtml(data)
                if js:
                    jspaths, jsblock = compilejs(js)
                    if mode is "static":
                        log("static mode", 1)
                        js = '\n'.join([
                            p.endswith("js") and '<script src="%s"></script>' %
                            (p, ) or '<script>%s</script>' % (p, )
                            for p in jspaths
                        ])
                    elif mode is "production":
                        log("production mode", 1)
                        txt = compress(txt)
                        from slimit import minify
                        js = "<script>%s</script>" % (minify(jsblock.replace(
                            '"_encode": false,', '"_encode": true,').replace(
                                "CT.log._silent = false;",
                                "CT.log._silent = true;"),
                                                             mangle=True), )
                    else:
                        error("invalid mode: %s" % (mode, ))
                    data = txt.format(jsspot=js)
                else:
                    data = txt
            write(data, topath)
示例#10
0
def getzip(code):
    if len(code) < 5:
        from cantools.util import error
        error("invalid zip code: %s"%(code,))
    try:
        code = str(int(code.strip()[:5]))
        while len(code) < 5: # preceding 0's
            code = '0'+code
    except:
        from cantools.util import error
        error("invalid zip code: %s"%(code,))
    zipcode = ZipCode.query().filter(ZipCode.code == code).get()
    if not zipcode:
        from cantools.web import fetch
        city, state, county = fetch(ZIPDOMAIN, path="/%s"%(code,), asjson=True)
        zipcode = ZipCode(code=code, city=city, state=state, county=county)
        zipcode.put()
    return zipcode
def go():
    parser = OptionParser(
        "ctstart [--web_backend=BACKEND] [--port=PORT] [--datastore=DS_PATH]")
    parser.add_option("-w",
                      "--web_backend",
                      dest="web_backend",
                      default=config.web.server,
                      help="web backend. options: dez, gae. (default: %s)" %
                      (config.web.server, ))
    parser.add_option("-p",
                      "--port",
                      dest="port",
                      default=config.web.port,
                      help="select your port (default=%s)" %
                      (config.web.port, ))
    parser.add_option("-a",
                      "--admin_port",
                      dest="admin_port",
                      default=config.admin.port,
                      help="select your port (default=%s)" %
                      (config.admin.port, ))
    parser.add_option("-d",
                      "--datastore",
                      dest="datastore",
                      default=config.db.main,
                      help="select your datastore file (default=%s)" %
                      (config.db.main, ))
    options, args = parser.parse_args()

    config.web.update("port", int(options.port))
    config.admin.update("port", int(options.admin_port))

    if options.web_backend == "gae":
        import subprocess
        cmd = 'dev_appserver.py . --host=%s --port=%s --admin_port=%s --datastore_path=%s' % (
            config.web.host, options.port, options.admin_port,
            options.datastore)
        print cmd
        subprocess.call(cmd, shell=True)
    elif options.web_backend == "dez":
        from cantools.web import run_dez_webserver
        run_dez_webserver()
    else:
        error("invalid web_backend: %s" % (options.web_backend, ))
示例#12
0
def manage(agent, membership, identifier, memberships=None):
    memship = db.get(membership or memberships[0])
    pod = db.get(memship.pod)
    if pod.agent.urlsafe() != (agent or global_pod().agent.urlsafe()):
        error("wrong!")
    conq = Content.query(Content.identifier == identifier)
    if memberships:
        conq.filter(Content.memberships == memberships)
    else:
        conq.filter(Content.membership == membership)
    con = conq.get()
    if not con:
        con = Content(identifier=identifier)
        if memberships:
            con.memberships = memberships
        else:
            con.membership = membership
        con.put()
    return con
示例#13
0
	def __init__(self, pname=None, cantools_path=HOME, web_backend="dez", refresh_symlinks=False):
		if not pname and not refresh_symlinks:
			pname = raw_input("project name? ")
		log("Initializing %s Project: %s"%(web_backend, pname or "(refresh)"))
		self.pname = pname
		self.ctroot = os.path.join(cantools_path, "cantools", "cantools")
		if not os.path.exists(self.ctroot):
			error("failed to establish cantools root",
				"We tried: %s"%(self.ctroot,),
				"This directory does not contain cantools.",
				"You can download cantools at https://github.com/bubbleboy14/cantools",
				"Please pass the path to your local copy of cantools via the -c flag."
			)
		self.web_backend = web_backend
		self.refresh_symlinks = refresh_symlinks
		if not refresh_symlinks:
			self.build_dirs()
			self.make_files()
		self.vcignore()
		self.generate_symlinks()
		log("done! goodbye.", 1)
def run():
    from optparse import OptionParser
    parser = OptionParser("ctdeploy [-d|s|p] [-un] [--js_path=PATH]")
    parser.add_option("-d", "--dynamic", action="store_true", dest="dynamic",
        default=False, help="switch to dynamic (development) mode")
    parser.add_option("-s", "--static", action="store_true", dest="static",
        default=False, help="switch to static (debug) mode")
    parser.add_option("-p", "--production", action="store_true", dest="production",
        default=False, help="switch to production (garbled) mode")
    parser.add_option("-u", "--upload", action="store_true", dest="upload", default=False,
        help="uploads project in specified mode and then switches back to dynamic (development) mode")
    parser.add_option("-n", "--no_build", action="store_true",
        dest="no_build", default=False, help="skip compilation step")
    parser.add_option("-j", "--js_path", dest="js_path", default=config.js.path,
        help="set javascript path (default=%s)"%(config.js.path,))
    options, args = parser.parse_args()

    mode = options.dynamic and "dynamic" or options.static and "static" or options.production and "production"
    if not mode:
        error("no mode specified")

    # 0) set js path
    if options.js_path != config.js.path:
        log("setting js path to: %s"%(options.js_path,))
        config.js.update("path", options.js_path)

    # 1) build static/production files
    if not options.no_build:
        os.path.walk(config.build.dynamic_dir, build, None)

    # 2) switch to specified mode
    setmode(mode)

    # 3) if -u, upload project and switch back to -d mode
    if options.upload:
        log("uploading files")
        subprocess.call('appcfg.py update . --no_precompilation --noauth_local_webserver', shell=True)
        setmode("dynamic")

    log("goodbye")
示例#15
0
 def id(self):
     if not self.key:
         util.error("can't get id -- not saved!")
     return self.key.urlsafe()
示例#16
0
from util import config

if config.web.server == "gae":
    from gae_server import *
elif config.web.server == "dez":
    from cantools.web.dez_server import *
else:
    from cantools import util
    util.error("no web server specified")
def run():
    from optparse import OptionParser
    parser = OptionParser("ctdeploy [-d|s|p] [-un] [--js_path=PATH]")
    parser.add_option("-d",
                      "--dynamic",
                      action="store_true",
                      dest="dynamic",
                      default=False,
                      help="switch to dynamic (development) mode")
    parser.add_option("-s",
                      "--static",
                      action="store_true",
                      dest="static",
                      default=False,
                      help="switch to static (debug) mode")
    parser.add_option("-p",
                      "--production",
                      action="store_true",
                      dest="production",
                      default=False,
                      help="switch to production (garbled) mode")
    parser.add_option(
        "-u",
        "--upload",
        action="store_true",
        dest="upload",
        default=False,
        help=
        "uploads project in specified mode and then switches back to dynamic (development) mode"
    )
    parser.add_option("-n",
                      "--no_build",
                      action="store_true",
                      dest="no_build",
                      default=False,
                      help="skip compilation step")
    parser.add_option("-j",
                      "--js_path",
                      dest="js_path",
                      default=config.js.path,
                      help="set javascript path (default=%s)" %
                      (config.js.path, ))
    options, args = parser.parse_args()

    mode = options.dynamic and "dynamic" or options.static and "static" or options.production and "production"
    if not mode:
        error("no mode specified")

    # 0) set js path
    if options.js_path != config.js.path:
        log("setting js path to: %s" % (options.js_path, ))
        config.js.update("path", options.js_path)

    # 1) build static/production files
    if not options.no_build:
        os.path.walk(config.build.dynamic_dir, build, None)

    # 2) switch to specified mode
    setmode(mode)

    # 3) if -u, upload project and switch back to -d mode
    if options.upload:
        log("uploading files")
        subprocess.call(
            'appcfg.py update . --no_precompilation --noauth_local_webserver',
            shell=True)
        setmode("dynamic")

    log("goodbye")
示例#18
0
def enroll(agent, pkey, person):
    pod = db.get(pkey)
    if pod.agent.urlsafe() != agent:
        error("wrong!")
    return db.get(person).enroll(pod)
示例#19
0
from ..config import config

# later, switch these imports on 'db' instead of 'web.server'
if config.web.server == "gae":
    from gae.model import *
elif config.web.server == "dez":
    from sql.model import *
    from sql.lookup import inc_counter, dec_counter, refresh_counter, refcount_subq
    from sql import lookup
else:
    from cantools import util
    util.error("no data backend specified")
from ..config import config

# later, switch these imports on 'db' instead of 'web.server'
if config.web.server == "gae":
	from gae.model import *
elif config.web.server == "dez":
	from sql.model import *
	from sql.lookup import inc_counter, dec_counter, refresh_counter, refcount_subq
	from sql import lookup
else:
	from cantools import util
	util.error("no data backend specified")
示例#21
0
 def cval(s, k, v):
     if v not in choices:
         util.error("can't set %s! %s not in %s"%(k, v, choices))
     return v