예제 #1
0
def bootstrapLauncherImages(path):
    notesPath = serverConfig.darksporeLauncherThemesPath()
    launcherFolder = pathUtils.join(notesPath, server.getActiveTheme())
    resourcePath = pathUtils.join(launcherFolder, path)

    filePath = pathUtils.join(
        pathUtils.join(serverConfig.storagePath(), 'www'), resourcePath)
    return send_file(filePath)
예제 #2
0
 def availableThemes(self):
     themesFolder = self.config.darksporeLauncherThemesPath()
     themesFolder = pathUtils.join(pathUtils.join(self.config.storagePath(), 'www'), themesFolder)
     themesFolderContents = os.listdir(themesFolder)
     themesList = []
     for file in themesFolderContents:
         themeFolder = pathUtils.join(themesFolder,file)
         themeFolderIndex = pathUtils.join(themeFolder,"index.html")
         if os.path.isdir(themeFolder) and os.path.isfile(themeFolderIndex):
             themesList.append(file)
     return themesList
예제 #3
0
    def __init__(self):

        self.ckpt_path = utils.CKPT_PATH
        self.gen = generator()
        self.dis = discriminator()

        self.gen.summary()
        self.dis.summary()

        self.gen_optimizer = tf.keras.optimizers.Adam(1e-4)
        self.dis_optimizer = tf.keras.optimizers.Adam(1e-4)

        self.init_epoch = tf.Variable(0)

        self.summary_writer = tf.summary.create_file_writer(utils.SUMMARY_PATH)
        self.ckpt = tf.train.Checkpoint(init_epoch=self.init_epoch,
                                        gen=self.gen,
                                        dis=self.dis,
                                        gen_optimizer=self.gen_optimizer,
                                        dis_optimizer=self.dis_optimizer)
        self.ckpt_manager = tf.train.CheckpointManager(
            self.ckpt, directory=self.ckpt_path, max_to_keep=3)
        self.gen_img_path = path.join(utils.OUTPUT_PATH, 'mnist')
        if not path.exists(self.gen_img_path):
            os.mkdir(self.gen_img_path)

        if not path.exists(self.ckpt_path):
            os.mkdir(self.ckpt_path)
예제 #4
0
 def gen_gif(self):
     """生成GIF图记录测试图片的变化过程"""
     anim_file = path.join(self.gen_img_path, 'mnist_gen_process.gif')
     with imageio.get_writer(anim_file, mode='I') as writer:
         filenames = glob.glob(path.join(self.gen_img_path, 'image*.png'))
         filenames = sorted(filenames)
         last = -1
         for i, filename in enumerate(filenames):
             frame = 2 * (i**0.5)
             if round(frame) > round(last):
                 last = frame
             else:
                 continue
             image = imageio.imread(filename)
             writer.append_data(image)
         image = imageio.imread(filename)
         writer.append_data(image)
예제 #5
0
def bootstrapLauncher():
    version = requestUtils.get(request, 'version', str)

    if serverConfig.skipLauncher():
        launcherNotesHtml = launcherUtils.directToGameHtml()
        return Response(launcherNotesHtml, mimetype='text/html')

    launcherPath = serverConfig.darksporeLauncherThemesPath()
    launcherPath = pathUtils.join(
        pathUtils.join(launcherPath, server.getActiveTheme()), "index.html")

    file = open(
        pathUtils.join(pathUtils.join(serverConfig.storagePath(), 'www'),
                       launcherPath), "r")
    launcherHtml = file.read()

    dlsClientScript = launcherUtils.dlsClientScript(server.config.host())
    launcherHtml = launcherHtml.replace('</head>', dlsClientScript + '</head>')

    return Response(launcherHtml, mimetype='text/html')
예제 #6
0
    def storagePath(self):
        if "docker" in sys.argv:
            return "/darkspore_server_storage"

        storagePath = self.get("STORAGE_PATH")
        if storagePath.startswith('.'):
            storagePath = pathUtils.join(self.serverPath,storagePath)

        while storagePath.endswith('/') or storagePath.endswith('\\'):
            storagePath = storagePath[:-1]
        return storagePath
예제 #7
0
def bootstrapLauncherNotes():
    notesPath = serverConfig.darksporeLauncherNotesPath()
    file = open(
        pathUtils.join(pathUtils.join(serverConfig.storagePath(), 'www'),
                       notesPath), "r")
    launcherNotesHtml = file.read()

    versionLocked = serverConfig.versionLockEnabled()
    singleplayer = serverConfig.singlePlayerOnly()
    isLatest = (server.gameVersion == darksporeBuild_latestOfficial)

    launcherNotesHtml = launcherNotesHtml.replace("{{dls-version}}",
                                                  server.version)
    launcherNotesHtml = launcherNotesHtml.replace(
        "{{version-lock}}", server.gameVersion if versionLocked else "no")
    launcherNotesHtml = launcherNotesHtml.replace(
        "{{game-mode}}", "singleplayer" if singleplayer else "multiplayer")
    launcherNotesHtml = launcherNotesHtml.replace(
        "{{display-latest-version}}", "block" if versionLocked else "none")
    launcherNotesHtml = launcherNotesHtml.replace("{{latest-version}}",
                                                  "yes" if isLatest else "no")

    return Response(launcherNotesHtml, mimetype='text/html')
예제 #8
0
    def generate_and_save_images(self, epoch, test_input, num_to_gen=100):
        """生成测试图片并保存"""
        n = int(math.sqrt(num_to_gen))

        labels = np.arange(0, num_to_gen)
        labels = labels % 10
        labels = labels.reshape((num_to_gen, 1, 1, 1))
        labels = tf.keras.utils.to_categorical(labels)
        predictions = self.gen([test_input, labels], training=False)

        plt.title(f'Epoch {epoch}')
        plt.figure(figsize=(n, n))
        for i in range(predictions.shape[0]):
            plt.subplot(n, n, i + 1)
            plt.imshow(predictions[i, :, :, 0] * 127.5 + 127.5, cmap='gray')
            plt.axis('off')
        save_filename = path.join(self.gen_img_path,
                                  'image_at_epoch_{:04d}.png'.format(epoch))
        plt.savefig(save_filename)
        plt.close()
예제 #9
0
파일: server.py 프로젝트: B-Rich/ttb-game
def serve_dirs(root,filename):
    return static_file(filename, join(STATIC_FILES_ROOT, root))
예제 #10
0
파일: server.py 프로젝트: B-Rich/ttb-game
#!/usr/bin/env python3
from utils.path import join
from bottle import route, run, static_file, request
from main import parse_request
import sys
import json
import traceback
import optparse
import common

STATIC_FILES_ROOT = join("./client/")
PORT = 80
DEBUG = False
SESSION_FILE = None

@route('/')
def serve_main():
    return static_file('main.html', STATIC_FILES_ROOT)

@route('/:root#css.*|images.*|js.*#/:filename')
def serve_dirs(root,filename):
    return static_file(filename, join(STATIC_FILES_ROOT, root))

@route('/:filename#.*\.css#')
@route('/:filename#.*\.ico#')
def serve_root_statics(filename):
    return static_file(filename, STATIC_FILES_ROOT)

@route('/ajax')
def serve_ajax():
    try:
예제 #11
0
from utils.path import join

common.COMMANDLINE = True

import commands as com

def prettify_name(name):
    return name.capitalize().replace("_", " ")

if __name__ == '__main__':
    com.clear()

    sid = com.register('admin', 'maintance')['sid']
    print('Log in as administrator, sid: {0}'. format(sid))

    maps_dir = join('data/maps')
    units_dir = join('data/units')

    factions = {}
    for dirpath, dirnames, filenames in os.walk(units_dir):
        faction = os.path.basename(dirpath)
        if faction not in factions:
            factions[faction] = []
        filenames = [os.path.join(dirpath, f)
                     for f in filenames if os.path.splitext(f)[1] == '.cfg']
        for unit_file in filenames:
            with open(unit_file, "r") as file:
                unit = json.loads(file.read())
                unit_name = os.path.splitext(os.path.basename(unit_file))[0]
                unit['name'] = prettify_name(unit_name)
                print(unit['name'])
예제 #12
0
from models.account import *
from models.server import *
from controllers.gameApi import *
from controllers.config import *

from utils import request as requestUtils
from utils import response as responseUtils
from utils import launcher as launcherUtils
from utils import path as pathUtils

serverConfig = DarkSporeServerConfig()
server = DarkSporeServer(serverConfig)
serverApi = DarkSporeServerApi(server)

staticFolderPath = pathUtils.join(
    pathUtils.join(serverConfig.storagePath(), 'www'), 'static')
app = Flask(__name__,
            static_url_path='/static',
            static_folder=staticFolderPath)

debugMode = ("debug" in sys.argv)
if debugMode:
    now = datetime.datetime.now()
    logFileName = 'dls-' + now.strftime("%Y-%m-%d_%H-%M-%S") + '.log'
    handler = logging.FileHandler(
        pathUtils.join(pathUtils.join(serverConfig.storagePath(), "logs"),
                       logFileName))  # errors logged to this file
    handler.setLevel(logging.ERROR)  # only log errors and above
    app.logger.addHandler(handler)

예제 #13
0
def steamDemoLinks(file_name):
    return send_from_directory(pathUtils.join(staticFolderPath, 'launcher'),
                               file_name + '.html',
                               mimetype='text/html')
예제 #14
0
def steamDemoImages(file_name):
    return send_from_directory(pathUtils.join(staticFolderPath, 'images'),
                               file_name + '.jpg',
                               mimetype='image/jpeg')
예제 #15
0
def index():
    indexPath = serverConfig.darksporeIndexPagePath()
    return send_from_directory(pathUtils.join(serverConfig.storagePath(),
                                              'www'),
                               indexPath,
                               mimetype='text/html')
예제 #16
0
 def serverDataFilePath(self):
     return pathUtils.join(self.storagePath(),'server.data')
예제 #17
0
파일: settings.py 프로젝트: B-Rich/ttb-game
# Set it to True, if you want to do some debug actions.
DEBUG = False

# The path to database (ignored if DEBUG = True)
# must be an absolute path. For instance you can use
# join function to attach relative path to a project
# root.
from utils.path import join
DB_PATH = join('game.db')