示例#1
0
文件: fsfix.py 项目: falstaff84/aspen
def mk(*treedef, **kw):
    """Given a treedef, build a filesystem fixture in ./fsfix.

    treedef is a sequence of strings and tuples. If a string, it is interpreted
    as a path to a directory that should be created. If a tuple, the first
    element is a path to a file, the second is the contents of the file. We do
    it this way to ease cross-platform testing.

    The one meaningful keyword argument is configure. If True, mk will call
    aspen.configure with ./fsfix as the root.

    """
    configure = kw.get('configure', False)
    root = realpath('fsfix')
    os.mkdir(root)
    for item in treedef:
        if isinstance(item, basestring):
            path = convert_path(item.lstrip('/'))
            path = os.sep.join([root, path])
            os.makedirs(path)
        elif isinstance(item, tuple):
            filepath, contents = item
            path = convert_path(filepath.lstrip('/'))
            path = os.sep.join([root, path])
            parent = dirname(path)
            if not isdir(parent):
                os.makedirs(parent)
            file(path, 'w').write(contents)
    if configure is True:
        aspen.configure(['--root', root])
示例#2
0
文件: fsfix.py 项目: dowski/aspen
def mk(*treedef, **kw):
    """Given a treedef, build a filesystem fixture in ./fsfix.

    treedef is a sequence of strings and tuples. If a string, it is interpreted
    as a path to a directory that should be created. If a tuple, the first
    element is a path to a file, the second is the contents of the file. We do
    it this way to ease cross-platform testing.

    The one meaningful keyword argument is configure. If True, mk will call
    aspen.configure with ./fsfix as the root.

    """
    configure = kw.get('configure', False)
    root = realpath('fsfix')
    os.mkdir(root)
    for item in treedef:
        if isinstance(item, basestring):
            path = convert_path(item.lstrip('/'))
            path = os.sep.join([root, path])
            os.makedirs(path)
        elif isinstance(item, tuple):
            filepath, contents = item
            path = convert_path(filepath.lstrip('/'))
            path = os.sep.join([root, path])
            parent = dirname(path)
            if not isdir(parent):
                os.makedirs(parent)
            file(path, 'w').write(contents)
    if configure is True:
        aspen.configure(['--root', root])
示例#3
0
文件: db.py 项目: adamdsouza1/gheat
#!/usr/local/bin/python
"""Update the database from the txt/csv file.

First run "__/bin/db.py create", then run this script without arguments: it 
should find the points.txt and points.db files.

"""
import csv
import os
import sqlite3
import stat
import sys
from datetime import datetime

import aspen
aspen.configure()


__all__ = ['clear', 'count', 'delete', 'sync']


RAWPATH = os.path.join(aspen.paths.__, 'var', 'points.txt')
DBPATH = os.path.join(aspen.paths.__, 'var', 'points.db')


def _create():
    cur = CONN.cursor()
    cur.execute("""

        CREATE TABLE IF NOT EXISTS points(
示例#4
0
#!/usr/bin/env python
"""Generate gheat tiles.
"""
import math
import os
import sys
from os.path import join

import aspen
root = aspen.find_root()
aspen.configure(['--root', root])

from gmerc import ll2px
from gheat import pil_ as backend


color_schemes = dict()          # this is used below
_color_schemes_dir = os.path.join(aspen.paths.__, 'etc', 'color-schemes')
for fname in os.listdir(_color_schemes_dir):
    if not fname.endswith('.png'):
        continue
    name = os.path.splitext(fname)[0]
    fspath = os.path.join(_color_schemes_dir, fname)
    color_schemes[name] = backend.ColorScheme(name, fspath)


def load_dots(backend):
    """Given a backend module, return a mapping of zoom level to Dot object.
    """
    return dict([(zoom, backend.Dot(zoom)) for zoom in range(20)])
dots = load_dots(backend) # factored for easier use from scripts
示例#5
0
#!/usr/local/bin/python
"""Update the database from the txt/csv file.

First run "__/bin/db.py create", then run this script without arguments: it 
should find the points.txt and points.db files.

"""
import csv
import os
import sqlite3
import stat
import sys
from datetime import datetime

import aspen
aspen.configure()

__all__ = ['clear', 'count', 'delete', 'sync']

RAWPATH = os.path.join(aspen.paths.__, 'var', 'points.txt')
DBPATH = os.path.join(aspen.paths.__, 'var', 'points.db')


def _create():
    cur = CONN.cursor()
    cur.execute("""

        CREATE TABLE IF NOT EXISTS points(

            uid         TEXT UNIQUE PRIMARY KEY             ,
            lat         REAL                                ,