Skip to content
Permalink
Browse files

Now you can build bot for optimisation (For fun, I mean)

  • Loading branch information...
YogurtTheHorse committed Aug 29, 2016
1 parent 843950d commit c38f1e10c6d213b988b514ef976798e542b34796
Showing with 48 additions and 5 deletions.
  1. +33 −0 build.py
  2. +5 −2 items/itemloader.py
  3. +10 −3 rooms/roomloader.py
@@ -0,0 +1,33 @@
import os
import shutil
import fnmatch
import compileall

BUILD_FOLDER = 'build'

if not os.path.isdir(BUILD_FOLDER):
print('Creating build directory')
os.makedirs(BUILD_FOLDER)
else:
print('Clearing build directory')
shutil.rmtree(BUILD_FOLDER)

print('Compiling..')
compileall.compile_dir('.', legacy=True, force=True)

print('Moving pyc and pyo files to build folder')


for root, dirnames, filenames in os.walk('.'):
if '__pycache__' in root:
continue

for filename in fnmatch.filter(filenames, '*.pyo'):
curr_path = os.path.join(root, filename)
dest_path = './' + BUILD_FOLDER + curr_path[1:-1] + 'c'

if not os.path.isdir(os.path.dirname(dest_path)):
os.makedirs(os.path.dirname(dest_path))

print('Moving {0} -> {1}'.format(curr_path, dest_path ))
os.rename(curr_path, dest_path)
@@ -9,7 +9,9 @@ def load_item(name, buff):
path = 'items/{0}/{1}.py'.format(buff, name)

if not os.path.exists(path):
return None
path += 'c'
if not os.path.exists(path):
return None

item_loader = SourceFileLoader(name, path)
item = item_loader.load_module()
@@ -46,8 +48,9 @@ def check_item(item, name, buff):
def load_random_item(buff):
pth = 'items/' + buff + '/'
items = [ f[:-3] for f in os.listdir(pth) if f.endswith('.py') ]
comp_items = [ f[:-4] for f in os.listdir(pth) if f.endswith('.pyc') ]

return (buff, random.choice(items))
return (buff, random.choice(items + comp_items))

def load_shop_items():
items = [
@@ -2,6 +2,7 @@
import random
import logging
from importlib.machinery import SourceFileLoader
from importlib.machinery import SourcelessFileLoader

from constants import *

@@ -11,9 +12,14 @@ def load_room(name, room_type='usual', user=None):
path = 'rooms/{0}/{1}.py'.format(room_type, name)

if not os.path.exists(path):
return None
path += 'c'
if not os.path.exists(path):
return None

room_loader = SourceFileLoader(name, path)
if path.endswith('c'):
room_loader = SourcelessFileLoader(name, path)
else:
room_loader = SourceFileLoader(name, path)
room = room_loader.load_module(name)

return check_room(room, name, room_type)
@@ -92,5 +98,6 @@ def get_next_room():
def get_random_room(room_type='usual'):
pth = 'rooms/' + room_type + '/'
rooms = [ f[:-3] for f in os.listdir(pth) if f.endswith('.py') ]
comp_rooms = [ f[:-4] for f in os.listdir(pth) if f.endswith('.pyc') ]

return (room_type, random.choice(rooms))
return (room_type, random.choice(rooms + comp_rooms))

0 comments on commit c38f1e1

Please sign in to comment.
You can’t perform that action at this time.