예제 #1
0
def set_tokens(name='token'):
    # import pdb; pdb.set_trace()
    cfg = ConfigUtil(ini="mapproxy.ini")
    tok = cfg.get(name, section="metro")
    if tok:
        dir = file_utils.get_file_dir(__file__)
        template_utils.apply_kv_to_files(key=name, value=tok, dir_path=dir, ext=".yaml", rewrite=True)
예제 #2
0
    def _make_parser(self):
        """ make the config parser (SafeConfigParser) ... file lookup relative to the directory you run your app from
        """
        # import pdb; pdb.set_trace()
        # capture the execution directory in a global, as we're likely to cd out of here at some point
        global RUN_DIR
        if RUN_DIR is None:
            RUN_DIR = os.getcwd()

        self.logging_cfg()

        candidates = []
        for i in self.ini:
            # add the .ini file and ./config/.ini file to our candidate file list
            c = self.get_candidates(name=i)
            if c:
                candidates = candidates + c

        # create the config parser and read the .ini files
        scp = configparser.SafeConfigParser()
        paths = scp.read(candidates)

        # set variables
        if paths and len(paths):
            for p in paths:
                if file_utils.exists(p):
                    self.found_ini = True
                    self.ini_file_path = p
                    self.ini_dir_path = file_utils.get_file_dir(p)
                    break

        return scp
예제 #3
0
def test_shp_file(file_name="tm_boundary"):
    dir = file_utils.get_file_dir(__file__)
    file_path = os.path.join(dir, 'data', file_name)
    shp = District.read_shp(file_path)
    geo = shp.shapes()
    print(shp, 'len =', len(geo))
    pt = geo[0].points[0]
    print(geo_utils.to_lon_lat_tuple(pt))
예제 #4
0
def load(files=None, database=None, schema=None, user=None):
    """"""
    # step 1: build cmd line for load_inrix_geojson.sh
    dir = file_utils.get_file_dir(__file__)
    load_sh = os.path.join(dir, "load_inrix_geojson.sh")
    if files:
        load_sh = "{} {}".format(load_sh, object_utils.list_to_str(files))

    # step 2: set env vars for  load_inrix_geojson.sh
    if database: os.environ['DB_NAME'] = database
    if schema: os.environ['DB_SCHEMA'] = schema
    if user: os.environ['DB_USER'] = user

    # step 3: run script
    #import pdb; pdb.set_trace()
    exe_utils.run_cmd_get_stdout(load_sh)
예제 #5
0
 def setUp(self):
     self.base_path = file_utils.get_file_dir(__file__)
     self.auto_url = "https://ws-st.trimet.org/pelias/v1/autocomplete"
     self.search_url = "https://ws-st.trimet.org/pelias/v1/search"
예제 #6
0
import os
from ott.utils import file_utils
from PIL import Image, ImageDraw, ImageFont

font_file = os.path.join(file_utils.get_file_dir(__file__), 'fonts',
                         'Transit-Bold.ttf')
transit_bold = ImageFont.truetype(font_file, 12)


def draw_ellipse(image, bounds, width=1, outline='white', antialias=4):
    """Improved ellipse drawing function, based on PIL.ImageDraw."""

    # Use a single channel image (mode='L') as mask.
    # The size of the mask can be increased relative to the imput image
    # to get smoother looking results.
    mask = Image.new(size=[int(dim * antialias) for dim in image.size],
                     mode='RGBA',
                     color=(0, 0, 0, 0))
    draw = ImageDraw.Draw(mask)

    # draw outer shape in white (color) and inner shape in black (transparent)
    offset, fill = (width / -2.0, '#6884ae')
    left, top = [(value + offset) * antialias for value in bounds[:2]]
    right, bottom = [(value - offset) * antialias for value in bounds[2:]]
    draw.ellipse([left, top, right, bottom], fill=fill)

    # downsample the mask using PIL.Image.LANCZOS (a high-quality downsampling filter)
    mask = mask.resize(image.size, Image.LANCZOS)

    # paste outline color to input image through the mask
    image.paste(outline, mask=mask)
예제 #7
0
 def setUp(self):
     self.base_path = file_utils.get_file_dir(__file__)
     self.csv = self.csv('./data/stops.csv', "stop_code")
예제 #8
0
 def get_test_data():
     dir = file_utils.get_file_dir(__file__)
     dir = file_utils.get_parent_dir(dir)
     file = os.path.join(dir, 'tests', 'data', 'portland.osm')
     return file