当前位置: 首页>>代码示例>>Python>>正文


Python mineos.mc函数代码示例

本文整理汇总了Python中mineos.mc函数的典型用法代码示例。如果您正苦于以下问题:Python mc函数的具体用法?Python mc怎么用?Python mc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了mc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: import_server

    def import_server(self, **raw_args):
        args = {k:str(v) for k,v in raw_args.iteritems()}
        server_name = args.pop('server_name')
        retval = None

        response = {
            'result': None,
            'cmd': 'import_server',
            'payload': None
            }

        from pwd import getpwnam
        from grp import getgrgid

        try:
            instance = mc(server_name, self.login, self.base_directory)
            instance.import_server(**args)
            instance = mc(server_name, None, self.base_directory)
            instance.chown(self.login)
            instance.chgrp(getgrgid(getpwnam(self.login).pw_gid).gr_name)
        except (RuntimeError, KeyError, OSError) as ex:
            response['result'] = 'error'
            retval = ex.message
        except CalledProcessError as ex:
            response['result'] = 'error'
            retval = ex.output
        except RuntimeWarning as ex:
            response['result'] = 'warning'
            retval = ex.message
        else:
            response['result'] = 'success'
            retval = "Server '%s' successfully imported" % server_name

        response['payload'] = to_jsonable_type(retval)
        return response 
开发者ID:Partypapa,项目名称:mineos,代码行数:35,代码来源:mounts.py

示例2: check_interval

    def check_interval(self):
        from procfs_reader import path_owner
        from time import sleep

        crons = []
        
        for action in ('backup','archive'):
            for server in mc.list_servers_to_act(action, self.base_directory):
                crons.append( (action, server) )

        for action, server in crons:
            try:
                path_ = os.path.join(self.base_directory, mc.DEFAULT_PATHS['servers'], server)
                getattr(mc(server, path_owner(path_), self.base_directory), 'commit')()
            except Exception:
                pass
        else:
            sleep(len(crons) * mc.COMMIT_DELAY)

        for action, server in crons:
            try:
                path_ = os.path.join(self.base_directory, mc.DEFAULT_PATHS['servers'], server)
                getattr(mc(server, path_owner(path_), self.base_directory), action)()
                sleep(mc.COMMIT_DELAY)
            except Exception:
                pass
开发者ID:AppleDevelopment,项目名称:mineos,代码行数:26,代码来源:server.py

示例3: test_create

    def test_create(self):
        instance = mc('one', **self.instance_arguments)
        instance.create()

        for d in ('cwd','bwd','awd'):
            self.assertTrue(os.path.exists(instance.env[d]))

        for f in ('sp', 'sc'):
            self.assertTrue(os.path.isfile(instance.env[f]))

        self.assertTrue(instance.server_properties[:])
        self.assertTrue(instance.server_config[:])

        with self.assertRaises(RuntimeError):
            self.assertTrue(instance.command_start)
        with self.assertRaises(RuntimeError):
            self.assertIsNone(instance.command_kill)
            
        self.assertTrue(instance.command_backup)
        self.assertTrue(instance.command_archive)
        self.assertTrue(instance.command_restore)

        ''' FIXME: how should prune/apply_profile/wget_profile respond? '''

        instance = mc('two', **self.instance_arguments)
        instance.create({'java':{'java_xmx':2048}}, {'server-port':'27000'})

        self.assertEqual(instance.server_properties['server-port'], '27000')
        self.assertEqual(instance.server_config['java':'java_xmx'], '2048')

        instance = mc('three', **self.instance_arguments)
        instance.create(sc={'java':{'java_bogus': 'wow!'}}, sp={'bogus-value':'abcd'})

        self.assertEqual(instance.server_properties['bogus-value'], 'abcd')
        self.assertEqual(instance.server_config['java':'java_bogus'], 'wow!')
开发者ID:128keaton,项目名称:mineos,代码行数:35,代码来源:test_mineos.py

示例4: display_crontabs

def display_crontabs():
    print '''
    <script type="text/javascript">
    $('.sc').one("click", (function(event){
        event.preventDefault();
        $.post("cgi-bin/server.py", { command: "display",
                                      server: $(this).attr("id"),
                                      page: 'server.config' },
         function(data){ $('#main').html(data); });
    }));
    </script>
    '''
    print '<h2>System Crontabs</h2>'
    print '<p><span class="green">%s</span> servers were located in <span class="green">%s</a>:</p>' % (len(mineos.mc.ports_reserved()),
                                                     mineos.mc().mineos_config['paths']['world_path'])
    print '<pre><b>%s%s%s%s</b><br>' % ('{:<20}'.format('server'),
                                      '{:<14}'.format('archive'),
                                      '{:<14}'.format('backup'),
                                      '{:<14}'.format('map'))

    for server, port, status in mineos.mc.ports_reserved():
        instance = mineos.mc(server)
        print '<a href="#" class="sc stats" id="%s">%s</a>%s%s%s' % (server,
                                                               '{:<20}'.format(server),
                                                               '{:<14}'.format(instance.server_config['crontabs']['freq_archive']),
                                                               '{:<14}'.format(instance.server_config['crontabs']['freq_backup']),
                                                               '{:<14}'.format(instance.server_config['crontabs']['freq_map']))
开发者ID:Fsmv,项目名称:MineOSCrux-Fork,代码行数:27,代码来源:server.py

示例5: test_sc_defaults

    def test_sc_defaults(self):
        from conf_reader import config_file
        instance = mc('one', **self.instance_arguments)
        instance.create(sc={'java':{'java-bin':'isworking'}})
        
        conf = config_file(instance.env['sc'])
        self.assertTrue(conf._use_sections)
        self.assertEqual(conf['java':'java-bin'], 'isworking')

        instance = mc('one', **self.instance_arguments)
        self.assertTrue(conf._use_sections)
        self.assertEqual(instance.server_config['java':'java-bin'], 'isworking')
开发者ID:128keaton,项目名称:mineos,代码行数:12,代码来源:test_mineos.py

示例6: test_sp_defaults

 def test_sp_defaults(self):
     from conf_reader import config_file
     instance = mc('one', **self.instance_arguments)
     instance.create(sp={'server-ip':'127.0.0.1'})
     
     conf = config_file(instance.env['sp'])
     self.assertFalse(conf._use_sections)
     self.assertEqual(conf['server-ip'],'127.0.0.1')
     
     instance = mc('one', **self.instance_arguments)
     self.assertFalse(conf._use_sections)
     self.assertEqual(instance.server_properties['server-ip'], '127.0.0.1')
开发者ID:128keaton,项目名称:mineos,代码行数:12,代码来源:test_mineos.py

示例7: test_prune

    def test_prune(self):
        instance = mc('one', **self.instance_arguments)
        instance.create()

        for d in ('cwd','bwd','awd'):
            self.assertTrue(os.path.exists(instance.env[d]))

        instance.backup() #0 incr
        self.assertEqual(len(instance.list_increments().increments), 0)

        instance._command_direct('touch me', instance.env['cwd'])
        self.assertTrue(os.path.isfile(os.path.join(instance.env['cwd'], 'me')))

        time.sleep(1.1)
        instance.backup() #1 incr
        self.assertEqual(len(instance.list_increments().increments), 1)

        instance._command_direct('touch you', instance.env['cwd'])
        self.assertTrue(os.path.isfile(os.path.join(instance.env['cwd'], 'you')))
        
        time.sleep(1.2)
        instance.backup() #2 incr

        self.assertEqual(len(instance.list_increments().increments), 2)
        instance.prune(1)
        self.assertEqual(len(instance.list_increments().increments), 1)

        instance.prune('now')
        self.assertEqual(len(instance.list_increments().increments), 0)
开发者ID:128keaton,项目名称:mineos,代码行数:29,代码来源:test_mineos.py

示例8: test_profiles

    def test_profiles(self):
        global VANILLA_PROFILE

        mc._make_skeleton(self.instance_arguments['base_directory'])
        instance = mc('one', **self.instance_arguments)
        instance.create()

        self.assertIsNone(instance.profile)
        with self.assertRaises(KeyError): instance.profile = 'vanilla'

        instance.define_profile(VANILLA_PROFILE)
        instance.update_profile(VANILLA_PROFILE['name'])
        
        self.assertTrue(os.path.exists(os.path.join(instance.env['pwd'],
                                                    VANILLA_PROFILE['name'])))
        
        self.assertFalse(os.path.isfile(os.path.join(instance.env['pwd'],
                                                     VANILLA_PROFILE['save_as'])))

        self.assertTrue(os.path.isfile(os.path.join(instance.env['pwd'],
                                                    VANILLA_PROFILE['name'],
                                                    VANILLA_PROFILE['run_as'])))

        from copy import copy
        newprofile = copy(VANILLA_PROFILE)
        newprofile['run_as'] = 'minecraft_server.1.6.2.jar'
        
        instance.define_profile(newprofile)
        
        self.assertEqual(instance.profile_config['vanilla':'run_as'],
                         'minecraft_server.1.6.2.jar')
开发者ID:128keaton,项目名称:mineos,代码行数:31,代码来源:test_mineos.py

示例9: delete_server

    def delete_server(self, **raw_args):
        args = {k:str(v) for k,v in raw_args.iteritems()}
        server_name = args.pop('server_name')
        retval = None

        response = {
            'result': None,
            'cmd': 'delete_server',
            'payload': None
            }

        try:
            if mc.has_server_rights(self.login, server_name, self.base_directory):
                instance = mc(server_name, None, self.base_directory)
                instance.delete_server()
            else:
                raise OSError('Server deletion failed. Only the server owner or root may delete servers.')
        except (RuntimeError, KeyError, OSError) as ex:
            response['result'] = 'error'
            retval = ex.message
        except CalledProcessError as ex:
            response['result'] = 'error'
            retval = ex.output
        except RuntimeWarning as ex:
            response['result'] = 'warning'
            retval = ex.message
        else:
            response['result'] = 'success'
            retval = "Server '%s' deleted" % server_name

        response['payload'] = to_jsonable_type(retval)
        return response     
开发者ID:Partypapa,项目名称:mineos,代码行数:32,代码来源:mounts.py

示例10: display_server_properties

def display_server_properties(server_name):
    print '''
    <script type="text/javascript">
     $('.updatesp').one("click", (function(event){
        event.preventDefault();
        $.post("cgi-bin/server.py", $('#changevalues').serialize(),
             function(data){ $('#main').html(data); });
    }));
    </script>'''

    print '<h2>server.properties for %s</h2>' % server_name

    instance = mineos.mc(server_name)
    filename = os.path.join(instance.mineos_config['paths']['world_path'], server_name, 'server.properties')
    status = instance.status()

    if status in ['up', 'down', 'foreign', 'unclean']:
        print '''<form name="changevalues" id="changevalues">
                    <input name="command" type="hidden" value="act">
                    <input name="action" type="hidden" value="update_sp">
                    <input name="server" type="hidden" value="%s">
                     <table>''' % server_name

        for key, value in mineos.mc.attribute_list(filename):
            print '''
                        <tr> 
                            <td colspan="2"><label for="%s">%s</label></td>
                            <td colspan="2"><input type="text" name="%s" id="%s" value="%s" /></td>
                        </tr>''' % (key.replace('-', '_'),
                                key,
                                key.replace('-', '_'),
                                key.replace('-', '_'),
                                value)
        print '''       <tr>
开发者ID:Fsmv,项目名称:MineOSCrux-Fork,代码行数:34,代码来源:server.py

示例11: test_valid_server_name

    def test_valid_server_name(self):
        bad_names = ['this!', 'another,server', '"hello"',
                     '.minecraft', 'top^sirloin', '[email protected]',
                     'server-with-hyphens','`', '\t',
                     'minecraft 1.6', '']

        ok_names = ['server', 'pvp', '21324', 'server_one',
                    'minecraft1.6', '_a_server']

        for server_name in bad_names:
            with self.assertRaises(ValueError):
                instance = mc(server_name, **self.instance_arguments)

        for server_name in ok_names:
            instance = mc(server_name, **self.instance_arguments)
            self.assertIsNotNone(instance.server_name)
开发者ID:128keaton,项目名称:mineos,代码行数:16,代码来源:test_mineos.py

示例12: check_interval

 def check_interval(self):
     from procfs_reader import path_owner
     
     for action in ('backup','archive'):
         for i in mc.list_servers_to_act(action, self.base_directory):
             path_ = os.path.join(self.base_directory, mc.DEFAULT_PATHS['servers'], i)
             getattr(mc(i, path_owner(path_), self.base_directory), action)()
开发者ID:jmorgensen,项目名称:mineos,代码行数:7,代码来源:server.py

示例13: change_pc_group

    def change_pc_group(self, **raw_args):
        args = {k:str(v) for k,v in raw_args.iteritems()}
        group = args.pop('group')
        retval = None

        response = {
            'result': None,
            'cmd': 'chgrp_pc',
            'payload': None
            }

        try:
            if self.login == 'root':
                instance = mc('throwaway', None, self.base_directory)
                instance.chgrp_pc(group)
            else:
                raise OSError('Group assignment to %s failed. Only the superuser may make change groups.' % group)
        except (RuntimeError, KeyError, OSError) as ex:
            response['result'] = 'error'
            retval = ex.message
        except CalledProcessError as ex:
            response['result'] = 'error'
            retval = ex.output
        except RuntimeWarning as ex:
            response['result'] = 'warning'
            retval = ex.message
        else:
            response['result'] = 'success'
            retval = "profile.config group ownership granted to '%s'" % group

        response['payload'] = to_jsonable_type(retval)
        return response 
开发者ID:Partypapa,项目名称:mineos,代码行数:32,代码来源:mounts.py

示例14: act_update_sp

def act_update_sp(form):
    sp = os.path.join(mineos.mc().mineos_config['paths']['world_path'], form['server'], 'server.properties')
    sc = os.path.join(mineos.mc().mineos_config['paths']['world_path'], form['server'], 'server.config')
    
    for key in form.keys():
        mineos.mc.attribute_change(sp, key.replace('_', '-'), form[key], form['server'])
        
        if key == 'server_port':
            mineos.mc.config_alter(sc, 'minecraft', 'port', form[key], form['server'])
        elif key == 'max_players':
            mineos.mc.config_alter(sc, 'minecraft', key, form[key], form['server'])
            
    print '<pre>'
    for key, value in mineos.mc.attribute_list(sp):
        print '{:<15}'.format(key), '{:<15}'.format(value)
    print '</pre>'
开发者ID:Fsmv,项目名称:MineOSCrux-Fork,代码行数:16,代码来源:server.py

示例15: change_group

    def change_group(self, **raw_args):
        args = {k:str(v) for k,v in raw_args.iteritems()}
        server_name = args.pop('server_name')
        group = args.pop('group')
        retval = None

        response = {
            'result': None,
            'cmd': 'chgrp',
            'payload': None
            }

        try:
            if self.login == mc.has_server_rights(self.login, server_name, self.base_directory) or \
               self.login == 'root':
                instance = mc(server_name, None, self.base_directory)
                instance.chgrp(group)
            else:
                raise OSError('Group assignment to %s failed. Only the owner make change groups.' % group)
        except (RuntimeError, KeyError, OSError) as ex:
            response['result'] = 'error'
            retval = ex.message
        except CalledProcessError as ex:
            response['result'] = 'error'
            retval = ex.output
        except RuntimeWarning as ex:
            response['result'] = 'warning'
            retval = ex.message
        else:
            response['result'] = 'success'
            retval = "Server '%s' group ownership granted to '%s'" % (server_name, group)

        response['payload'] = to_jsonable_type(retval)
        return response 
开发者ID:Partypapa,项目名称:mineos,代码行数:34,代码来源:mounts.py


注:本文中的mineos.mc函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。