Commit 8af64bf7 authored by Ryan Pavlik's avatar Ryan Pavlik

Add code to find a list of paths for boilerplate

parent 0f9c76a9
#!/usr/bin/python3
# -*- coding: utf-8 -*-
#
# Copyright (c) 2018 Collabora, Ltd.
#
# SPDX-License-Identifier: BSL-1.0
#
# Author(s): Ryan Pavlik <ryan.pavlik@collabora.com>
#
# Purpose: Create a list of 'search paths' for templates
from pathlib import Path
def get_parents(dir=None):
if dir is None:
dir = Path.cwd()
parts = list(dir.parts)
ret = [Path(*(parts[:i+1])) for i in range(len(parts))]
ret.reverse()
return ret
def get_potential_boilerplate_dirs(dir=None):
return [ d/'.boilerplate' for d in get_parents(dir)]
def find_paths():
return [ str(d) for d in get_potential_boilerplate_dirs() if d.exists() and d.is_dir()]
# -*- coding: utf-8 -*-
#
# Copyright (c) 2018 Collabora, Ltd.
#
# SPDX-License-Identifier: BSL-1.0
#
# Author(s): Ryan Pavlik <ryan.pavlik@collabora.com>
from file_boilerplate.find_paths import *
from pathlib import PurePosixPath as PPP
from nose.tools import eq_
def test_decomp():
eq_(len(get_parents(PPP('/a/b/c'))), 4)
def test_order():
eq_(get_parents(PPP('/a/b/c'))[0], PPP('/a/b/c'))
eq_(get_parents(PPP('/a/b/c'))[1], PPP('/a/b'))
eq_(get_parents(PPP('/a/b/c'))[2], PPP('/a'))
eq_(get_parents(PPP('/a/b/c'))[3], PPP('/'))
def test_get_candidates():
eq_(get_potential_boilerplate_dirs(PPP('/a/b/c'))[0], PPP('/a/b/c/.boilerplate'))
eq_(get_potential_boilerplate_dirs(PPP('/a/b/c'))[1], PPP('/a/b/.boilerplate'))
eq_(get_potential_boilerplate_dirs(PPP('/a/b/c'))[2], PPP('/a/.boilerplate'))
eq_(get_potential_boilerplate_dirs(PPP('/a/b/c'))[3], PPP('/.boilerplate'))
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment