mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-11-06 15:30:28 +03:00
More improvements to yaml writing
This commit is contained in:
parent
9c5b5f7b60
commit
ac37e3084e
2 changed files with 80 additions and 56 deletions
|
|
@ -19,7 +19,7 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from argparse import ArgumentParser
|
||||
import sys
|
||||
import os
|
||||
import logging
|
||||
import StringIO
|
||||
|
||||
|
|
@ -39,7 +39,7 @@ 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',
|
||||
parser.add_argument("-t", "--to", default=None,
|
||||
help="Rewrite to a specific format")
|
||||
parser.add_argument("appid", nargs='*', help="app-id in the form APPID")
|
||||
options = parser.parse_args()
|
||||
|
|
@ -50,16 +50,25 @@ def main():
|
|||
allapps = metadata.read_metadata(xref=True)
|
||||
apps = common.read_app_args(options.appid, allapps, False)
|
||||
|
||||
if options.list and options.to:
|
||||
if options.list and options.to is not None:
|
||||
parser.error("Cannot use --list and --to at the same time")
|
||||
|
||||
supported = ['txt', 'yaml']
|
||||
|
||||
if options.to is not None and options.to not in supported:
|
||||
parser.error("Must give a valid format to --to")
|
||||
|
||||
for appid, app in apps.iteritems():
|
||||
metadatapath = app['metadatapath']
|
||||
base, ext = common.get_extension(metadatapath)
|
||||
if not options.to and ext not in ['txt', 'yaml']:
|
||||
if not options.to and ext not in supported:
|
||||
logging.info("Ignoring %s file at '%s'" % (ext, metadatapath))
|
||||
continue
|
||||
logging.debug("Rewriting " + metadatapath)
|
||||
|
||||
to_ext = ext
|
||||
if options.to is not None:
|
||||
to_ext = options.to
|
||||
|
||||
if options.list:
|
||||
s = StringIO.StringIO()
|
||||
# TODO: currently reading entire file again, should reuse first
|
||||
|
|
@ -73,14 +82,11 @@ def main():
|
|||
print(metadatapath)
|
||||
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
|
||||
with open(base + '.' + to_ext, 'w') as f:
|
||||
metadata.write_metadata(to_ext, f, app)
|
||||
|
||||
if ext != to_ext:
|
||||
os.remove(metadatapath)
|
||||
|
||||
logging.debug("Finished.")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue