예제 #1
0
 def reset_settings(self, old_obj):
     for option in Option.objects.filter(server=self):
         option.delete()
     for tune in Tune.objects.filter(server=self):
         tune.delete()
     for vote in Vote.objects.filter(server=self):
         vote.delete()
     for rcon_command in RconCommand.objects.filter(server=self):
         rcon_command.delete()
     for available_rcon_command in AvailableRconCommand.objects.filter(server=self):
         available_rcon_command.delete()
     config_path = os.path.join(MEDIA_ROOT, 'mods', self.mod.title, 'config.cfg')
     config = TwConfig(config_path)
     config.read()
     for key, value in config.options.iteritems():
         widget = 1  # text
         for widget_type in Option.WIDGET_CHOICES:
             if widget_type[1] == value[1]:
                 widget = widget_type[0]
         data = Option(server=self, command=key, value=value[0], widget=widget)
         data.save()
     for tune in config.tunes:
         data = Tune(server=self, command=tune['command'], value=tune['value'])
         data.save()
     for vote in config.votes:
         data = Vote(server=self, command=vote['command'], title=vote['title'])
         data.save()
     for rcon_command in config.available_rcon_commands:
         data = AvailableRconCommand(server=self, command=rcon_command)
         data.save()
     # copy maps if there are already some
     if old_obj:
         server_maps_path = os.path.join(MEDIA_ROOT, 'mods', old_obj.mod.title, 'servers', old_obj.owner.username, '{0}'.format(old_obj.id), old_obj.random_key, 'maps')
         if os.path.exists(server_maps_path):
             maps = [_file for _file in os.listdir(server_maps_path) if os.path.splitext(_file)[1].lower() == '.map']
             for _map in maps:
                 new_server_maps_path = os.path.join(MEDIA_ROOT, 'mods', self.mod.title, 'servers', self.owner.username, '{0}'.format(self.id), self.random_key, 'maps')
                 if not os.path.exists(new_server_maps_path):
                     os.makedirs(new_server_maps_path)
                 copyfile(os.path.join(server_maps_path, _map), os.path.join(new_server_maps_path, _map))
             rmtree(os.path.join(MEDIA_ROOT, 'mods', old_obj.mod.title, 'servers', old_obj.owner.username))
     # copy default mod maps
     maps_path = os.path.join(MEDIA_ROOT, 'mods', self.mod.title, 'data', 'maps')
     if os.path.exists(maps_path):
         maps = [_file for _file in os.listdir(maps_path) if os.path.splitext(_file)[1].lower() == '.map']
         for _map in maps:
             map_obj = Map.objects.filter(server=self, name=os.path.splitext(_map)[0])
             if not map_obj:
                 map_obj = Map(server=self, name=os.path.splitext(_map)[0])
                 map_obj.save()
                 server_maps_path = os.path.join(MEDIA_ROOT, 'mods', self.mod.title, 'servers', self.owner.username, '{0}'.format(self.id), self.random_key, 'maps')
                 if not os.path.exists(server_maps_path):
                     os.makedirs(server_maps_path)
                 copyfile(os.path.join(maps_path, _map), os.path.join(server_maps_path, _map))
예제 #2
0
파일: admin.py 프로젝트: kolko/upTee
 def save_model(self, request, obj, form, change):
     obj.save()
     if not obj.is_active:
         obj.set_offline()
     if not change:
         mod_path = os.path.join(MEDIA_ROOT, "mods", obj.mod.title)
         config_path = os.path.join(mod_path, "config.cfg")
         config = TwCongig(config_path)
         config.read()
         for key, value in config.options.iteritems():
             widget = 1  # text
             for widget_type in Option.WIDGET_CHOICES:
                 if widget_type[1] == value[1]:
                     widget = widget_type[0]
             data = Option(server=obj, command=key, value=value[0], widget=widget)
             data.save()
         for tune in config.tunes:
             data = Tune(server=obj, command=tune["command"], value=tune["value"])
             data.save()
         for vote in config.votes:
             data = Vote(server=obj, command=vote["command"], title=vote["title"])
             data.save()
     maps_path = os.path.join(MEDIA_ROOT, "mods", obj.mod.title, "data", "maps")
     if os.path.exists(maps_path):
         maps = [_file for _file in os.listdir(maps_path) if os.path.splitext(_file)[1].lower() == ".map"]
         for _map in maps:
             map_obj = Map.objects.filter(server=obj, name=os.path.splitext(_map)[0])
             if not map_obj:
                 map_obj = Map(server=obj, name=os.path.splitext(_map)[0])
                 map_obj.save()
             server_maps_path = os.path.join(
                 MEDIA_ROOT, "mods", obj.mod.title, "servers", obj.owner.username, "{0}".format(obj.id), "maps"
             )
             if not os.path.exists(server_maps_path):
                 os.makedirs(server_maps_path)
             copyfile(os.path.join(maps_path, _map), os.path.join(server_maps_path, _map))
예제 #3
0
 def reset_settings(self, old_obj):
     for option in Option.objects.filter(server=self):
         option.delete()
     for tune in Tune.objects.filter(server=self):
         tune.delete()
     for vote in Vote.objects.filter(server=self):
         vote.delete()
     for rcon_command in RconCommand.objects.filter(server=self):
         rcon_command.delete()
     for available_rcon_command in AvailableRconCommand.objects.filter(
             server=self):
         available_rcon_command.delete()
     config_path = os.path.join(MEDIA_ROOT, 'mods', self.mod.title,
                                'config.cfg')
     config = TwConfig(config_path)
     config.read()
     for key, value in config.options.iteritems():
         widget = 1  # text
         for widget_type in Option.WIDGET_CHOICES:
             if widget_type[1] == value[1]:
                 widget = widget_type[0]
         data = Option(server=self,
                       command=key,
                       value=value[0],
                       widget=widget)
         data.save()
     for tune in config.tunes:
         data = Tune(server=self,
                     command=tune['command'],
                     value=tune['value'])
         data.save()
     for vote in config.votes:
         data = Vote(server=self,
                     command=vote['command'],
                     title=vote['title'])
         data.save()
     for rcon_command in config.available_rcon_commands:
         data = AvailableRconCommand(server=self, command=rcon_command)
         data.save()
     # copy maps if there are already some
     if old_obj:
         server_maps_path = os.path.join(MEDIA_ROOT, 'mods',
                                         old_obj.mod.title, 'servers',
                                         old_obj.owner.username,
                                         '{0}'.format(old_obj.id),
                                         old_obj.random_key, 'maps')
         if os.path.exists(server_maps_path):
             maps = [
                 _file for _file in os.listdir(server_maps_path)
                 if os.path.splitext(_file)[1].lower() == '.map'
             ]
             for _map in maps:
                 new_server_maps_path = os.path.join(
                     MEDIA_ROOT, 'mods', self.mod.title, 'servers',
                     self.owner.username, '{0}'.format(self.id),
                     self.random_key, 'maps')
                 if not os.path.exists(new_server_maps_path):
                     os.makedirs(new_server_maps_path)
                 copyfile(os.path.join(server_maps_path, _map),
                          os.path.join(new_server_maps_path, _map))
             rmtree(
                 os.path.join(MEDIA_ROOT, 'mods', old_obj.mod.title,
                              'servers', old_obj.owner.username))
     # copy default mod maps
     maps_path = os.path.join(MEDIA_ROOT, 'mods', self.mod.title, 'data',
                              'maps')
     if os.path.exists(maps_path):
         maps = [
             _file for _file in os.listdir(maps_path)
             if os.path.splitext(_file)[1].lower() == '.map'
         ]
         for _map in maps:
             map_obj = Map.objects.filter(server=self,
                                          name=os.path.splitext(_map)[0])
             if not map_obj:
                 map_obj = Map(server=self, name=os.path.splitext(_map)[0])
                 map_obj.save()
                 server_maps_path = os.path.join(MEDIA_ROOT, 'mods',
                                                 self.mod.title, 'servers',
                                                 self.owner.username,
                                                 '{0}'.format(self.id),
                                                 self.random_key, 'maps')
                 if not os.path.exists(server_maps_path):
                     os.makedirs(server_maps_path)
                 copyfile(os.path.join(maps_path, _map),
                          os.path.join(server_maps_path, _map))