write parameters to object
Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
This commit is contained in:
		
					parent
					
						
							
								3faf56cb04
							
						
					
				
			
			
				commit
				
					
						9de1d9ce20
					
				
			
		
					 2 changed files with 31 additions and 17 deletions
				
			
		
							
								
								
									
										46
									
								
								bin/cdist
									
										
									
									
									
								
							
							
						
						
									
										46
									
								
								bin/cdist
									
										
									
									
									
								
							| 
						 | 
					@ -77,6 +77,9 @@ def file_to_list(filename):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   return lines
 | 
					   return lines
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def exit_error(*args):
 | 
				
			||||||
 | 
					   log.error(*args)
 | 
				
			||||||
 | 
					   sys.exit(1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Cdist:
 | 
					class Cdist:
 | 
				
			||||||
   """Cdist main class to hold arbitrary data"""
 | 
					   """Cdist main class to hold arbitrary data"""
 | 
				
			||||||
| 
						 | 
					@ -144,10 +147,6 @@ class Cdist:
 | 
				
			||||||
         shutil.rmtree(self.cache_dir)
 | 
					         shutil.rmtree(self.cache_dir)
 | 
				
			||||||
      shutil.move(self.temp_dir, self.cache_dir)
 | 
					      shutil.move(self.temp_dir, self.cache_dir)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   def exit_error(self, *args):
 | 
					 | 
				
			||||||
      log.error(*args)
 | 
					 | 
				
			||||||
      sys.exit(1)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
   def remote_mkdir(self, directory):
 | 
					   def remote_mkdir(self, directory):
 | 
				
			||||||
      """Create directory on remote side"""
 | 
					      """Create directory on remote side"""
 | 
				
			||||||
      self.run_or_fail(["mkdir", "-p", directory], remote=True)
 | 
					      self.run_or_fail(["mkdir", "-p", directory], remote=True)
 | 
				
			||||||
| 
						 | 
					@ -182,9 +181,9 @@ class Cdist:
 | 
				
			||||||
            print(script_fd.read())
 | 
					            print(script_fd.read())
 | 
				
			||||||
            script_fd.close()
 | 
					            script_fd.close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
         self.exit_error("Command failed (shell): " + " ".join(*args))
 | 
					         exit_error("Command failed (shell): " + " ".join(*args))
 | 
				
			||||||
      except OSError as error:
 | 
					      except OSError as error:
 | 
				
			||||||
         self.exit_error(" ".join(*args) + ": " + error.args[1])
 | 
					         exit_error(" ".join(*args) + ": " + error.args[1])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   def run_or_fail(self, *args, **kargs):
 | 
					   def run_or_fail(self, *args, **kargs):
 | 
				
			||||||
      if "remote" in kargs:
 | 
					      if "remote" in kargs:
 | 
				
			||||||
| 
						 | 
					@ -197,9 +196,9 @@ class Cdist:
 | 
				
			||||||
      try:
 | 
					      try:
 | 
				
			||||||
         subprocess.check_call(*args, **kargs)
 | 
					         subprocess.check_call(*args, **kargs)
 | 
				
			||||||
      except subprocess.CalledProcessError:
 | 
					      except subprocess.CalledProcessError:
 | 
				
			||||||
         self.exit_error("Command failed: " + " ".join(*args))
 | 
					         exit_error("Command failed: " + " ".join(*args))
 | 
				
			||||||
      except OSError as error:
 | 
					      except OSError as error:
 | 
				
			||||||
         self.exit_error(" ".join(*args) + ": " + error.args[1])
 | 
					         exit_error(" ".join(*args) + ": " + error.args[1])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   def remove_remote_dir(self, destination):
 | 
					   def remove_remote_dir(self, destination):
 | 
				
			||||||
| 
						 | 
					@ -365,7 +364,7 @@ class Cdist:
 | 
				
			||||||
      """Run global explorers"""
 | 
					      """Run global explorers"""
 | 
				
			||||||
      explorers = self.list_global_explorers()
 | 
					      explorers = self.list_global_explorers()
 | 
				
			||||||
      if(len(explorers) == 0):
 | 
					      if(len(explorers) == 0):
 | 
				
			||||||
         self.exit_error("No explorers found in", self.global_explorer_dir)
 | 
					         exit_error("No explorers found in", self.global_explorer_dir)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      self.transfer_global_explorers()
 | 
					      self.transfer_global_explorers()
 | 
				
			||||||
      for explorer in explorers:
 | 
					      for explorer in explorers:
 | 
				
			||||||
| 
						 | 
					@ -639,14 +638,23 @@ def emulator():
 | 
				
			||||||
   if os.path.isfile(os.path.join(type_dir, "singleton")):
 | 
					   if os.path.isfile(os.path.join(type_dir, "singleton")):
 | 
				
			||||||
      object_id = "singleton"
 | 
					      object_id = "singleton"
 | 
				
			||||||
   else:
 | 
					   else:
 | 
				
			||||||
      object_id = args.object_id
 | 
					      object_id = args.object_id[0]
 | 
				
			||||||
      del args.object_id
 | 
					      del args.object_id
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   print(args)
 | 
					      # FIXME: / hardcoded - better portable solution available?
 | 
				
			||||||
 | 
					      if object_id[0] == '/':
 | 
				
			||||||
 | 
					         object_id = object_id[1:]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   print(object_id)
 | 
					   log.debug(args)
 | 
				
			||||||
   param_out_dir = os.path.join(global_dir, type,
 | 
					
 | 
				
			||||||
                     object_id, DOT_CDIST, "parameter")
 | 
					   object_dir = os.path.join(global_dir, type,
 | 
				
			||||||
 | 
					                     object_id, DOT_CDIST)
 | 
				
			||||||
 | 
					   param_out_dir = os.path.join(object_dir, "parameter")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   try:
 | 
				
			||||||
 | 
					      os.makedirs(param_out_dir, exist_ok=True)
 | 
				
			||||||
 | 
					   except OSError as error:
 | 
				
			||||||
 | 
					      exit_error(param_out_dir + ": " + error.args[1])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   # Record parameter
 | 
					   # Record parameter
 | 
				
			||||||
   params = vars(args)
 | 
					   params = vars(args)
 | 
				
			||||||
| 
						 | 
					@ -654,16 +662,19 @@ def emulator():
 | 
				
			||||||
      value = getattr(args, param)
 | 
					      value = getattr(args, param)
 | 
				
			||||||
      if value:
 | 
					      if value:
 | 
				
			||||||
         file = os.path.join(param_out_dir, param)
 | 
					         file = os.path.join(param_out_dir, param)
 | 
				
			||||||
         print(file + "<-" + param + " = " + value)
 | 
					         log.debug(file + "<-" + param + " = " + value)
 | 
				
			||||||
         param_fd = open(file)
 | 
					         param_fd = open(file, "w")
 | 
				
			||||||
         param_fd.writelines(value)
 | 
					         param_fd.writelines(value)
 | 
				
			||||||
         param_fd.close()
 | 
					         param_fd.close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
   # Record requirements
 | 
					   # Record requirements
 | 
				
			||||||
   if "__require" in os.environ:
 | 
					   if "__require" in os.environ:
 | 
				
			||||||
      requirements = os.environ['__require']
 | 
					      requirements = os.environ['__require']
 | 
				
			||||||
 | 
					      print(object_id + ":Writing requirements: " + requirements)
 | 
				
			||||||
 | 
					      require_fd = open(os.path.join(object_dir, "require"), "a")
 | 
				
			||||||
 | 
					      require_fd.writelines(requirements.split(" "))
 | 
				
			||||||
 | 
					      require_fd.close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   # Merge / mv object into tree
 | 
					   # Merge / mv object into tree
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -672,6 +683,7 @@ def emulator():
 | 
				
			||||||
   # write to .source?
 | 
					   # write to .source?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   # sys.exit(1)
 | 
					   # sys.exit(1)
 | 
				
			||||||
 | 
					   print("Finished " + type + "/" + object_id + repr(params))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def commandline():
 | 
					def commandline():
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -33,3 +33,5 @@
 | 
				
			||||||
- Allow manifest to be read from stdin
 | 
					- Allow manifest to be read from stdin
 | 
				
			||||||
- Create new video for cdist 2.0.0
 | 
					- Create new video for cdist 2.0.0
 | 
				
			||||||
   http://www.youtube.com/watch?v=PRMjzy48eTI
 | 
					   http://www.youtube.com/watch?v=PRMjzy48eTI
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- Setup __debug, if -d is given, so other tools can reuse it
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue