示例#1
0
    def copy_to_plugin_step(self,
                            xaf,
                            plugin_name,
                            step_name,
                            keep_original_basename=False,
                            info=False):
        """Copy a XattrFile (with tags) to another plugin/step.

        Args:
            xaf (XattrFile): XattrFile to move.
            plugin_name (string): plugin name.
            step_name (string): step name.
            keep_original_basename (boolean): if True, we keep the original
                basename of xaf. If False, we generate a new basename, If None,
                we use the value of first.core.original_uid tag as basename
                (if exists).
            info (boolean): if true, add INFO log messages.

        Returns:
            boolean: True if ok

        """
        basename = \
            self.__xxx_to_plugin_step_get_basename(xaf, keep_original_basename)
        old_filepath = xaf.filepath
        target_path = os.path.join(
            get_plugin_step_directory_path(plugin_name, step_name),
            basename,
        )
        result = xaf.copy_or_nothing(target_path)
        if info and result:
            self.info("File %s copied to %s" % (old_filepath, target_path))
        if result:
            self.add_trace(xaf, plugin_name, step_name)
        return result
示例#2
0
 def _init(self):
     super(AcquisitionStep, self)._init()
     self.failure_policy = self.args.failure_policy
     self.failure_policy_move_dest_dir = None
     self.failure_policy_move_absolute_dir = False
     if self.failure_policy not in ("keep", "delete", "move"):
         self.error_and_die("unknown failure policy: %s",
                            self.failure_policy)
     if self.failure_policy == "move":
         fpmdd = self.args.failure_policy_move_dest_dir
         if fpmdd is None or fpmdd == "" or fpmdd == "FIXME":
             self.error_and_die("you have to set a "
                                "failure-policy-move-dest-dir"
                                " in case of move failure policy")
         if "/" not in fpmdd:
             self.error_and_die(
                 "failure-policy-move-dest-dir must be something like "
                 "plugin_name/step_name or an absolute path")
         if fpmdd.startswith('/'):
             # absolute dir
             mkdir_p_or_die(fpmdd)
             self.add_virtual_trace(fpmdd)
             self.failure_policy_move_dest_dir = fpmdd
             self.failure_policy_move_absolute_dir = True
         else:
             # plugin_name/step_name
             plugin_name = fpmdd.split('/')[0]
             step_name = fpmdd.split('/')[1]
             self.add_virtual_trace(plugin_name, step_name)
             self.failure_policy_move_dest_dir = \
                 get_plugin_step_directory_path(plugin_name, step_name)
             mkdir_p_or_die(self.failure_policy_move_dest_dir)
     signal.signal(signal.SIGTERM, self.__sigterm_handler)
示例#3
0
def main():
    parser = argparse.ArgumentParser("Inject a file into a plugin/step")
    parser.add_argument("filepath", type=str, help="filepath to inject")
    parser.add_argument("--plugin",
                        type=str,
                        help="plugin name (default :guess_file_type)",
                        default="guess_file_type")
    parser.add_argument("--step",
                        type=str,
                        help="step name (default: main)",
                        default="main")
    parser.add_argument("--move",
                        action="store_true",
                        help="move the file instead of copying it "
                        "(default: copy)")
    parser.add_argument("--random-basename",
                        action="store_true",
                        help="use a random basename for copying/moving "
                        "the file (default: keep the original basename)")
    parser.add_argument(
        "--incoming",
        action="store_true",
        help="ignore plugin and step parameter and inject "
        "the file into the first configured directory listened"
        " by the MFDATA_INTERNAL_PLUGINS_WATCHED_DIRECTORIES env var")

    args = parser.parse_args()
    try:
        x = XattrFile(args.filepath)
    except Exception:
        logger.warning("can't open %s" % args.filepath)
        sys.exit(1)
    if args.random_basename:
        basename = get_unique_hexa_identifier()
    else:
        basename = os.path.basename(args.filepath)
    if args.incoming:
        env_var = 'MFDATA_INTERNAL_PLUGINS_WATCHED_DIRECTORIES'
        first_directory = os.environ[env_var].split(',')[0]
        new_filepath = os.path.join(os.environ['MFDATA_DATA_IN_DIR'],
                                    first_directory, basename)
    else:
        new_filepath = \
            os.path.join(get_plugin_step_directory_path(args.plugin,
                                                        args.step), basename)
    if args.move:
        res, moved = x.move_or_copy(new_filepath)
        if not res:
            logger.warning("can't move %s to %s" %
                           (args.filepath, new_filepath))
            sys.exit(1)
    else:
        res = x.copy_or_nothing(new_filepath)
        if not res:
            logger.warning("can't copy %s to %s" %
                           (args.filepath, new_filepath))
            sys.exit(1)
示例#4
0
    def copy_to_plugin_step(self, xaf, plugin_name, step_name):
        """Copy a XattrFile (with tags) to another plugin/step.

        Args:
            xaf (XattrFile): XattrFile to move
            plugin_name (string): plugin name
            step_name (string): step name

        Returns:
            boolean: True if ok

        """
        target_path = os.path.join(
            get_plugin_step_directory_path(plugin_name, step_name),
            get_unique_hexa_identifier())
        self._set_after_tags(xaf, True)
        result = xaf.copy_or_nothing(target_path)
        return result
示例#5
0
文件: step.py 项目: moas/mfdata
    def move_to_plugin_step(self, xaf, plugin_name, step_name):
        """Move a XattrFile to another plugin/step.

        Args:
            xaf (XattrFile): XattrFile to move
            plugin_name (string): plugin name
            step_name (string): step name

        Returns:
            boolean: True if ok

        """
        target_path = os.path.join(
            get_plugin_step_directory_path(plugin_name, step_name),
            get_unique_hexa_identifier(),
        )
        result, _ = xaf.move_or_copy(target_path)
        return result
示例#6
0
 def _init(self):
     AcquisitionStep._init(self)
     self.__xafs = {}
     if self.args.dest_dir is None:
         raise Exception('you have to set a dest-dir argument')
     if self.args.dest_dir == "FIXME":
         raise Exception('you have to set a dest-dir argument')
     if '/' not in self.args.dest_dir:
         raise Exception("invalid dest_dir: %s" % self.args.dest_dir)
     if self.args.dest_dir.startswith('/'):
         raise Exception("invalid dest_dir: %s, must be something like: "
                         "plugin_name/step_name" % self.args.dest_dir)
     plugin_name = self.args.dest_dir.split('/')[0]
     step_name = self.args.dest_dir.split('/')[1]
     self.add_virtual_trace(plugin_name, step_name)
     self.add_virtual_trace(">delete", "giveup")
     self.dest_dir = get_plugin_step_directory_path(plugin_name, step_name)
     mkdir_p_or_die(self.dest_dir)
     self.retry_total = self.args.retry_total
     self.retry_min_wait = self.args.retry_min_wait
     self.retry_max_wait = self.args.retry_max_wait
     self.retry_backoff = self.args.retry_backoff
示例#7
0
 def _init(self):
     AcquisitionStep._init(self)
     if self.args.dest_dir == "FIXME":
         raise Exception("dest_dir is not set")
     if '/' not in self.args.dest_dir:
         raise Exception("invalid dest_dir: %s" % self.args.dest_dir)
     if self.args.dest_dir.startswith('/'):
         self.dest_dir = self.args.dest_dir
     else:
         plugin_name = self.args.dest_dir.split('/')[0]
         step_name = self.args.dest_dir.split('/')[1]
         self.dest_dir = get_plugin_step_directory_path(plugin_name,
                                                        step_name)
     mkdir_p_or_die(self.dest_dir)
     self.add_virtual_trace(self.dest_dir)
     try:
         if self.args.drop_tags == "AUTO":
             self.drop_tags = self.args.dest_dir.startswith('/')
         elif self.args.drop_tags == "1":
             self.drop_tags = True
         elif self.args.drop_tags == "0":
             self.drop_tags = False
         else:
             raise Exception("invalid value for drop_tags configuration "
                             "key: %s" % self.args.drop_tags)
     except AttributeError:
         self.drop_tags = True
     try:
         if self.args.force_chmod == "null":
             self.force_chmod = ""
         else:
             self.force_chmod = self.args.force_chmod
     except AttributeError:
         self.force_chmod = ""
     if self.args.dest_basename == "":
         raise Exception("dest_basename can't be empty")
     self.dest_basename = self.args.dest_basename