Пример #1
0
 def task():
     model = loader.loadModel(abspath(f"models/{mod}_low_flat.bam"))
     model.clearModelNodes()
     model.flattenStrong()
     model.setHpr(orient*90+180, 90, 0)
     model.reparentTo(parent)
     model.setPos(Vec3(pos)+Vec3(10, 10, 0))
     model.setScale(10.0)
Пример #2
0
 def set_tower(self, loader, tower_class):
     self.remove_tower()
     self.tower = loader.loadModel(
         abspath(f"models/{tower_class.name}.dae"))
     self.tower.reparentTo(self.model)
     self.tower.setHpr(0, 90, 0)
     self.tower.setTransparency(TransparencyAttrib.MAlpha)
     self.tower.setAlphaScale(0.5)
     self.tower.setScale(tower_class.scale)
     self.tower_class = tower_class
Пример #3
0
 def generate(self, loader, parent, get_tile):
     """Load in the model into self.model."""
     self.model = loader.loadModel(abspath(f"models/{self.name}.dae"))
     self.model.clearModelNodes()
     self.model.flattenStrong()
     self.model.reparentTo(parent)
     self.model.setHpr(self.hpr)
     self.model.setScale(self.scale)
     self.model.setPos(self.pos)
     self.active = True
     self.generated = True
     self.get_tile = get_tile
     del self.pos
     del self.hpr
Пример #4
0
def create_file_tree(rootdir):
    """Creates a k-tree that takes the dir hierarchy and
    parent-child relationships and turns it into package-module
    and package - sub-package relationship.
    
    Arguments:
        rootdir:- path to rootdir of project being analyzed.
    
    Returns: The file tree
    """
    
    if not os.path.isdir(rootdir):
        error("root is not a dir")
    
    root = tree.FileTree(rootdir)
    pathmap = {}
    ptr =  None
    this = None
    for selfpath, dirs, files in os.walk(rootdir):
        #selfpath is own path
        #dirs is child dirs
        #files is child files
        this = pathmap.get(selfpath, root)
        for d in dirs:
            path = ut.abspath(selfpath, d)
            ptr = this.add_child_dir(path)
            pathmap[path] = ptr
        
        for f in files:
            path = ut.abspath(selfpath, f)
            ptr = this.add_child_file(path)
            pathmap[path] = ptr
            if f == "__init__.py":
                this.set_package(True)
    #print root
    return root
Пример #5
0
def tid2ts(tmx, id, basefile):
    "for a given tid in tmx, find the tileset + local tid type"
    for ts in tmx.findall('tileset'):
        if int(ts.get('firstgid')) > id:
            break
        last_ts = ts

    rid = id - int(last_ts.get('firstgid'))  # local id of this tile within
    src = last_ts.get('source')
    if src:
        ts = ET.parse(abspath(basefile, src)).getroot()
    else:
        ts = last_ts

    return ts, rid
Пример #6
0
 def getData(self,including_deps = True):
     data = {}
     if C('disable_deps_search') or not including_deps:
         deps = [self.__token+'.'+C('template_ext')]
     else:
         #复制
         deps = self.__deps[0:]
         deps.reverse()
     deps.insert(len(deps),self.__token+".json")
     deps.insert(0,"_ursa.json")
     for dep in deps:
         try:
             json_filepath = utils.abspath(os.path.join(C('data_dir'),re.sub(r'\.%s$'%C('template_ext'),'.json',dep)))
             content = utils.readfile(json_filepath)
             content = re.sub('\/\*[\s\S]*?\*\/','',content)
             json_data = json.loads(content)
             data.update(json_data)
         except Exception, e:
             e#log.warn('[getdata]%s:%s'%(json_filepath,e))
Пример #7
0
    def _search(self,tpl):
        '''
        递归搜索
        '''
        try:
            abspath = utils.abspath(os.path.join(C('template_dir'),tpl))

            content = utils.readfile(abspath)
            iters = re.finditer(self._pattern,content)

            for i in reversed(list(iters)):
                tpl = utils.filterRelPath(i.group(3))
                if C('ignore_parents') and tpl.endswith('parent.'+C('template_ext')):
                    continue
                if self._history.get(tpl) is None:
                    self._result.append(tpl)
                    self._history[tpl] = 1
                    if 'include' == i.group(1):
                        self._include_result.append(tpl)
                    self._search(tpl)
        except Exception, e:
            log.error('[deps]%s'%e)
Пример #8
0
    "Python file defining a list H of homographies to be used in uNetXST model"
)
parser.add("-mw",
           "--model-weights",
           type=str,
           required=True,
           help="weights file of trained model")
parser.add("-pd",
           "--prediction-dir",
           type=str,
           required=True,
           help="output directory for storing predictions of testing data")
conf, unknown = parser.parse_known_args()

# determine absolute filepaths
conf.input_testing = [utils.abspath(path) for path in conf.input_testing]
conf.one_hot_palette_input = utils.abspath(conf.one_hot_palette_input)
conf.one_hot_palette_label = utils.abspath(conf.one_hot_palette_label)
conf.model = utils.abspath(conf.model)
conf.unetxst_homographies = utils.abspath(
    conf.unetxst_homographies
) if conf.unetxst_homographies is not None else conf.unetxst_homographies
conf.model_weights = utils.abspath(conf.model_weights)
conf.prediction_dir = utils.abspath(conf.prediction_dir)

# load network architecture module
architecture = utils.load_module(conf.model)

# get max_samples_testing samples
files_input = [
    utils.get_files_in_folder(folder) for folder in conf.input_testing
Пример #9
0
#!/usr/bin/env python3
# Generates a fizzbuzz, with some mistakes

import utils

MAX = 1000
OUTPUT = "fizzbuzz"
FORMAT = "{}\t{}\n"

def writeout(output, num, msg):
    output.write(FORMAT.format(num, msg))

with open(utils.abspath(OUTPUT), mode = "w") as output:
    for num in range(MAX + 1):
        three = (num % 3) == 0
        five = (num % 5) == 0

        if num == 28:
            writeout(output, num, "Woof!")
            continue
        if num == 25:
            writeout(output, num, "Fizz")
            continue
        if num == 30:
            writeout(output, num, "Buzz")
            continue

        if three and five:
            writeout(output, num, "FizzBuzz")
        elif three:
            writeout(output, num, "Fizz")
Пример #10
0
 def __init__(self):
     super(PathFinder, self).__init__()
     basedir, filename = utils.split(utils.abspath(__file__))
     self.config_name = os.path.join(basedir, "workspace_path_config.json")
     self.logger = logging.getLogger("main_log.path_finder")
     self.path_dict = self.read_in_path_config(self.config_name)
Пример #11
0
import os
import shutil
import tempfile
import time
import utils

from nova import vendor
import M2Crypto

from nova import exception
from nova import flags


FLAGS = flags.FLAGS
flags.DEFINE_string('ca_file', 'cacert.pem', 'Filename of root CA')
flags.DEFINE_string('keys_path', utils.abspath('../keys'), 'Where we keep our keys')
flags.DEFINE_string('ca_path', utils.abspath('../CA'), 'Where we keep our root CA')
flags.DEFINE_boolean('use_intermediate_ca', False, 'Should we use intermediate CAs for each project?')

def ca_path(project_id):
    if project_id:
        return "%s/INTER/%s/cacert.pem" % (FLAGS.ca_path, project_id)
    return "%s/cacert.pem" % (FLAGS.ca_path)

def fetch_ca(project_id=None, chain=True):
    if not FLAGS.use_intermediate_ca:
        project_id = None
    buffer = ""
    if project_id:
        with open(ca_path(project_id),"r") as cafile:
            buffer += cafile.read()
Пример #12
0
import sys
import threading

from utils import abspath

import Tkinter as tk

def remove_values_from_list(the_list, val):
    return [value for value in the_list if value != val]

_LIB_DIR = '../lib/'
_LIB32_DIR = '../lib32/'
_LIB64_DIR = '../lib64/'
if sys.maxsize > 2**32:
    print 'using 64bit libs'
    _plat_lib_path = abspath(_LIB64_DIR)
    sys.path = remove_values_from_list(sys.path, abspath(_LIB32_DIR))    
else:
    print 'using 32bit libs'
    _plat_lib_path = abspath(_LIB32_DIR)
    sys.path = remove_values_from_list(sys.path, abspath(_LIB64_DIR))
if _plat_lib_path not in sys.path:
    sys.path.append(_plat_lib_path)
_lib_path = abspath(_LIB_DIR)
if _lib_path not in sys.path:
    sys.path.append(_lib_path)
del _LIB_DIR, _lib_path, _LIB32_DIR, _LIB64_DIR, _plat_lib_path

import ldap
from msr605 import MSR605
Пример #13
0
import shutil
import struct
import tempfile
import time
import utils

from nova import vendor
import M2Crypto

from nova import exception
from nova import flags


FLAGS = flags.FLAGS
flags.DEFINE_string('ca_file', 'cacert.pem', 'Filename of root CA')
flags.DEFINE_string('keys_path', utils.abspath('../keys'), 'Where we keep our keys')
flags.DEFINE_string('ca_path', utils.abspath('../CA'), 'Where we keep our root CA')
flags.DEFINE_boolean('use_intermediate_ca', False, 'Should we use intermediate CAs for each project?')

def ca_path(project_id):
    if project_id:
        return "%s/INTER/%s/cacert.pem" % (FLAGS.ca_path, project_id)
    return "%s/cacert.pem" % (FLAGS.ca_path)

def fetch_ca(project_id=None, chain=True):
    if not FLAGS.use_intermediate_ca:
        project_id = None
    buffer = ""
    if project_id:
        with open(ca_path(project_id),"r") as cafile:
            buffer += cafile.read()
Пример #14
0
 @version 0.0.1
 @since 0.0.1
'''
from conf import C,log,BASE_DIR
import utils
import os
import re
import json
from timestamp import html_link,html_script,html_img,all_url,all as allt
from deps import DepsFinder
from replace import replace
from jinja2 import Template,Environment,FileSystemLoader,TemplateNotFound,TemplateSyntaxError

_template_dir = C('template_dir')

jinjaenv = Environment(loader = FileSystemLoader(utils.abspath(_template_dir),  C('encoding') ), extensions = ["jinja2.ext.do"] , autoescape = True )
build_jinjaenv = Environment( loader = FileSystemLoader( os.path.join( os.getcwd() , C('build_dir'), _template_dir) ,  C('encoding') ))
mgr_jinjaenv = Environment( loader = FileSystemLoader( os.path.join(BASE_DIR,'tpl') ,  C('encoding') ))

def render_file(filename,data = None,noEnvironment = False,build = False):
    '''
    渲染文件
    '''
    if noEnvironment:
        body = mgr_jinjaenv.get_template(filename)#Template(utils.readfile(filename))#这里应为绝对路径
    else:
        if build:
            body = build_jinjaenv.get_template(filename)
        else:
            body = jinjaenv.get_template(filename)
    return body.render(data or {})
Пример #15
0
def file_roots(request):
    file_roots = request.config.getini('SALT_FILE_ROOTS')
    if not file_roots:
        file_roots = [abspath(str(request.config.rootdir), '../')]
    return [str(p) for p in file_roots]
Пример #16
0
import os
import contrib
import anyjson

import flags
import utils

FLAGS = flags.FLAGS

flags.DEFINE_string('datastore_path', utils.abspath('../keeper'),
                    'where keys are stored on disk')


class keeper(object):
    def __init__(self, prefix="nova-"):
        self.prefix = prefix
        try:
            os.mkdir(FLAGS.datastore_path)
        except:
            pass

    def _slugify(self, key):
        return key

    def __delitem__(self, item):
        item = self._slugify(item)
        path = "%s/%s%s" % (FLAGS.datastore_path, self.prefix, item)
        if os.path.isfile(path):
            os.remove(path)

    def __getitem__(self, item):
Пример #17
0
# figure out a bunch of directories so we don't need to parse them every time
# Yay abstraction!
waisman_user = False
home_dir_str = None
if utils.systemName in ('Linux', 'Darwin'):
    home_dir_str = utils.environ['HOME']
elif utils.systemName == 'Windows':
    try:
        # used by waisman users alone
        home_dir_str = utils.environ['_USR'] + '/'
        waisman_user = True
    except (AttributeError, KeyError):
        home_dir_str = utils.environ['USERPROFILE'] + '/'

basedir, filename = utils.split(utils.abspath(__file__))  # within the package

basedir = utils.split(basedir)[0]  # move up one dir


def if_path_not_found(path_key, path_dict):
    dir_path = filedialog.askdirectory(
        title="Please choose the directory for your %s file" % path_key)
    path_dict[path_key] = dir_path
    return dir_path


#templatedir = utils.join(basedir, 'mapping_files')
templatedir = path_finder.find_path("mapping_file_dir",
                                    func_if_path_not_found=if_path_not_found,
                                    func_if_path_empty=if_path_not_found)
Пример #18
0
def _addtimestamp(content,reg,base_dir,force_abspath=False):
    '''
    以base_dir为基础目录,在content中搜寻匹配reg的URL并尝试追加时间戳
    
    reg:匹配URL的正则,其中\3为URL
    force_abspath:强制路径为绝对路径,即以WD为base_dir
    '''
    iters=re.finditer(reg,content,re.I|re.M)
    t=C('timestamp_name')
    for it in reversed(list(iters)):
        start = content[0:it.start(1)]
        url = it.group(3)
        end = content[it.end(1):]
        local_url = replace(url)
        parsed_url = urlparse(local_url)
        parsed_query = parse_qs(parsed_url.query)

        #已经有时间戳的不再添加
        #带协议的不再添加
        if not local_url or not parsed_url.path:
            continue
        #具有模板语法的不予添加
        elif parsed_url.path.find('{{') >=0 or parsed_url.path.find('{%') >= 0:
            log.warn('twig syntax found in %s'%parsed_url.path)
            continue
        elif re.match(r'^\s*(about:|data:|#)',local_url):
            log.warn('%s is an invalid url'%local_url)
            continue
        elif parsed_query.get(t) is not None:
            log.warn("%s has a timestamp"%local_url)
            continue
        elif parsed_url.scheme  or local_url.startswith('//'):
            log.warn("%s has a scheme"%local_url)
            continue
        
        if os.path.isabs(parsed_url.path) or force_abspath:
            #绝对路径,则以当前工程根目录为root
            timestamp = utils.get_file_timestamp(utils.abspath(base_dir + parsed_url.path))
        else:
            #相对目录,则此当前文件目录为root
            #应该仅在CSS内使用相对路径
            timestamp = utils.get_file_timestamp(os.path.join(base_dir,parsed_url.path))

        #计算不到时间戳则忽略
        if not timestamp:
            continue

        parsed_url = urlparse(url)
        new_query = parsed_url.query
        if '' == new_query:
            new_query = t+"="+timestamp
        else:
            new_query+='&%s=%s'%(t,timestamp)
        if '' == parsed_url.fragment:
            new_fragment = ''
        else:
            new_fragment = '#'+parsed_url.fragment

        if not parsed_url.scheme:
            new_scheme = ''
        else:
            new_scheme = parsed_url.scheme+"://"

        new_url = new_scheme + parsed_url.netloc + parsed_url.path + '?' + new_query + new_fragment
        content = start + (it.group(2) or '') + new_url + (it.group(2) or '') + end

    return content
Пример #19
0
#!/usr/bin/env python3
# Generates a fizzbuzz, with some mistakes

import utils

MAX = 1000
OUTPUT = "fizzbuzz"
FORMAT = "{}\t{}\n"


def writeout(output, num, msg):
    output.write(FORMAT.format(num, msg))


with open(utils.abspath(OUTPUT), mode="w") as output:
    for num in range(MAX + 1):
        three = (num % 3) == 0
        five = (num % 5) == 0

        if num == 28:
            writeout(output, num, "Woof!")
            continue
        if num == 25:
            writeout(output, num, "Fizz")
            continue
        if num == 30:
            writeout(output, num, "Buzz")
            continue

        if three and five:
            writeout(output, num, "FizzBuzz")
Пример #20
0
           default=5,
           help="epoch interval between exports of the model")
parser.add("-o",
           "--output-dir",
           type=str,
           required=True,
           help="output dir for TensorBoard and models")
parser.add("-mw",
           "--model-weights",
           type=str,
           default=None,
           help="weights file of trained model for training continuation")
conf, unknown = parser.parse_known_args()

# determine absolute filepaths
conf.input_training = [utils.abspath(path) for path in conf.input_training]
conf.label_training = utils.abspath(conf.label_training)
conf.input_validation = [utils.abspath(path) for path in conf.input_validation]
conf.label_validation = utils.abspath(conf.label_validation)
conf.one_hot_palette_input = utils.abspath(conf.one_hot_palette_input)
conf.one_hot_palette_label = utils.abspath(conf.one_hot_palette_label)
conf.model = utils.abspath(conf.model)
conf.unetxst_homographies = utils.abspath(
    conf.unetxst_homographies
) if conf.unetxst_homographies is not None else conf.unetxst_homographies
conf.model_weights = utils.abspath(
    conf.model_weights
) if conf.model_weights is not None else conf.model_weights
conf.output_dir = utils.abspath(conf.output_dir)

# load network architecture module
Пример #21
0
    if platform not in settings.platforms:
        raise RuntimeError("unknown platform '%s'" % platform)
    if toolchain not in settings.toolchains:
        raise RuntimeError("unknown toolchain '%s'" % toolchain)
    toolchain_settings = settings.toolchains[toolchain]

    if config not in settings.configs:
        raise RuntimeError("unknown config '%s'" % config)
    if target not in settings.targets:
        raise RuntimeError("unknown target '%s'" % target)

    print platform, toolchain, config, target  # , args

    os.environ["SH_PATH"] = args.sh_path or ""

    src_dir = utils.abspath(target, args.src_dir)
    logger.debug("SRC_DIR=%s", src_dir)
    os.environ["SRC_DIR"] = src_dir

    build_dir = utils.makedirs(args.build_dir,
                               platform, toolchain, config, target)
    logger.debug("BUILD_DIR=%s", build_dir)
    os.environ["BUILD_DIR"] = build_dir

    target_settings = utils.load_json(
        os.path.join(src_dir, BUILD_SETTINGS_FILENAME), {})

    target_settings = get_by_alias(target_settings, platform, target_settings)
    target_settings = get_by_alias(target_settings, toolchain, target_settings)
    target_settings = get_by_alias(target_settings, config, target_settings)
    target_settings = Settings(disable=False,
Пример #22
0
import logging

import M2Crypto
import time
import hashlib
import os
import utils
import tempfile
import shutil
import contrib
import flags

FLAGS = flags.FLAGS

flags.DEFINE_string('ca_file', 'cacert.pem', 'Filename of root CA')
flags.DEFINE_string('keys_path', utils.abspath('../keys'),
                    'Where we keep our keys')
flags.DEFINE_string('ca_path', utils.abspath('../CA'),
                    'Where we keep our root CA')


def ca_path(username):
    if username:
        return "%s/INTER/%s/cacert.pem" % (FLAGS.ca_path, username)
    return "%s/cacert.pem" % (FLAGS.ca_path)


def fetch_ca(username=None, chain=True):
    buffer = ""
    with open(ca_path(username), "r") as cafile:
        buffer += cafile.read()
Пример #23
0
import os
import contrib
import anyjson

import flags
import utils

FLAGS = flags.FLAGS

flags.DEFINE_string('datastore_path', utils.abspath('../keeper'),
                    'where keys are stored on disk')


class keeper(object):
    def __init__(self, prefix="nova-"):
        self.prefix = prefix
        try:
            os.mkdir(FLAGS.datastore_path)
        except:
            pass
        
    def _slugify(self, key):
        return key

    def __delitem__(self, item):
        item = self._slugify(item)
        path = "%s/%s%s" % (FLAGS.datastore_path, self.prefix, item)
        if os.path.isfile(path):
            os.remove(path)

    def __getitem__(self, item):
Пример #24
0
# figure out a bunch of directories so we don't need to parse them every time
# Yay abstraction!
waisman_user = False
home_dir_str = None
if utils.systemName in ('Linux', 'Darwin'):
    home_dir_str = utils.environ['HOME']
elif utils.systemName == 'Windows':
    try:
        # used by waisman users alone
        home_dir_str = utils.environ['_USR'] + '/'
        waisman_user = True
    except (AttributeError, KeyError):
        home_dir_str = utils.environ['USERPROFILE'] + '/'

basedir, filename = utils.split(utils.abspath(__file__))  # within the package

basedir = utils.split(basedir)[0]  # move up one dir


def if_path_not_found(path_key, path_dict):
    dir_path = filedialog.askdirectory(title="Please choose the directory for your %s file"%path_key)
    path_dict[path_key] = dir_path
    return dir_path

#templatedir = utils.join(basedir, 'mapping_files')
templatedir = path_finder.find_path("mapping_file_dir", func_if_path_not_found=if_path_not_found
                                    , func_if_path_empty=if_path_not_found)
srcdatdir = path_finder.find_path("source_data_dir", func_if_path_not_found=if_path_not_found
                                    , func_if_path_empty=if_path_not_found)
sinkdatdir = path_finder.find_path("sink_data_dir", func_if_path_not_found=if_path_not_found,
Пример #25
0
 def __init__(self):
     super(PathFinder, self).__init__()
     basedir, filename = utils.split(utils.abspath(__file__))
     self.config_name = os.path.join(basedir, "workspace_path_config.json")
     self.logger = logging.getLogger("main_log.path_finder")
     self.path_dict = self.read_in_path_config(self.config_name)