Exemplo n.º 1
0
def rename(old_path, new_path, old_item_name="", new_item_name=""):
    if not is_repository(old_path):
        raise RepositoryException(
            _("There is no repository by path: [%s]") % old_path)
    if os.path.exists(new_path) and not os.path.isdir(new_path):
        raise RepositoryException(_("There is file by path: [%s]") % new_path)
    elif os.path.exists(new_path) and not os.access(new_path, os.R_OK
                                                    or os.W_OK):
        raise RepositoryException(
            _("There is no access rights by path: [%s]") % new_path)

    try:
        shutil.move(old_path, new_path)
    except (shutil.Error, OSError) as e:
        raise RepositoryException(
            _("Repository [%(old_path)s] is not moved to [%(new_path)s], because of error: %(cause)s"
              ) % {
                  "old_path": old_path,
                  "new_path": new_path,
                  "cause": str(e)
              })
    if old_item_name != "":  # no group
        hgweb = HGWeb(settings.HGWEB_CONFIG)
        hgweb.del_paths(old_item_name)
        hgweb.add_paths(new_item_name, new_path)
Exemplo n.º 2
0
def delete(path, item_name=""):
    """
    Deletes single repository with it directory tree.
    """
    if not is_repository(path):
        raise RepositoryException(
            _("There is no repository by path: [%s]") % path)
    try:
        shutil.rmtree(
            path
        )  #, ignore_errors=True - to ignore any problem like "Permission denied"
    except (shutil.Error,
            OSError) as e:  #probably more specific exception is needed
        raise RepositoryException(
            _("Failed to delete [%(path)s], because of error: %(cause)s") % {
                "path": path,
                "cause": str(e)
            })
    if item_name != "":  # no group
        hgweb = HGWeb(settings.HGWEB_CONFIG)
        hgweb.del_paths(item_name)
Exemplo n.º 3
0
def delete_group(path, name, is_collection=False, delete_content=True):
    """
    Deletes group: deletes name from [paths] section of it is collection or from [collections] section;
    Also deletes directory tree py path.
    """
    hgweb = HGWeb(settings.HGWEB_CONFIG)
    try:
        if not is_collection:
            hgweb.del_paths(name)  # may throw IOError
            path = path.rstrip('*')
        else:
            hgweb.del_collections(name)  # may throw IOError
        if delete_content:
            shutil.rmtree(
                path
            )  #, ignore_errors=True - to ignore any problem like "Permission denied".
            os.makedirs(path)
        # def onerror  function to hahdle errors or handle exception shutil.Error
    except (IOError, shutil.Error) as e:
        raise RepositoryException(
            _("There is a problem while deleting group: %s") % str(e))