Ejemplo n.º 1
0
def main(*args):
    try:
        parser = argparse.ArgumentParser()
        parser.add_argument('--debug',
                            help="Running in debug mode",
                            action="store_true")
        parsed = parser.parse_args()

        config = IMConfig(sys.platform)
        setup_logger(config, parsed.debug)
        log = logging.getLogger(__name__)
        lock_filename = "islands_lock"
        lock_filepath = os.path.join(tempfile.gettempdir(), lock_filename)
        lock = fasteners.InterProcessLock(lock_filepath)
        gotten = lock.acquire(blocking=False)
        if gotten:
            application = Application(config)
            application.run()
        else:
            log.info(
                "Another instance of Island Manager is already running. Exiting..."
            )
            sys.exit(0)
    except Exception as e:
        msg = "Application has crashed: %s" % str(e)
        print(msg)
        log = logging.getLogger(__name__)
        log.error(msg)
        sys.exit(1)
 def setUp(self):
     config = Config()
     config.pkgdir = 'test/data/res/packages'
     config.schema = 'res/itemschema.json'
     config.localedir = 'test/data/res'
     self.app = Application()
     self.app.setup(config)
Ejemplo n.º 3
0
class TestConfig(unittest.TestCase):

    def setUp(self):
        self.app = Application("../default_config.json", "../config.json")
        self.main_window = self.app.main_window
        self.setup = self.app.setup
        self.island_manager = self.app.island_manager
        self.setup_window = self.main_window.setup_window
        self.setup = self.app.setup

    def test_init_app(self):
        app = Process(target=self.app.run, group=None)
        app.start()
        for i in range(10):
            print ("Sleeping %ds." % i)
            sleep(1)
        self.app.kill()




#def test_progress_bar:





    # self.progress_bar_handler(0, "init", "Testing progress bar")
    #
    # for i in range(100):
    #     self.progress_bar_handler(console_index=0, action="update", progress_in_percents=str(i), ratio="%d/100" % i)
    #     sleep()
Ejemplo n.º 4
0
 def setUp(self):
     self.app = Application("../default_config.json", "../config.json")
     self.main_window = self.app.main_window
     self.setup = self.app.setup
     self.island_manager = self.app.island_manager
     self.setup_window = self.main_window.setup_window
     self.setup = self.app.setup
Ejemplo n.º 5
0
 def setUp(self):
     config = Config()
     config.guipkg = 'test/data/res/packages/gui.pkg'
     config.scriptspkg = 'test/data/res/packages/scripts.pkg'
     config.localedir = 'test/data/res'
     config.schema = 'res/itemschema.json'
     self.app = Application()
     self.app.setup(config)
 def setUp(self):
     from lib.config import Config
     from lib.application import Application
     config = Config()
     config.guipkg = 'test/data/res/packages/gui.pkg'
     config.scriptspkg = 'test/data/res/packages/scripts.pkg'
     config.localedir = 'test/data/res'
     self.app = Application()
     self.app.setup(config)
 def setUp(self):
     config = Config()
     config.guipkg = 'test/data/res/packages/gui.pkg'
     config.scriptspkg = 'test/data/res/packages/scripts.pkg'
     config.schema = 'res/itemschema.json'
     config.localedir = 'test/data/res'
     config.outputjson = True
     app = Application()
     app.setup(config)
     self.dropdownlist = DropdownList(app)
 def test_application(self):
     config = Config()
     config.guipkg = 'test/data/res/packages/gui.pkg'
     config.scriptspkg = 'test/data/res/packages/scripts.pkg'
     config.localedir = 'test/data/res'
     app = Application()
     vpath = app.setupVPath(config)
     result = vpath.getPathInfo('gui/gui_settings.xml')
     self.assertEqual('gui/gui_settings.xml', result.path)
     self.assertEqual('test/data/res/packages/gui.pkg', result.pkg)
class ApplicationTranslateTestCase(unittest.TestCase):
    def setUp(self):
        config = Config()
        config.localedir = 'test/data/res'
        config.pkgdir = 'test/data/res/packages'
        self.app = Application()
        self.app.setup(config)

    def test_transalte(self):
        self.assertEqual('T-34',
                         self.app.gettext.translate('#ussr_vehicles:T-34'))
class ApplicationVPathTestCase(unittest.TestCase):
    def setUp(self):
        from lib.config import Config
        from lib.application import Application
        config = Config()
        config.guipkg = 'test/data/res/packages/gui.pkg'
        config.scriptspkg = 'test/data/res/packages/scripts.pkg'
        config.localedir = 'test/data/res'
        self.app = Application()
        self.app.setup(config)

    def test_vpath(self):
        vpath = VPath(pkgdir='c:/Games/World_of_Tanks_ASIA/res/packages',
                      guidir='./test')
        self.assertEqual('T-34',
                         self.app.gettext.translate('#ussr_vehicles:T-34'))
Ejemplo n.º 11
0
 def setUp(self):
     config = Config()
     config.guipkg = 'test/data/res/packages/gui.pkg'
     config.scriptspkg = 'test/data/res/packages/scripts.pkg'
     config.schema = 'res/itemschema.json'
     config.localedir = 'test/data/res'
     app = Application()
     app.setup(config)
     self.resource = app.resource
     self.ctx = {
         'nation': 'ussr',
         'vehicle': 'R04_T-34',
         'vehicle_siege': 'R04_T-34',
         'chassis': 'T-34_mod_1943',
         'turret': 'T-34_mod_1942',
         'engine': 'V-2-34',
         'radio': '_9RM',
         'gun': '_76mm_S-54'
     }
Ejemplo n.º 12
0
    def show(self):
        self.setWindowOpacity(0.0)
        self.animation.setDuration(150)
        self.animation.setStartValue(0.0)
        self.animation.setEndValue(1.0)

        self.setGeometry(
            QApplication.desktop(
                Application.get_app()).availableGeometry().width() - 36 -
            self.width(), +QApplication.desktop())
class ResourceFactoryTestCase_1(unittest.TestCase):
    def setUp(self):
        config = Config()
        config.pkgdir = 'test/data/res/packages'
        config.schema = 'res/itemschema.json'
        config.localedir = 'test/data/res'
        self.app = Application()
        self.app.setup(config)

    def test_0_appenv(self):
        result = self.app.resource.vpath.getPathInfo('gui')
        self.assertEqual('test/data/res/packages/gui.pkg', result.pkg)

    def test_ResourceXml_1(self):
        desc = {
            "file": "gui/gui_settings.xml",
            "xpath": "setting/[name='nations_order']/value/item"
        }
        expect = [
            'germany', 'ussr', 'usa', 'japan', 'china', 'uk', 'france',
            'czech', 'poland', 'italy', 'sweden'
        ]
        resource = ResourceFactory(self.app).create(desc)
        self.assertEqual(expect, resource.getValue())
 def test_setupGettext(self):
     config = Config()
     config.localedir = 'missing'
     app = Application()
     self.assertRaises(FileNotFoundError, app.setupGettext, config)
Ejemplo n.º 15
0
class VehicleInfoTestCase(unittest.TestCase):
    def setUp(self):
        config = Config()
        config.guipkg = 'test/data/res/packages/gui.pkg'
        config.scriptspkg = 'test/data/res/packages/scripts.pkg'
        config.localedir = 'test/data/res'
        config.schema = 'res/itemschema.json'
        self.app = Application()
        self.app.setup(config)

    def test_queryVehicleModule(self):
        result = queryVehicleModule(self.app, 'germany::lt,mt,ht,td', 'shell',
                                    'shell:gravity')
        result = result.asPrimitive()
        self.assertEqual([{'shell:gravity': '9.81'}], result)
        result = queryVehicleModule(self.app,
                                    '::',
                                    'shell',
                                    'shell:gravity',
                                    sort='shell:gravity')
        result = result.asPrimitive()
        self.assertEqual(26, len(result))
        self.assertEqual({'shell:gravity': '9.81'}, result[0])
        self.assertEqual({'shell:gravity': '190'}, result[-1])

    def test_queryVehicleModule_secret(self):
        result = queryVehicleModule(self.app,
                                    'germany:10:td:secret',
                                    None,
                                    'vehicle:index',
                                    sort='vehicle:id')
        result = result.asPrimitive()
        expect = [{
            'vehicle:id': '66',
            'vehicle:index': 'G98_Waffentrager_E100'
        }, {
            'vehicle:id': '190',
            'vehicle:index': 'G98_Waffentrager_E100_P'
        }]
        self.assertEqual(2, len(result))
        self.assertEqual(expect, result)
        result = queryVehicleModule(self.app,
                                    'germany::lt:secret',
                                    None,
                                    'vehicle:index',
                                    sort='vehicle:id')
        result = result.asPrimitive()
        self.assertEqual(7, len(result))
        result = queryVehicleModule(self.app,
                                    'germany:10:lt:secret',
                                    None,
                                    'vehicle:index',
                                    sort='vehicle:id')
        result = result.asPrimitive()
        self.assertEqual(0, len(result))
        self.assertEqual([], result)

    def test_queryVehicleModule_sort(self):
        result = queryVehicleModule(self.app,
                                    'china:2:lt',
                                    'gun',
                                    'turret:index,gun:index',
                                    sort='turret:index,gun:index')
        result = result.asPrimitive()
        expect = [['Turret_1_Ch07_Vickers_MkE_Type_BT26', '_47mm_QFSA'],
                  ['Turret_2_Ch07_Vickers_MkE_Type_BT26', '_40mm_Pom_Pom'],
                  ['Turret_2_Ch07_Vickers_MkE_Type_BT26', '_45mm_20K'],
                  ['Turret_2_Ch07_Vickers_MkE_Type_BT26', '_47mm_QFSA']]
        self.assertEqual(expect,
                         [[v[k] for k in ('turret:index', 'gun:index')]
                          for v in result])
        result = queryVehicleModule(self.app,
                                    'china:2:lt',
                                    'gun',
                                    'gun:index',
                                    sort='turret:index,gun:index')
        result = result.asPrimitive()
        expect = ['_47mm_QFSA', '_40mm_Pom_Pom', '_45mm_20K']
        self.assertEqual(expect, [v['gun:index'] for v in result])
        result = queryVehicleModule(self.app,
                                    'ussr:4:lt',
                                    None,
                                    'vehicle:userString',
                                    sort='vehicle:userString')
        result = result.asPrimitive()
        expect = ['A-20', 'T-80', 'Valentine II']
        self.assertEqual(expect, [v['vehicle:userString'] for v in result])
        result = queryVehicleModule(self.app,
                                    'ussr:4:lt',
                                    None,
                                    'vehicle:userString',
                                    sort=',-vehicle:userString')
        result = result.asPrimitive()
        self.assertEqual(list(reversed(expect)),
                         [v['vehicle:userString'] for v in result])
Ejemplo n.º 16
0
#!/usr/bin/env python3

from lib.application import Application

if __name__ == "__main__":
    app = Application()
    app.launch()
class ResourceFactoryTestCase_2(unittest.TestCase):
    def setUp(self):
        config = Config()
        config.guipkg = 'test/data/res/packages/gui.pkg'
        config.scriptspkg = 'test/data/res/packages/scripts.pkg'
        config.schema = 'res/itemschema.json'
        config.localedir = 'test/data/res'
        self.app = Application()
        self.app.setup(config)

    def test_0_appenv(self):
        result = self.app.resource.vpath.getPathInfo('vehicles')
        self.assertEqual('test/data/res/packages/scripts.pkg', result.pkg)

    def test_ResourceXml_1(self):
        desc = {
            "file": "gui/gui_settings.xml",
            "xpath": "setting/[name='nations_order']/value/item"
        }
        expect = [
            'germany', 'ussr', 'usa', 'japan', 'china', 'uk', 'france',
            'czech', 'poland', 'italy', 'sweden'
        ]
        resource = ResourceFactory(self.app).create(desc)
        self.assertIsInstance(resource, ResourceMeta)
        self.assertIsInstance(resource, ResourceXml)
        self.assertEqual(expect, resource.getValue())

    def test_ResourceXml_2(self):
        desc = {
            "file": "vehicles/{nation}/components/fuelTanks.xml",
            "xpath": "ids/{fueltank}",
            "param": {
                "fueltank": "vehicle:fueltank"
            }
        }
        ctx = {'nation': 'ussr', 'vehicle': 'R04_T-34'}
        resource = ResourceFactory(self.app).create(desc)
        self.assertIsInstance(resource, ResourceXml)
        self.assertEqual(['203'], resource.getValue(ctx))

    def test_ResourceImmediate(self):
        desc = {"immediate": ["LT", "MT", "HT", "TD", "SPG"]}
        expect = ['LT', 'MT', 'HT', 'TD', 'SPG']
        resource = ResourceFactory(self.app).create(desc)
        self.assertIsInstance(resource, ResourceMeta)
        self.assertIsInstance(resource, ResourceImmediate)
        self.assertEqual(expect, resource.getValue())

    def test_ResourceFunction_sum(self):
        desc = {"func": "sum()", "args": ["hull:health", "turret:health"]}
        ctx = {'hull:health': '320', 'turret:health': '130'}
        expect = 450
        resource = ResourceFactory(self.app).create(desc)
        self.assertIsInstance(resource, ResourceMeta)
        self.assertIsInstance(resource, ResourceFunction)
        self.assertEqual(expect, resource.getValue(ctx))

    def test_ResourceFunction_div(self):
        desc = {
            "func": "div()",
            "args": ["engine:power", "vehicle:totalWeight"]
        }
        ctx = {'engine:power': '500', 'vehicle:totalWeight': '29390.0'}
        expect = 500 / 29390
        resource = ResourceFactory(self.app).create(desc)
        self.assertIsInstance(resource, ResourceMeta)
        self.assertIsInstance(resource, ResourceFunction)
        self.assertEqual(expect, resource.getValue(ctx))

    def test_ResourceFunction_mul(self):
        desc = {
            "func": "mul()",
            "args": ["vehicle:powerWeightRatio", "physics:hpToWatts"]
        }
        ctx = {
            'vehicle:powerWeightRatio': '0.01701258931609391',
            'physics:hpToWatts': '735.5'
        }
        expect = 0.01701258931609391 * 735.5
        resource = ResourceFactory(self.app).create(desc)
        self.assertIsInstance(resource, ResourceMeta)
        self.assertIsInstance(resource, ResourceFunction)
        self.assertEqual(expect, resource.getValue(ctx))

    def test_ResourceFunction_join(self):
        desc = {
            "func":
            "join()",
            "args": [
                "vehicle:maxSpeed_hard", "vehicle:maxSpeed_medium",
                "vehicle:maxSpeed_soft"
            ]
        }
        ctx = {
            'vehicle:maxSpeed_hard': '16.6',
            'vehicle:maxSpeed_medium': '14.0',
            'vehicle:maxSpeed_soft': '7.9'
        }
        expect = ['16.6', '14.0', '7.9']
        resource = ResourceFactory(self.app).create(desc)
        self.assertIsInstance(resource, ResourceMeta)
        self.assertIsInstance(resource, ResourceFunction)
        self.assertEqual(expect, resource.getValue(ctx))

    def test_ResourceFunction_or(self):
        desc = {
            "func": "or()",
            "args": ["vehicle:shortUserString", "vehicle:userString"]
        }
        ctx = {'vehicle:shortUserString': None, 'vehicle:userString': 'T-34'}
        expect = 'T-34'
        resource = ResourceFactory(self.app).create(desc)
        self.assertIsInstance(resource, ResourceMeta)
        self.assertIsInstance(resource, ResourceFunction)
        self.assertEqual(expect, resource.getValue(ctx))
        ctx = {
            'vehicle:shortUserString': 'missing',
            'vehicle:userString': 'T-34'
        }
        expect = 'missing'
        resource = ResourceFactory(self.app).create(desc)
        self.assertIsInstance(resource, ResourceMeta)
        self.assertIsInstance(resource, ResourceFunction)
        self.assertEqual(expect, resource.getValue(ctx))

    def test_ResourceFunction_format(self):
        desc = {
            "func": "format('{}: {}')",
            "args": ["shell:kindShort", "shell:userString"]
        }
        ctx = {'shell:kindShort': 'AP', 'shell:userString': 'UBR-354MA'}
        expect = 'AP: UBR-354MA'
        resource = ResourceFactory(self.app).create(desc)
        self.assertIsInstance(resource, ResourceMeta)
        self.assertIsInstance(resource, ResourceFunction)
        self.assertEqual(expect, resource.getValue(ctx))
Ejemplo n.º 18
0
import sys
import io

from lib.config import parseArgument
from lib.application import Application
from lib.widgets import GuiApplication
from lib.dropdownlist import DropdownList

if __name__ == '__main__':
    sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8')
    sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
    sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8')

    config = parseArgument(mode='gui')

    app = Application()
    app.setup(config)
    app.dropdownlist = DropdownList(app)

    gui = GuiApplication(app)
    gui.mainloop()
Ejemplo n.º 19
0
if __name__ == '__main__':
    import sys
    import os.path

    from lib.application import Application

    from PyQt5.QtWidgets import QApplication

    # to be able to close the app from terminal with
    # ctr+c we have to do the following:
    import signal
    signal.signal(signal.SIGINT, signal.SIG_DFL)
    # ------------------------------------------

    def usage():
        """
        Prints how to use this script.
        """
        print('Can be supplied with a path to some QML script containing a GUI definition.')

    gui = sys.argv[1] if (len(sys.argv) == 2 and os.path.isfile(sys.argv[1])) else 'main.qml'
    app = Application(gui)
    app.run()
 def test_setupSettings(self):
     config = Config()
     config.schema = 'missing'
     app = Application()
     self.assertRaisesRegex(FileNotFoundError, r'not found schema file: ', app.setupSettings, config)
Ejemplo n.º 21
0
    },
    'shell': {
        'show': 'vehicle:index,turret:index,gun:index,shell:index',
        'sort': 'vehicle:nation,vehicle:tier,vehicle:type,vehicle:id',
        'header': 'Vehicle,Turret,Gun,Shell'
    }
}

if __name__ == '__main__':
    logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s')
    logger = logging.getLogger(__name__)
    logger.addHandler(logging.StreamHandler())

    config = parseArgument(mode='cui')

    app = Application()
    app.setup(config)
    if config.list_nation:
        result = app.resource.getValue('settings:nationsOrder')
        print(result)
    elif config.list_tier:
        result = app.resource.getValue('settings:tiersOrder')
        print(result)
    elif config.list_type:
        result = app.resource.getValue('settings:typesOrder')
        print(result)
    elif config.list_tag:
        result = app.settings.schema.keys()

        def f(pattern, string):
            match = re.search(pattern, string)
Ejemplo n.º 22
0
from lib.application import Application

from PyQt5.QtWidgets import QApplication

if __name__ == '__main__':

    # to be able to close the app from terminal with
    # ctr+c we have to do the following:
    import signal
    signal.signal(signal.SIGINT, signal.SIG_DFL)
    # ------------------------------------------

    gui = 'demo.qml'
    app = Application(gui)
    app.run()