本文整理匯總了Python中repository.Repository.set_minecraft_target方法的典型用法代碼示例。如果您正苦於以下問題:Python Repository.set_minecraft_target方法的具體用法?Python Repository.set_minecraft_target怎麽用?Python Repository.set_minecraft_target使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類repository.Repository
的用法示例。
在下文中一共展示了Repository.set_minecraft_target方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: CreepClient
# 需要導入模塊: from repository import Repository [as 別名]
# 或者: from repository.Repository import set_minecraft_target [as 別名]
class CreepClient(Client, cmd.Cmd):
"""Creep Mod Package Manager Client"""
# Version of this client
VERSION = '0.1.2'
# Absolute path where this client is installed
installdir = ''
# Absolute path to the dotfile for this client
appdir = ''
# Absolute path to the minecraft dir
minecraftdir = ''
# Version of minecraft to target for mods
minecraft_target = '1.7.10'
def __init__(self, **kwargs):
"""Constructor"""
cmd.Cmd.__init__(self)
Client.__init__(self, **kwargs)
self.updateVersionWithGitDescribe()
self.updatePaths()
self.load_target()
self.createRepository()
def do_version(self, args):
"""Display creep version"""
print self.colortext("Creep v{}".format(self.VERSION), self.terminal.C_GREEN)
self.display_target()
def do_target(self, args):
"""Set the targeted minecraft version
Usage: creep target <minecraft_version>
Examples:
creep target 1.7.10
Set the version of minecraft for mods
"""
if len(args) > 0:
# TODO: Validate against ~/.minecraft/launcher_profiles.json for valid versions to use
self.minecraft_target = args
self.display_target()
self.repository.set_minecraft_target(self.minecraft_target)
self.save_options()
def display_target(self):
print self.colortext("Targetting minecraft version {}".format(self.minecraft_target), self.terminal.C_GREEN)
def load_target(self):
# TODO: More robust user options file handling. It should be its own object to load options
options_path = self.appdir + os.sep + 'options.json'
if os.path.isfile(options_path):
options = json.load(open(options_path))
self.minecraft_target = options['minecraft_target']
def save_options(self):
options_path = self.appdir + os.sep + 'options.json'
with open(options_path, 'w') as outfile:
json.dump({'minecraft_target': self.minecraft_target}, outfile)
def do_list(self, args):
"""List packages (mods)
Usage: creep list [installed]
Examples:
creep list
List available packages in repository
creep list installed
List installed packages
"""
if args == 'installed':
installdir = self.minecraftdir + os.sep + 'mods' + os.sep + self.minecraft_target
files = []
try:
files = os.listdir(installdir)
except OSError:
pass
if not files:
print self.colortext("Looking in {}".format(installdir), self.terminal.C_YELLOW)
print "No mods installed"
return False
packages = []
unknownfiles = []
for name in files:
package = self.repository.fetch_package_byfilename(name)
if not package:
unknownfiles.append(name)
else:
packages.append(package)
packages.sort(key=attrgetter('name'))
#.........這裏部分代碼省略.........