diff options
author | Lars Wirzenius <liw@liw.fi> | 2016-02-12 13:09:35 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2016-02-12 13:30:44 +0200 |
commit | 379388673da6e6fb867d957b81e0733b6efd60e6 (patch) | |
tree | ebf9765b3e3225a9d5fdcb609c2b4554d723d04b /yarnstep.py | |
parent | 5b44086e0b6a60433df9ae27b56c5f52fdc2a5df (diff) | |
download | genbackupdata-379388673da6e6fb867d957b81e0733b6efd60e6.tar.gz |
Add a Python library for making IMPLEMENTS
Diffstat (limited to 'yarnstep.py')
-rw-r--r-- | yarnstep.py | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/yarnstep.py b/yarnstep.py new file mode 100644 index 0000000..1935cc6 --- /dev/null +++ b/yarnstep.py @@ -0,0 +1,60 @@ +# yarnstep.py -- Python code for making yarn IMPLEMENTS sections nicer +# +# This is meant to be imported, not used with yarn --shell-library. +# +# Copyright 2016 Lars Wirzenius +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# =*= License: GPL-3+ =*= + + +import os + +import cliapp + + +_next_match = 1 +def get_next_match(): + global _next_match + name = 'MATCH_{}'.format(_next_match) + _next_match += 1 + return os.environ[name] + + +def get_next_match_as_int(): + return int(get_next_match()) + + +def get_next_match_as_datadir_path(): + return datadir(get_next_match()) + + +def datadir(relative): + return os.path.join(os.environ['DATADIR'], relative) + + +def srcdir(relative): + return os.path.join(os.environ['SRCDIR'], relative) + + +def iter_over_files(root): + for dirname, _, filenames in os.walk(root): + for filename in filenames: + yield os.path.join(dirname, filename) + + +def cat(filename): + with open(filename) as f: + return f.read() |