move file_to_list to cdist
Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
This commit is contained in:
		
					parent
					
						
							
								cf97fd9837
							
						
					
				
			
			
				commit
				
					
						e26f612012
					
				
			
		
					 3 changed files with 16 additions and 23 deletions
				
			
		| 
						 | 
					@ -34,3 +34,17 @@ class MissingEnvironmentVariableError(Error):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __str__(self):
 | 
					    def __str__(self):
 | 
				
			||||||
        return 'Missing required environment variable: ' + str(self.name)
 | 
					        return 'Missing required environment variable: ' + str(self.name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def file_to_list(filename):
 | 
				
			||||||
 | 
					    """Return list from \n seperated file"""
 | 
				
			||||||
 | 
					    if os.path.isfile(filename):
 | 
				
			||||||
 | 
					        file_fd = open(filename, "r")
 | 
				
			||||||
 | 
					        lines = file_fd.readlines()
 | 
				
			||||||
 | 
					        file_fd.close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # Remove \n from all lines
 | 
				
			||||||
 | 
					        lines = map(lambda s: s.strip(), lines)
 | 
				
			||||||
 | 
					    else:
 | 
				
			||||||
 | 
					        lines = []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return lines
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -43,10 +43,10 @@ def run(argv):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    parser = argparse.ArgumentParser(add_help=False)
 | 
					    parser = argparse.ArgumentParser(add_help=False)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for parameter in cdist.path.file_to_list(os.path.join(param_dir, "optional")):
 | 
					    for parameter in cdist.file_to_list(os.path.join(param_dir, "optional")):
 | 
				
			||||||
        argument = "--" + parameter
 | 
					        argument = "--" + parameter
 | 
				
			||||||
        parser.add_argument(argument, action='store', required=False)
 | 
					        parser.add_argument(argument, action='store', required=False)
 | 
				
			||||||
    for parameter in cdist.path.file_to_list(os.path.join(param_dir, "required")):
 | 
					    for parameter in cdist.file_to_list(os.path.join(param_dir, "required")):
 | 
				
			||||||
        argument = "--" + parameter
 | 
					        argument = "--" + parameter
 | 
				
			||||||
        parser.add_argument(argument, action='store', required=True)
 | 
					        parser.add_argument(argument, action='store', required=True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -38,20 +38,6 @@ log = logging.getLogger(__name__)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import cdist.exec
 | 
					import cdist.exec
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def file_to_list(filename):
 | 
					 | 
				
			||||||
    """Return list from \n seperated file"""
 | 
					 | 
				
			||||||
    if os.path.isfile(filename):
 | 
					 | 
				
			||||||
        file_fd = open(filename, "r")
 | 
					 | 
				
			||||||
        lines = file_fd.readlines()
 | 
					 | 
				
			||||||
        file_fd.close()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        # Remove \n from all lines
 | 
					 | 
				
			||||||
        lines = map(lambda s: s.strip(), lines)
 | 
					 | 
				
			||||||
    else:
 | 
					 | 
				
			||||||
        lines = []
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return lines
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class Path:
 | 
					class Path:
 | 
				
			||||||
    """Class that handles path related configurations"""
 | 
					    """Class that handles path related configurations"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -92,13 +78,6 @@ class Path:
 | 
				
			||||||
        self.object_base_dir = os.path.join(self.out_dir, "object")
 | 
					        self.object_base_dir = os.path.join(self.out_dir, "object")
 | 
				
			||||||
        self.bin_dir = os.path.join(self.out_dir, "bin")
 | 
					        self.bin_dir = os.path.join(self.out_dir, "bin")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
        # List of type explorers transferred
 | 
					 | 
				
			||||||
        self.type_explorers_transferred = {}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        # objects prepared
 | 
					 | 
				
			||||||
        self.objects_prepared = []
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        # Create directories
 | 
					        # Create directories
 | 
				
			||||||
        self.__init_out_dirs()
 | 
					        self.__init_out_dirs()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue