Exemple #1
0
def copytree(src, dst, exclude_sub_dirs=set(), force_replace=False):
  """
  Copy content of directory from source path to the target path with possibility to exclude some directories

  :type src str
  :type dst str
  :type exclude_sub_dirs list|set
  :type force_replace bool
  """

  def copy(_src, _dst):
    from resource_management.core import shell
    # full path is required to avoid usage of system command aliases like 'cp -i', which block overwrite
    if force_replace:
      shell.checked_call(["/bin/cp", "-rfp", _src, _dst], sudo=True)
    else:
      shell.checked_call(["/bin/cp", "-rp", _src, _dst], sudo=True)

  if not sudo.path_isdir(src) or not sudo.path_isdir(dst):
    raise Fail("The source or the destination is not a folder")

  sub_dirs_to_copy = sudo.listdir(src)
  for d in sub_dirs_to_copy:
    if d not in exclude_sub_dirs:
      src_path = os.path.join(src, d)
      copy(src_path, dst)
Exemple #2
0
    def uncomplete_transactions(self):
        """
    Transactions reader

    :rtype collections.Iterable(YumTransactionItem)
    """
        transactions = {}

        prefix_len = len(self.properties.yum_tr_prefix)
        for item in sudo.listdir(self.properties.yum_lib_dir):
            if self.properties.yum_tr_prefix == item[:prefix_len]:
                tr_id = self.__extract_transaction_id(item)

                f = StringIO(
                    sudo.read_file(
                        os.path.join(self.properties.yum_lib_dir, item)))
                pkgs_in_transaction = list(self.__transaction_file_parser(f))

                if tr_id not in transactions:
                    transactions[tr_id] = YumTransactionItem(tr_id)

                if RPMTransactions.all in item:
                    transactions[tr_id].pkgs_all = pkgs_in_transaction
                elif RPMTransactions.done in item:
                    transactions[tr_id].pkgs_done = pkgs_in_transaction

        for tr in transactions.values():
            if len(tr.pkgs_all) == 0:
                continue

            if isinstance(tr, YumTransactionItem):
                yield tr
Exemple #3
0
 def _copy_from_local_directory(self, target, source):
     for next_path_part in sudo.listdir(source):
         new_source = os.path.join(source, next_path_part)
         new_target = format("{target}/{next_path_part}")
         if sudo.path_isdir(new_source):
             Logger.info(format("Creating DFS directory {new_target}"))
             self._create_directory(new_target)
             self._copy_from_local_directory(new_target, new_source)
         else:
             self._create_file(new_target, new_source)
 def _copy_from_local_directory(self, target, source):
   for next_path_part in sudo.listdir(source):
     new_source = os.path.join(source, next_path_part)
     new_target = format("{target}/{next_path_part}")
     if sudo.path_isdir(new_source):
       Logger.info(format("Creating DFS directory {new_target}"))
       self._create_directory(new_target)
       self._copy_from_local_directory(new_target, new_source)
     else:
       self._create_file(new_target, new_source)