def loadPlugins(self, dirname): for name in self._my_list_dir(dirname): m = re.search(r"^(.+)\.py$", name) n = os.path.join(dirname, name) if m and os.path.isfile(n): try: loadGame(m.group(1), n) except Exception as ex: if DEBUG: traceback.print_exc() print_err(_("error loading plugin %s: %s") % (n, ex))
def write_game(app, game=None): import pysollib.customgame # for py2exe pysollib.customgame.no_use() if game is None: # new game d = app.dn.plugins n = 1 while True: fn = os.path.join(d, 'customgame%d.py' % n) # file name mn = 'customgame%d' % n # module name gameid = 200000 + n if not os.path.exists(fn): break n += 1 check_game = True else: # edit current game fn = game.MODULE_FILENAME mn = game.__module__ gameid = game.SETTINGS['gameid'] check_game = False # print '===>', fn with open(fn, 'w') as fd: fd.write('''\ ## -*- coding: utf-8 -*- ## THIS FILE WAS GENERATED AUTOMATICALLY BY THE SOLITAIRE WIZARD ## DO NOT EDIT from pysollib.customgame import CustomGame, registerCustomGame class MyCustomGame(CustomGame): WIZARD_VERSION = 1 SETTINGS = { ''') for w in WizardWidgets: if isinstance(w, six.string_types): continue v = w.variable.get() if w.widget in ('menu', 'preset'): v = w.translation_map[v] if v == w.default: # save only unique values continue if isinstance(v, int): fd.write(" '%s': %i,\n" % (w.var_name, v)) else: if w.var_name == 'name': # escape v = v.replace('\\', '\\\\') v = v.replace("'", "\\'") v = v.replace("\n", "\\n") v = v.replace("\r", "\\r") v = v.replace("\t", "\\t") # See: https://github.com/shlomif/PySolFC/issues/177 # if isinstance(v, six.text_type): # v = v.encode('utf-8') if not v: v = 'Invalid Game Name' fd.write(" '{}': '{}',\n".format(w.var_name, v)) fd.write(" 'gameid': %i,\n" % gameid) fd.write('''\ } registerCustomGame(MyCustomGame) ''') loadGame(mn, fn, check_game=check_game) return gameid
def write_game(app, game=None): import pysollib.customgame # for py2exe if game is None: # new game d = app.dn.plugins ls = os.listdir(d) n = 1 while True: fn = os.path.join(d, 'customgame%d.py' % n) # file name mn = 'customgame%d' % n # module name gameid = 200000 + n if not os.path.exists(fn): break n += 1 check_game = True else: # edit current game fn = game.MODULE_FILENAME mn = game.__module__ gameid = game.SETTINGS['gameid'] check_game = False ##print '===>', fn fd = open(fn, 'w') fd.write('''\ ## -*- coding: utf-8 -*- ## THIS FILE WAS GENERATED AUTOMATICALLY BY SOLITAIRE WIZARD ## DO NOT EDIT from pysollib.customgame import CustomGame, registerCustomGame class MyCustomGame(CustomGame): WIZARD_VERSION = 1 SETTINGS = { ''') for w in WizardWidgets: if isinstance(w, basestring): continue v = w.variable.get() if w.widget in ('menu', 'preset'): v = w.translation_map[v] if v == w.default: # save only unique values continue if isinstance(v, int): fd.write(" '%s': %i,\n" % (w.var_name, v)) else: if w.var_name == 'name': # escape v = v.replace('\\', '\\\\') v = v.replace("'", "\\'") if isinstance(v, unicode): v = v.encode('utf-8') if not v: v = 'Invalid Game Name' fd.write(" '%s': '%s',\n" % (w.var_name, v)) fd.write(" 'gameid': %i,\n" % gameid) fd.write('''\ } registerCustomGame(MyCustomGame) ''') fd.close() loadGame(mn, fn, check_game=check_game) return gameid
def write_game(app, game=None): import pysollib.customgame # for py2exe if game is None: # new game d = app.dn.plugins ls = os.listdir(d) n = 1 while True: fn = os.path.join(d, 'customgame%d.py' % n) # file name mn = 'customgame%d' % n # module name gameid = 200000+n if not os.path.exists(fn): break n += 1 check_game = True else: # edit current game fn = game.MODULE_FILENAME mn = game.__module__ gameid = game.SETTINGS['gameid'] check_game = False ##print '===>', fn fd = open(fn, 'w') fd.write('''\ ## -*- coding: utf-8 -*- ## THIS FILE WAS GENERATED AUTOMATICALLY BY SOLITAIRE WIZARD ## DO NOT EDIT from pysollib.customgame import CustomGame, registerCustomGame class MyCustomGame(CustomGame): WIZARD_VERSION = 1 SETTINGS = { ''') for w in WizardWidgets: if isinstance(w, basestring): continue v = w.variable.get() if w.widget in ('menu', 'preset'): v = w.translation_map[v] if v == w.default: # save only unique values continue if isinstance(v, int): fd.write(" '%s': %i,\n" % (w.var_name, v)) else: if w.var_name == 'name': # escape v = v.replace('\\', '\\\\') v = v.replace("'", "\\'") if isinstance(v, unicode): v = v.encode('utf-8') if not v: v = 'Invalid Game Name' fd.write(" '%s': '%s',\n" % (w.var_name, v)) fd.write(" 'gameid': %i,\n" % gameid) fd.write('''\ } registerCustomGame(MyCustomGame) ''') fd.close() loadGame(mn, fn, check_game=check_game) return gameid