示例#1
0
def walk_and_find_json(path, action, *action_args):
    for root, dirs, files in os.walk(path):
        for file_name in files:
            if file_name.endswith(".json"):
                file_path = os.path.join(root, file_name)
                with open(file_path, 'rt') as f:
                    try:
                        content = json.loads(f.read())
                    except IOError as e:
                        raise handlers_api.InvalidSourceError(str(e)) from e
                    except json.JSONDecodeError as e:
                        raise handlers_api.InvalidSourceError(str(e)) from e
                    action(file_path, content, *action_args)
示例#2
0
 def descriptor_file_path(self):
     yaml_path = self.resolve_relative_path(BrentSourceTree.DEFINITIONS_DIR_NAME, BrentSourceTree.LM_DIR_NAME, BrentSourceTree.DESCRIPTOR_FILE_NAME_YAML)
     yml_path = self.resolve_relative_path(BrentSourceTree.DEFINITIONS_DIR_NAME, BrentSourceTree.LM_DIR_NAME, BrentSourceTree.DESCRIPTOR_FILE_NAME_YML)
     if os.path.exists(yml_path):
         if os.path.exists(yaml_path):
             raise handlers_api.InvalidSourceError('Project has both a {0} file and a {1} file when there should only be one'.format(
                 BrentSourceTree.DESCRIPTOR_FILE_NAME_YAML, BrentSourceTree.DESCRIPTOR_FILE_NAME_YML))
         return yml_path
     else:
         return yaml_path
示例#3
0
 def discover_file_path(self):
     yaml_path = self.resolve_relative_path(OpenstackTree.DISCOVER_FILE_NAME_YAML)
     yml_path = self.resolve_relative_path(OpenstackTree.DISCOVER_FILE_NAME_YML)
     if os.path.exists(yml_path):
         if os.path.exists(yaml_path):
             raise handlers_api.InvalidSourceError('Project has both a {0} file and a {1} file when there should only be one'.format(
                 OpenstackTree.DISCOVER_FILE_NAME_YAML, OpenstackTree.DISCOVER_FILE_NAME_YML))
         return yml_path
     else:
         return yaml_path
示例#4
0
 def service_behaviour_path(self):
     uk_path = self.resolve_relative_path(TypeSourceTree.BEHAVIOUR_DIR_NAME)
     us_path = self.resolve_relative_path(TypeSourceTree.BEHAVIOR_DIR_NAME)
     if os.path.exists(us_path):
         if os.path.exists(uk_path):
             raise handlers_api.InvalidSourceError(
                 'Project has both a {0} directory and a {1} directory when there should only be one'
                 .format(TypeSourceTree.BEHAVIOUR_DIR_NAME,
                         TypeSourceTree.BEHAVIOR_DIR_NAME))
         return us_path
     else:
         return uk_path
示例#5
0
 def descriptor_template_file_path(self):
     yml_path = self.resolve_relative_path(
         AssemblySourceTree.DESCRIPTOR_DIR_NAME,
         AssemblySourceTree.DESCRIPTOR_TEMPLATE_FILE_YML)
     yaml_path = self.resolve_relative_path(
         AssemblySourceTree.DESCRIPTOR_DIR_NAME,
         AssemblySourceTree.DESCRIPTOR_TEMPLATE_FILE_YAML)
     if os.path.exists(yaml_path):
         if os.path.exists(yml_path):
             raise handlers_api.InvalidSourceError(
                 'Project has both a {0} file and a {1} file when there should only be one'
                 .format(AssemblySourceTree.DESCRIPTOR_TEMPLATE_FILE_YML,
                         AssemblySourceTree.DESCRIPTOR_TEMPLATE_FILE_YAML))
         return yaml_path
     else:
         return yml_path