Example #1
0
def load_action(actionfile, target_action):
  """ Load the action data """
  action_ds = utils.load_json_file(actionfile)
  actionnames = action_ds.keys()

  if len(actionnames) > 1:
    raise InvalidValueException('Found > 1 action in [%s] - %s' % (actionfile, actionfile))

  actionname = actionnames[0]
  if actionname != target_action:
    raise InvalidValueException('Found invalid action [%s] - expecting %s' % \
                                (actionname, target_action))

  return action_ds
Example #2
0
  def _load_from_cache(self, only_pickle=False):
    """ Method to load from cache - abstract how data is cached """
    data = {}

    if not only_pickle:
      json_files = glob.glob(os.path.join(self.cache_dir, '*.json'))
      for json_file in json_files:
        data.update(utils.load_json_file(json_file))

    pickled_files = glob.glob(os.path.join(self.cache_dir, '*.pickle'))
    for pickled_file in pickled_files:
      with open(pickled_file) as fdesc:
        data.update(pickle.load(fdesc))

    return data
Example #3
0
    def extract_uris(self):
        """ Extract uris from target files """
        target = None

        try:
            target = utils.load_json_file(self.targetfile)
        except ValueError:
            with open(self.targetfile) as fdesc:
                target = pickle.load(fdesc)

        for target_key, target_values in target.iteritems():
            key = None

            if "filter" not in target_values:
                key = target_key
            else:
                key = target_key + target_values["filter"]

            self.uris[key] = {"categories": target_values["categories"]}
        return self.uris
Example #4
0
def cli(ctx, **kwargs):
  """ Manage device42 bulk operations """
  print 'STATUS: Loading config file %s' % kwargs['configfile']
  ctx.obj['config'] = utils.load_json_file(kwargs['configfile'])
  validate_config(ctx.obj['config'])