예제 #1
0
    def getActionNames(self):
        self.deletePrFiles()
        try:
            cmd = self.CALL_PR2 + ' -d ' + self.domain + ' -i ' + self.problem + ' -o ' + './planner/blank_obs.dat'
            os.system(cmd)
        except:
            raise Exception('[ERROR] Call to PR2 failed!')

        if not os.path.isfile(self.pr_domain) or not os.path.isfile(
                self.pr_problem):
            print "[ERROR] Goal cannot be reached from initial state"
            return []

        try:
            cmd = 'cat pr-problem.pddl | grep -v "EXPLAIN" > pr-problem.pddl.tmp && mv pr-problem.pddl.tmp pr-problem.pddl'
            os.system(cmd)
            cmd = 'cat pr-domain.pddl | grep -v "EXPLAIN" > pr-domain.pddl.tmp && mv pr-domain.pddl.tmp pr-domain.pddl'
            os.system(cmd)
        except:
            raise Exception(
                '[ERROR] Removing "EXPLAIN" from pr-domain and pr-problem files.'
            )

        copyf(self.pr_domain, self.val_pr_domain)
        copyf(self.pr_problem, self.val_pr_problem)
        actionNames = []
        f = open('./pr-domain.pddl')
        for l in f:
            if '(:action ' in l:
                actionNames.append('(' + l.split('(:action ')[1] + ')')
        return actionNames
예제 #2
0
    def definePlanningProblem(self):
        problem_state = problem_generator.generateState()

        # Get pddl file from problem state
        problem_generator.compile2pddl(problem_state)

        # Write json to file for ui
        with open(self.problem_state_json, 'w') as f:
            f.write(problem_state)

        # Removing observation during problem initialization
        copyf(self.blank_obs, self.obs)

        # create a log file for the new user, when server starts
        self.log_file = self.log_file_name.format(time.time())

        # creating a new session id when creating a new planning problem
        self.session_id = self.generate_random_id()
예제 #3
0
    def __create_grounded_files(self):
        self.__run_pr2(self.domain, self.problem, self.blank_obs)

        # Remove the proposition EXPLAINED_FULL_OBS_SEQUENCE from
        # the goal state that makes the problem infeasible.
        with open(self.pr_problem, 'r') as f:
            lines = f.read().split('\n')

        s = ''
        for line in lines:
            if 'EXPLAINED_FULL_OBS_SEQUENCE' in line:
                continue
            s += "{}\n".format(line.strip())
        s = s.strip()

        with open(self.pr_problem, 'w') as f:
            f.write(s)

        copyf(self.pr_domain, self.grounded_pr_domain)
        copyf(self.pr_problem, self.grounded_pr_problem)
예제 #4
0
 def load_plan(self):
     print("[DEBUG] Loading observations from {0} to {1}".format(
         self.saveduiPlan, self.obs))
     copyf(self.saveduiPlan, self.obs)
예제 #5
0
 def save_plan(self):
     print("[DEBUG] Saving observations in {0} to {1}".format(
         self.obs, self.saveduiPlan))
     copyf(self.obs, self.saveduiPlan)
예제 #6
0
        else:
            version_data_file.write(':'.join(l) + "\n")

chdir(PROJECT_NAME)

if f'v{curr_version}' not in listdir('asset_backups'):
    system(f'mkdir asset_backups{sep}v{curr_version}')
for req in ['pys']:
    if req not in listdir(): 
        system(f'mkdir {req}')

if platform == 'win32':
    if 'exes' not in listdir(): system(f'mkdir exes')
    try: 
        for file in listdir('assets'):
            copyf(f'assets{sep}{file}', f'asset_backups{sep}v{curr_version}{sep}{file}')
    except FileNotFoundError: print("No assets found")
    try: copyf('application_update.py', f'asset_backups{sep}v{curr_version}{sep}application_update.py')
    except FileNotFoundError: print("No 'application_update.py' file found")
    copyf('main.py', f'pys{sep}v{curr_version}.py')
    if 'latest.py' in listdir():
        copyf('latest.exe', f'exes{sep}v{last_version}.exe')
    system("pyinstaller --onefile -w main.py")
    copyf(f'dist{sep}main.exe', 'latest.exe')
    copyf('latest.exe', f'exes{sep}v{curr_version}.exe')
    for directory in ["dist", "build"]:
        rmtree(directory)
    remove('main.spec')
elif platform == 'darwin':
    if 'apps' not in listdir(): system(f'mkdir apps')
    system(f'cp main.py pys{sep}v{curr_version}.py')
예제 #7
0
def addConfigToFs():

	""" Move the acquired configuration 
	from downloadConfigGit() to the Filesystem
	and make a backup of each file if exists """

	def downloadFsConfig():

		""" Downloads all required config 
		file for the system return path"""

		try:
			git('.').clone(repo)

		except Exception as exp:
			print(exp)
			return False

		else:
			os.chdir(repoName)
			print('RepoPath : ' + repoName)
			return repoName

	def bckupCfg():

		""" Make a zip of all current configuartions
		returns True if success otherwise False """

		try:
			azip.makeZip('/etc', '.')
			azip.makeZip('/usr', '.')
			azip.makeZip('/boot/config.txt', '.')
			azip.makeZip('/boot/cmdline.txt', '.')
			
		except Exception as exp:
			print(exp)
			return False
			
		else:
			return True

	try:
		bckupCfg()

		if not os.path.exists(repoName):
			path = downloadFsConfig()

		else:
			os.chdir(repoName)
			path = repoName


		for dirname, dirnames, filenames in os.walk(path):
			# print path to all subdirectories first.
			for subdirname in dirnames:
				if 'root' in dirname:
					print(os.path.join(dirname, subdirname))
					print(subdirname)
					copyf(os.path.abspath(subdirname), '/')

			# print path to all filenames.
			# for filename in filenames:
			# 	print(os.path.join(dirname, filename))

			# Advanced usage:
			# editing the 'dirnames' list will stop os.walk() from recursing into there.
			if '.git' in dirnames:
				# don't go into any .git directories.
				dirnames.remove('.git')

	except Exception as exp:
		print(exp)
		return False
	
	else:
		configInstallState = True
		return True