Merge "make the cache command write to a file by default"

This commit is contained in:
Jenkins 2016-04-18 12:57:21 +00:00 committed by Gerrit Code Review
commit 79cb9cd5a3
2 changed files with 13 additions and 5 deletions

View File

@ -10,6 +10,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from reno import loader
from reno import scanner from reno import scanner
from reno import utils from reno import utils
@ -62,10 +63,15 @@ def cache_cmd(args):
"Generates a release notes cache" "Generates a release notes cache"
reporoot = args.reporoot.rstrip('/') + '/' reporoot = args.reporoot.rstrip('/') + '/'
notesdir = utils.get_notes_dir(args) notesdir = utils.get_notes_dir(args)
if args.output: if args.output == '-':
stream = open(args.output, 'w')
else:
stream = sys.stdout stream = sys.stdout
close_stream = False
elif args.output:
stream = open(args.output, 'w')
close_stream = True
else:
stream = open(loader.get_cache_filename(reporoot, notesdir), 'w')
close_stream = True
try: try:
cache = build_cache_db( cache = build_cache_db(
reporoot=reporoot, reporoot=reporoot,
@ -83,6 +89,6 @@ def cache_cmd(args):
encoding='utf-8', encoding='utf-8',
) )
finally: finally:
if args.output: if close_stream:
stream.close() stream.close()
return return

View File

@ -127,7 +127,9 @@ def main(argv=sys.argv[1:]):
do_cache.add_argument( do_cache.add_argument(
'--output', '-o', '--output', '-o',
default=None, default=None,
help='output filename, defaults to stdout', help=('output filename, '
'defaults to the cache file within the notesdir, '
'use "-" for stdout'),
) )
_build_query_arg_group(do_cache) _build_query_arg_group(do_cache)
do_cache.set_defaults(func=cache.cache_cmd) do_cache.set_defaults(func=cache.cache_cmd)