Esempio n. 1
0
 def _load_recipe_from_file(self, filename):
     """
     Turn a .lwr file into a valid recipe datastructure.
     """
     data = PBConfigFile(filename).get()
     # Make sure dependencies is always a valid list:
     if data.has_key('depends') and data['depends'] is not None:
         if not isinstance(data['depends'], list):
             data['depends'] = [
                 data['depends'],
             ]
     else:
         data['depends'] = []
     return data
Esempio n. 2
0
 def _lint_recipe(self, recipe_file):
     """
     Check if recipe_file is a valid recipe
     """
     print("Linting recipe `{0}'".format(recipe_file))
     # Basic file checks
     try:
         recipe_dict = PBConfigFile(recipe_file).get()
     except IOError:
         self.log.error("Can't open `{0}'".format(recipe_file))
         return -1
     except AttributeError:
         self.log.error(
             "Can't parse contents of file `{0}'".format(recipe_file))
         return -1
     if not isinstance(recipe_dict, dict):
         self.log.error("Invalid recipe file. Not a dict.")
         return -1
     # Try loading as recipe
     try:
         rec = recipe.Recipe(recipe_file)
         if not hasattr(rec, 'satisfy'):
             print("[HMM] - No satisfy rules declared")
         else:
             for pkgtype in rec.satisfy.keys():
                 rec.get_package_reqs(pkgtype)
     except PBException as ex:
         print("[VERY BAD] - Recipe error: " + str(ex))
     # Check keys
     key_check = {
         'HMM': ['source', 'depends'],
         'BAD': ['inherit', 'category'],
     }
     for err_type, key_list in key_check.iteritems():
         for key in key_list:
             if not recipe_dict.has_key(key):
                 print("[{err}] Recipe doesn't have key: {key}".format(
                     err=err_type, key=key))
Esempio n. 3
0
 def _lint_recipe(self, recipe_file):
     """
     Check if recipe_file is a valid recipe
     """
     print("Linting recipe `{0}'".format(recipe_file))
     # Basic file checks
     try:
         recipe_dict = PBConfigFile(recipe_file).get()
     except IOError:
         self.log.error("Can't open `{0}'".format(recipe_file))
         return -1
     except AttributeError:
         self.log.error("Can't parse contents of file `{0}'".format(recipe_file))
         return -1
     if not isinstance(recipe_dict, dict):
         self.log.error("Invalid recipe file. Not a dict.")
         return -1
     # Try loading as recipe
     try:
         rec = recipe.Recipe(recipe_file)
         if not hasattr(rec, 'satisfy'):
             print("[HMM] - No satisfy rules declared")
         else:
             for pkgtype in rec.satisfy.keys():
                 rec.get_package_reqs(pkgtype)
     except PBException as ex:
         print("[VERY BAD] - Recipe error: " + str(ex))
     # Check keys
     key_check = {
         'HMM': ['source', 'depends'],
         'BAD': ['inherit', 'category'],
     }
     for err_type, key_list in key_check.iteritems():
         for key in key_list:
             if not recipe_dict.has_key(key):
                 print("[{err}] Recipe doesn't have key: {key}".format(err=err_type, key=key))