Skip to content
This repository was archived by the owner on Jan 4, 2021. It is now read-only.

Commit 0f639fa

Browse files
author
totokaka
committed
Some fixing of importing and exporting
1 parent 1d7cd05 commit 0f639fa

File tree

4 files changed

+32
-12
lines changed

4 files changed

+32
-12
lines changed

mcman/commands/export.py

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ def __init__(self, args):
4141

4242
args.types = args.types.split(',')
4343

44+
if args.quiet:
45+
self.printer = lambda *a, **b: None
46+
4447
self.run()
4548

4649
def run(self):

mcman/commands/import_cmd.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import json
2525

2626
import os
27+
from sys import stdin
28+
2729
import mcman.logic.servers as s_backend
2830
from mcman.logic.plugins import plugins as p_backend
2931
from mcman.logic import common
@@ -45,7 +47,9 @@ def __init__(self, args):
4547

4648
def run(self):
4749
""" Run the command. """
48-
self.p_main('Parsing file and finding plugins and servers')
50+
if self.args.input is not stdin:
51+
self.p_main('Parsing file and finding plugins and servers')
52+
4953
document = json.loads('\n'.join(self.args.input))
5054

5155
plugins = document['plugins']
@@ -59,13 +63,15 @@ def run(self):
5963
self.parse_plugins(plugins, remote_plugins)
6064
self.parse_servers(servers, remote_servers)
6165

62-
self.p_main('Downloading servers and plugins')
66+
self.p_main('Downloading servers and plugins'
67+
+ ' to {}'.format(self.args.destination)
68+
if self.args.destination != './' else '')
6369
prefix = '({{part:>{}}}/{}) '.format(
6470
len(str(len(self.to_download))), len(self.to_download))
6571
for i in range(len(self.to_download)):
6672
jar = self.to_download[i]
6773
this_prefix = prefix.format(part=i+1)
68-
destination = jar[0]
74+
destination = self.args.destination + '/' + jar[0]
6975
if jar[1].endswith('.zip'):
7076
destination = jar[1].split('/')[-1]
7177
common.download(jar[1], destination=destination, checksum=jar[2],

mcman/logic/plugins/plugins.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import os
2020
import threading
2121
from queue import Queue
22-
from zipfile import ZipFile
22+
from zipfile import ZipFile, BadZipFile
2323

2424
import bukget
2525
import yaml
@@ -305,16 +305,19 @@ def parse_installed_plugins_worker(jar_queue, result_queue):
305305

306306
checksum = common.checksum_file(jar)
307307

308-
with ZipFile(jar, 'r') as zipped:
309-
if 'plugin.yml' not in zipped.namelist():
310-
continue
308+
try:
309+
with ZipFile(jar, 'r') as zipped:
310+
if 'plugin.yml' not in zipped.namelist():
311+
continue
311312

312-
yml = yaml.load(zipped.read('plugin.yml').decode())
313-
plugin_name = yml['name']
314-
main = yml['main']
315-
version = str(yml['version'])
313+
yml = yaml.load(zipped.read('plugin.yml').decode())
314+
plugin_name = yml['name']
315+
main = yml['main']
316+
version = str(yml['version'])
316317

317-
result_queue.put((checksum, main, plugin_name, version, jar))
318+
result_queue.put((checksum, main, plugin_name, version, jar))
319+
except BadZipFile:
320+
print(" Could not read '{}'.".format(jar))
318321

319322
jar_queue.task_done()
320323

mcman/mcman.py

+8
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ def setup_import_command(sub_parsers, parent):
4646
help=('the json file contating the server and plugin information. '
4747
'"-" may be used to mark stdin'))
4848

49+
parser.add_argument(
50+
'destination', default='./', nargs='?',
51+
help='the destination folder. defaults to ./')
52+
4953
return parser
5054

5155

@@ -68,6 +72,10 @@ def setup_export_command(sub_parsers, parent):
6872
'--types', default='plugins,servers',
6973
help='what to save. A comma separated list of "servers" and "plugins"')
7074

75+
parser.add_argument(
76+
'--quiet', action='store_true',
77+
help="don't print anything other than the result")
78+
7179
return parser
7280

7381

0 commit comments

Comments
 (0)