Exemplo n.º 1
0
 def _get_scaffold_dir(self, scaffold_name):
     if ':' not in scaffold_name:
         entry_points = pkg_resources.iter_entry_points('tangled.scaffolds')
         for entry_point in entry_points:
             if entry_point.name == scaffold_name:
                 module_name = entry_point.module_name
                 path = entry_point.attrs[0]
                 return asset_path(module_name, path)
         else:
             return None
     return asset_path(scaffold_name)
Exemplo n.º 2
0
 def _get_scaffold_dir(self, scaffold_name):
     if ':' not in scaffold_name:
         entry_points = pkg_resources.iter_entry_points('tangled.scaffolds')
         for entry_point in entry_points:
             if entry_point.name == scaffold_name:
                 module_name = entry_point.module_name
                 path = entry_point.attrs[0]
                 return asset_path(module_name, path)
         else:
             return None
     return asset_path(scaffold_name)
Exemplo n.º 3
0
def load_usps_street_suffixes(user,
                              password,
                              database,
                              host='localhost',
                              port=5432):
    """Load USPS street suffixes into database."""
    file_name = '{model.__tablename__}.csv'.format(model=USPSStreetSuffix)
    path = asset_path('bycycle.core.model', file_name)

    engine = create_engine(user, password, host, port, database)
    session_factory = sessionmaker(bind=engine)
    session = session_factory()

    printer.info('Deleting existing USPS street suffixes...', end=' ')
    count = session.query(USPSStreetSuffix).delete()
    session.commit()
    printer.info(count, 'deleted')

    printer.info('Adding USPS street suffixes...', end=' ')
    with open(path) as fp:
        reader = csv.DictReader(fp)
        records = [USPSStreetSuffix(**row) for row in reader]
    count = len(records)
    session.add_all(records)
    session.commit()
    printer.info(count, 'added')

    session.close()
    engine.dispose()
Exemplo n.º 4
0
 def get_template(self, uri):
     """Allow absolute and asset paths."""
     if os.path.isabs(uri):
         srcfile = uri
     elif ':' in uri:
         srcfile = asset_path(uri)
     else:
         srcfile = None
     if srcfile and os.path.isabs(srcfile):
         try:
             if self.filesystem_checks:
                 return self._check(uri, self._collection[uri])
             else:
                 return self._collection[uri]
         except KeyError:
             if os.path.isfile(srcfile):
                 return self._load(srcfile, uri)
     return super().get_template(uri)
Exemplo n.º 5
0
 def get_template(self, uri):
     """Allow absolute and asset paths."""
     if os.path.isabs(uri):
         srcfile = uri
     elif ':' in uri:
         srcfile = asset_path(uri)
     else:
         srcfile = None
     if srcfile and os.path.isabs(srcfile):
         try:
             if self.filesystem_checks:
                 return self._check(uri, self._collection[uri])
             else:
                 return self._collection[uri]
         except KeyError:
             if os.path.isfile(srcfile):
                 return self._load(srcfile, uri)
     return super().get_template(uri)
Exemplo n.º 6
0
 def test_asset_path_for_module(self):
     path = util.asset_path('tangled.util')
     self.assertTrue(path.endswith('/tangled/tangled'))
Exemplo n.º 7
0
 def test_asset_path_with_base_rel_path(self):
     path = util.asset_path('tangled.util:dir', 'file')
     self.assertTrue(path.endswith('/tangled/tangled/dir/file'))
Exemplo n.º 8
0
 def test_asset_path_for_module(self):
     path = util.asset_path('tangled.util')
     self.assertTrue(path.endswith('/tangled/tangled/util'))
Exemplo n.º 9
0
 def test_asset_path_with_base_rel_path(self):
     path = util.asset_path('tangled.util:dir', 'file')
     self.assertTrue(path.endswith('/tangled/tangled/util/dir/file'))
Exemplo n.º 10
0
 def test_asset_path_with_rel_path(self):
     path = util.asset_path('tangled.util', 'dir/file')
     self.assertTrue(path.endswith('/tangled/tangled/util/dir/file'))