Add basic yaml metadata writing

This commit is contained in:
Daniel Martí 2015-10-04 00:03:02 -07:00
parent 082e275aa1
commit 1aa891c4fd
3 changed files with 160 additions and 96 deletions

View file

@ -19,6 +19,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from argparse import ArgumentParser
import sys
import logging
import StringIO
@ -38,6 +39,8 @@ def main():
common.setup_global_opts(parser)
parser.add_argument("-l", "--list", action="store_true", default=False,
help="List files that would be reformatted")
parser.add_argument("-t", "--to", default='txt',
help="Rewrite to a specific format")
parser.add_argument("appid", nargs='*', help="app-id in the form APPID")
options = parser.parse_args()
@ -47,12 +50,14 @@ def main():
allapps = metadata.read_metadata(xref=True)
apps = common.read_app_args(options.appid, allapps, False)
if options.list and options.to:
parser.error("Cannot use --list and --to at the same time")
for appid, app in apps.iteritems():
metadatapath = app['metadatapath']
ext = common.get_extension(metadatapath)
if ext not in ['txt']:
logging.info("Ignoring %s file at '%s'"
% (ext.upper(), metadatapath))
base, ext = common.get_extension(metadatapath)
if not options.to and ext not in ['txt', 'yaml']:
logging.info("Ignoring %s file at '%s'" % (ext, metadatapath))
continue
logging.debug("Rewriting " + metadatapath)
if options.list:
@ -66,9 +71,16 @@ def main():
s.close()
if content != cur_content:
print(metadatapath)
else:
with open(metadatapath, 'w') as f:
continue
if options.to == 'txt':
with open(base+'.txt', 'w') as f:
metadata.write_txt_metadata(f, app)
elif options.to == 'yaml':
# with open(base+'.yaml', 'w') as f:
# metadata.write_yaml_metadata(f, app)
metadata.write_yaml_metadata(sys.stdout, app)
break
logging.debug("Finished.")