Example #1
0
def path_put_first(var_name, directories):
    """Puts the provided directories first in the path, adding them
       if they're not already there.
    """
    path = os.environ.get(var_name, "").split(':')

    for dir in directories:
        if dir in path:
            path.remove(dir)

    new_path = tuple(directories) + tuple(path)
    path_set(var_name, new_path)
Example #2
0
def path_put_first(var_name, directories):
    """Puts the provided directories first in the path, adding them
       if they're not already there.
    """
    path = os.environ.get(var_name, "").split(':')

    for dir in directories:
        if dir in path:
            path.remove(dir)

    new_path = tuple(directories) + tuple(path)
    path_set(var_name, new_path)
Example #3
0
 def doDelete(self, result):
     if result:
         if os.path.isdir(self.SOURCELIST.getFilename()) == True:
             pattern = self.SOURCELIST.getFilename()
             for None in os.walk(pattern, topdown = False):
                 (root, dirs, files) = None
                 for name in files:
                     os.remove(os.path.join(root, name))
                 for name in dirs:
                     os.rmdir(os.path.join(root, name))
             os.rmdir(pattern)
         else:
             pattern = self.SOURCELIST.getCurrentDirectory() + self.SOURCELIST.getFilename()
             os.remove(pattern)
         self.doRefresh()
Example #4
0
 def OptimizePathSlide(self, path, frict = Sf):
   '''
      Optimize by sliding WP along segments
   '''
   i = 0
   while i+2 < len(path):
     temp = self.SlideMove(path[i],path[i+1],path[i+2],frict=frict)
     if temp == None:
       # remove path[i+1]
       path.remove(path[i+1])
       # Keep i unchanged
     else:
       index = path.index(path[i+1])
       path.insert(index, temp)
       i = i + 1
   return path
Example #5
0
    def save(self):
        try:
            path.remove(self.__filename)
        except:
            print "existing"

        f = open(locate(), "w")

        data = {
            "supercollider-dir": self.sc_dir,
            "advanced": self.advanced,
            "interpreter": {"command": self.sclang_cmd, "runtime-dir": self.sclang_work_dir},
        }

        simplejson.dump(data, f, indent="    ")

        f.close()

        print "Sced settings saved."
Example #6
0
	def action_prepare(self):
		self._checkState()
		tplPath = self._template().getPath()
		if tplPath.endswith(".tar.gz"):
			tplPath = tplPath[:-len(".tar.gz")]
		tplPath = os.path.relpath(tplPath, "/var/lib/vz/template/cache") #calculate relative path to trick openvz
		imgPath = self._imagePath()
		if path.exists(imgPath):
			path.remove(imgPath, recursive=True)
		self._vzctl("create", ["--ostemplate", tplPath, "--config", "default"])
		self._vzctl("set", ["--devices", "c:10:200:rw", "--capability", "net_admin:on", "--save"])
		self.setState(ST_PREPARED, True) #must be here or the set commands fail
		self._setRam()
		self._setDiskspace()
		self._setRootpassword()
		self._setHostname()
		# add all interfaces
		for interface in self.getChildren():
			self._addInterface(interface)
Example #7
0
    def inst_start(self):
        while not self.stop_signal:

            # Build a new graph.
            nodes = [
                BearProvider(),
                HoneyProvider(),
                TreeProvider(num_trees=170),
                ]
            self.graph = Graph.build(nodes, width=30, height=15)

            # Attempt to solve the graph.
            start = self.graph.find_one(NodeType.BEAR_ON_GRASS)
            goal = self.graph.find_one(NodeType.HONEY_ON_GRASS)
            closed_set = set(self.graph.find_all(NodeType.TREE))
            algorithm =\
                astarsearch.Algorithm(self.graph.width, self.graph.height)
            path = algorithm.search(start, goal, closed_set) 
            if not path:
                continue # Graph with no solution.

            SubscribeHandler.publish(self.graph.nodes)

            # Render the solved graph. 
            time.sleep(2)
            path.remove(start)
            self.graph.set_many(path, NodeType.PATH)
            self.graph.replace(NodeType.BEAR_ON_GRASS, NodeType.BEAR_ON_PATH)
            self.graph.replace(NodeType.HONEY_ON_GRASS, NodeType.HONEY_ON_PATH)
            SubscribeHandler.publish(self.graph.nodes)

            time.sleep(2)
            path.append(goal)
            while path and not self.stop_signal:
                next_path_point = path.pop(0)
                self.graph.replace(NodeType.BEAR_ON_PATH, NodeType.GRASS)
                self.graph.set(next_path_point, NodeType.BEAR_ON_PATH)
                SubscribeHandler.publish(self.graph.nodes)
                time.sleep(.5)
            self.graph.replace(NodeType.BEAR_ON_PATH, NodeType.BEAR_ON_GRASS)
            SubscribeHandler.publish(self.graph.nodes)
            time.sleep(2)
Example #8
0
    def inst_start(self):
        while not self.stop_signal:

            # Build a new graph.
            nodes = [
                BearProvider(),
                HoneyProvider(),
                TreeProvider(num_trees=170),
            ]
            self.graph = Graph.build(nodes, width=30, height=15)

            # Attempt to solve the graph.
            start = self.graph.find_one(NodeType.BEAR_ON_GRASS)
            goal = self.graph.find_one(NodeType.HONEY_ON_GRASS)
            closed_set = set(self.graph.find_all(NodeType.TREE))
            algorithm =\
                astarsearch.Algorithm(self.graph.width, self.graph.height)
            path = algorithm.search(start, goal, closed_set)
            if not path:
                continue  # Graph with no solution.

            SubscribeHandler.publish(self.graph.nodes)

            # Render the solved graph.
            time.sleep(2)
            path.remove(start)
            self.graph.set_many(path, NodeType.PATH)
            self.graph.replace(NodeType.BEAR_ON_GRASS, NodeType.BEAR_ON_PATH)
            self.graph.replace(NodeType.HONEY_ON_GRASS, NodeType.HONEY_ON_PATH)
            SubscribeHandler.publish(self.graph.nodes)

            time.sleep(2)
            path.append(goal)
            while path and not self.stop_signal:
                next_path_point = path.pop(0)
                self.graph.replace(NodeType.BEAR_ON_PATH, NodeType.GRASS)
                self.graph.set(next_path_point, NodeType.BEAR_ON_PATH)
                SubscribeHandler.publish(self.graph.nodes)
                time.sleep(.5)
            self.graph.replace(NodeType.BEAR_ON_PATH, NodeType.BEAR_ON_GRASS)
            SubscribeHandler.publish(self.graph.nodes)
            time.sleep(2)
Example #9
0
    def save(self):
        try:
            path.remove(self.__filename)
        except:
            print "existing"

        f = open(locate(), "w")

        data = {
            "supercollider-dir": self.sc_dir,
            "advanced": self.advanced,
            "interpreter": {
                "command": self.sclang_cmd,
                "runtime-dir": self.sclang_work_dir
            }
        };

        simplejson.dump(data, f, indent="    ")

        f.close()

        print "Sced settings saved."
Example #10
0
import random
import csv
import os.path as path

datasets_num = 5
datasets_size = 1000

if path.exists('datasets.csv'):
    path.remove('datasets.csv')

with open('datasets.csv', 'w') as outfile:
    writer = csv.writer(outfile)
    outfile.write("A,B,C,D,E\n")
    for col in range(datasets_size):
        tablica = random.sample(range(1, 100000), 15000)
        #rlist = [random.randint(1,1000) for col in range(datasets_num)]
        values = ",".join(str(i) for i in rlist)
        outfile.write(values + "\n")
Example #11
0
    def A_star(self, cn, goal, allowedSet):
        self.searchEngine = "ASTAR"
        openList = []
        path = []
#        for e in allowedSet:
#            ND = (e[0], e[1], 0,0)
#            openList.append(ND)
        
        # add root node into allowed set
        #allowedSet.append(cn)
        firstTime = 1
        ND = (cn[0],cn[1],0,self.heuris(cn, goal))
        openList.append(ND)
        closeList = []

        '''
        'x, y, g_value, f_value'
        '''
#        Node = (cn[0],cn[1],0,self.heuris(cn, goal))
#        openList.append(Node)
        
        while len(openList) != 0:
            openList.sort(cmp, key = lambda k: k[3])
            curNode = openList[0]
            #if curNode[0] == goal[0] and curNode[1] == goal[1]:
            if (curNode[0], curNode[1]) == goal:
                path.append(curNode)
                return path
            
            openList.remove(curNode)
            closeList.append((curNode[0], curNode[1]))
            # track storage
            if (curNode[0], curNode[1]) != cn:
                path.append(curNode)
            if firstTime:
                firstTime = False
            else:
                if (curNode[0],curNode[1]) not in allowedSet:# and (curNode[0],curNode[1]) == cn:
                       path.remove(curNode)
                       continue
            
            child = self.env.neighbors(curNode[0],curNode[1])
#            children = []
#            for e in child:
#                curN = (e[0],e[1],0,0)
#                children.append(curN)
                
            for idx,e in enumerate(child):
                if (e) in closeList:
                    continue
                t_g = curNode[2] + 1
                bNOpLst = e not in openList
                
                if bNOpLst == True :
                    e2 = t_g
                    
                    e3 =  self.heuris(e, goal)
                    children = (e[0], e[1], e2, e3)
                    
                    if bNOpLst == True:
                        for e1 in openList:
                            if e1 == e:
                                continue
                        #if children[idx] not in openList:
                        openList.append(children)
        
        path = []                
        return path
Example #12
0
 def _useImage(self, path_):
     assert self.state != ST_CREATED
     imgPath = self._imagePath()
     path.remove(imgPath, recursive=True)
     path.createDir(imgPath)
     path.extractArchive(path_, imgPath)
Example #13
0
	def _useImage(self, path_):
		assert self.state != ST_CREATED
		imgPath = self._imagePath()
		path.remove(imgPath, recursive=True)
		path.createDir(imgPath)
		path.extractArchive(path_, imgPath)
Example #14
0
def print_tree(d, l):
    l += 1
    for k, v in d.items():

        if (len(v) > 0):
            print('{0}<li><a href="#">{1}</a>\n{0}  <ul>'.format('\t' * l, k))
            print_tree(v, l)
            print('{0}  </ul>\n{0}</li>'.format('\t' * l))
        else:
            print('{0}<li>{1}</li>'.format('\t' * l, k))


fp = open('input.test', 'r')
for path in fp:
    path = path.split()[0]
    path = path.split('/')
    path.remove('')
    insert_dict(tree, path)
fp.close()

print('<div class="container" style="margin-top:30px;">')
print('    <div class="row">')
print('        <div class="col-md-12">')
print('<ul id="tree1">')

print_tree(tree, 0)

print('</ul>')
print('        </div>')
print('    </div>')
print('</div>')
Example #15
0
#  This file can not be copied and/or distributed
#  without the express permission of Comet ML Inc.
# *******************************************************

import imp
import os.path
import sys

import comet_ml  # noqa

if __name__ == "sitecustomize":
    # Import the next sitecustomize.py file

    # Then remove current directory from the search path
    current_dir = os.path.dirname(__file__)
    path = list(sys.path)

    try:
        path.remove(current_dir)
    except KeyError:
        pass

    # Then import any other sitecustomize
    try:
        _file, pathname, description = imp.find_module("sitecustomize", path)
    except ImportError:
        # We might be the only sitecustomize file
        pass
    else:
        imp.load_module("sitecustomize", _file, pathname, description)
Example #16
0
import re
import string

import TestRuntest

python = TestRuntest.python
_python_ = TestRuntest._python_

test = TestRuntest.TestRuntest(noqmtest=1)

qmtest_py = test.where_is('qmtest.py')

if qmtest_py:
    dir = os.path.split(qmtest_py)[0]
    path = string.split(os.environ['PATH'], os.pathsep)
    path.remove(dir)
    os.environ['PATH'] = string.join(path, os.pathsep)

test.subdir('test')

test_pass_py = os.path.join('test', 'pass.py')
test_fail_py = os.path.join('test', 'fail.py')
test_no_result_py = os.path.join('test', 'no_result.py')

workpath_pass_py = test.workpath(test_pass_py)
workpath_fail_py = test.workpath(test_fail_py)
workpath_no_result_py = test.workpath(test_no_result_py)

test.write_failing_test(test_fail_py)
test.write_no_result_test(test_no_result_py)
test.write_passing_test(test_pass_py)
Example #17
0
import re
import string

import TestRuntest

python = TestRuntest.python
_python_ = TestRuntest._python_

test = TestRuntest.TestRuntest(noqmtest=1)

qmtest_py = test.where_is('qmtest.py')

if qmtest_py:
    dir = os.path.split(qmtest_py)[0]
    path = string.split(os.environ['PATH'], os.pathsep)
    path.remove(dir)
    os.environ['PATH'] = string.join(path, os.pathsep)

test.subdir('test')

test_pass_py = os.path.join('test', 'pass.py')
test_fail_py = os.path.join('test', 'fail.py')
test_no_result_py = os.path.join('test', 'no_result.py')

workpath_pass_py = test.workpath(test_pass_py)
workpath_fail_py = test.workpath(test_fail_py)
workpath_no_result_py = test.workpath(test_no_result_py)

test.write_failing_test(test_fail_py)
test.write_no_result_test(test_no_result_py)
test.write_passing_test(test_pass_py)