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

Commit a45dbae

Browse files
author
totokaka
committed
Some more code quality
1 parent 1958433 commit a45dbae

File tree

3 files changed

+51
-53
lines changed

3 files changed

+51
-53
lines changed

mcman/backend/common.py

+40
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,43 @@ def ask(question, default=True, skip=False):
247247
return default
248248
else:
249249
return 'y' in answer.lower()
250+
251+
252+
def type_fits(has, requires):
253+
""" Return whether the `has` version is compatible with the `requires`. """
254+
has = has.lower()
255+
requires = requires.lower()
256+
if requires == 'latest' or has == 'release':
257+
return True
258+
elif has == requires:
259+
return True
260+
elif requires == 'release':
261+
return False
262+
elif requires == 'alpha' and has == 'beta':
263+
return True
264+
return False
265+
266+
267+
def format_name(name):
268+
""" Format the name.
269+
270+
If the name consists of multiple words they will be capitalized and put
271+
together without spaces.
272+
273+
"""
274+
if ' ' in name:
275+
words = name.split(' ')
276+
name = ''.join([w.capitalize() for w in words])
277+
return name
278+
279+
280+
def find_plugins_folder():
281+
""" Find the plugins folder.
282+
283+
This will return the relative path to the plugins folder.
284+
Currently either '.' or 'plugins' is returend.
285+
286+
"""
287+
if 'plugins' in os.listdir('.'):
288+
return 'plugins'
289+
return '.'

mcman/backend/plugins.py

+1-40
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import yaml
2323
from queue import Queue
2424
from zipfile import ZipFile
25+
from mcman.backend.common import type_fits, format_name, find_plugins_folder
2526
from mcman.backend import common as utils
2627

2728

@@ -399,18 +400,6 @@ def list_plugins(workers=4):
399400
return results
400401

401402

402-
def find_plugins_folder():
403-
""" Find the plugins folder.
404-
405-
This will return the relative path to the plugins folder.
406-
Currently either '.' or 'plugins' is returend.
407-
408-
"""
409-
if 'plugins' in os.listdir('.'):
410-
return 'plugins'
411-
return '.'
412-
413-
414403
def select_newest_version(plugin, v_type="Release"):
415404
""" Return the newest version in plugin which is compatible `v_type`. """
416405
for version in plugin['versions']:
@@ -432,34 +421,6 @@ def select_installed_version(plugin):
432421
return version
433422

434423

435-
def type_fits(has, requires):
436-
""" Return whether the `has` version is compatible with the `requires`. """
437-
has = has.lower()
438-
requires = requires.lower()
439-
if requires == 'latest' or has == 'release':
440-
return True
441-
elif has == requires:
442-
return True
443-
elif requires == 'release':
444-
return False
445-
elif requires == 'alpha' and has == 'beta':
446-
return True
447-
return False
448-
449-
450-
def format_name(name):
451-
""" Format the name.
452-
453-
If the name consists of multiple words they will be capitalized and put
454-
together without spaces.
455-
456-
"""
457-
if ' ' in name:
458-
words = name.split(' ')
459-
name = ''.join([w.capitalize() for w in words])
460-
return name
461-
462-
463424
def remove_duplicate_plugins(plugins, field='slug'):
464425
""" Return a new list without duplicates.
465426

mcman/mcman.py

+10-13
Original file line numberDiff line numberDiff line change
@@ -286,22 +286,19 @@ def main():
286286

287287
if args.show_version:
288288
print('Version: {}'.format(mcman.__version__))
289-
# If there no command or subcommand is specified we print the help
290-
if not 'command' in args:
289+
elif not 'command' in args:
291290
parser.print_help()
292-
return
293-
if not 'subcommand' in args:
291+
elif not 'subcommand' in args:
294292
if args.command is PluginsCommand:
295293
plugin_parser.print_help()
296294
elif args.command is ServersCommand:
297295
server_parser.print_help()
298-
return
296+
else:
297+
if 'ignored' in args and args.ignored is None:
298+
args.ignored = []
299299

300-
if 'ignored' in args and args.ignored is None:
301-
args.ignored = []
302-
303-
try:
304-
args.command(args)
305-
except KeyboardInterrupt:
306-
print()
307-
return
300+
try:
301+
args.command(args)
302+
except KeyboardInterrupt:
303+
print()
304+
return

0 commit comments

Comments
 (0)