Compare commits
2 Commits
defd991006
...
f53e5bb527
| Author | SHA1 | Date | |
|---|---|---|---|
| f53e5bb527 | |||
| f2854a0df5 |
@@ -17,6 +17,12 @@ def create_parser():
|
|||||||
epilog="WARNING: This tool performs destructive operations. Only use it if you intend to erase data from your Bluesky account."
|
epilog="WARNING: This tool performs destructive operations. Only use it if you intend to erase data from your Bluesky account."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"--yes",
|
||||||
|
action="store_true",
|
||||||
|
help="Skip confirmation prompt and proceed with destructive operations"
|
||||||
|
)
|
||||||
|
|
||||||
subparsers = parser.add_subparsers(
|
subparsers = parser.add_subparsers(
|
||||||
dest="command",
|
dest="command",
|
||||||
help="Command to execute",
|
help="Command to execute",
|
||||||
@@ -48,13 +54,14 @@ def main():
|
|||||||
config = Configuration()
|
config = Configuration()
|
||||||
config_data = config.load()
|
config_data = config.load()
|
||||||
verbose = config_data.get("verbose", False)
|
verbose = config_data.get("verbose", False)
|
||||||
log_file = Path.home() / ".config" / "skywipe" / "skywipe.log"
|
log_file = Path.home() / ".cache" / "skywipe" / "skywipe.log"
|
||||||
setup_logger(verbose=verbose, log_file=log_file)
|
setup_logger(verbose=verbose, log_file=log_file)
|
||||||
else:
|
else:
|
||||||
setup_logger(verbose=False)
|
setup_logger(verbose=False)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
registry.execute(args.command)
|
registry.execute(
|
||||||
|
args.command, skip_confirmation=getattr(args, "yes", False))
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
logger = setup_logger(verbose=False)
|
logger = setup_logger(verbose=False)
|
||||||
logger.error(f"{e}")
|
logger.error(f"{e}")
|
||||||
|
|||||||
@@ -10,9 +10,10 @@ from .quotes import delete_quotes_posts
|
|||||||
from .follows import unfollow_all
|
from .follows import unfollow_all
|
||||||
from .bookmarks import delete_bookmarks
|
from .bookmarks import delete_bookmarks
|
||||||
from .logger import get_logger
|
from .logger import get_logger
|
||||||
|
from .safeguard import require_confirmation
|
||||||
|
|
||||||
|
|
||||||
CommandHandler = Callable[[], None]
|
CommandHandler = Callable[..., None]
|
||||||
|
|
||||||
|
|
||||||
class CommandRegistry:
|
class CommandRegistry:
|
||||||
@@ -44,10 +45,13 @@ class CommandRegistry:
|
|||||||
def get_all_commands(self) -> Dict[str, str]:
|
def get_all_commands(self) -> Dict[str, str]:
|
||||||
return self._help_texts.copy()
|
return self._help_texts.copy()
|
||||||
|
|
||||||
def execute(self, name: str):
|
def execute(self, name: str, skip_confirmation: bool = False):
|
||||||
handler = self.get_handler(name)
|
handler = self.get_handler(name)
|
||||||
if handler:
|
if handler:
|
||||||
handler()
|
if name == "configure":
|
||||||
|
handler()
|
||||||
|
else:
|
||||||
|
handler(skip_confirmation)
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"Unknown command: {name}")
|
raise ValueError(f"Unknown command: {name}")
|
||||||
|
|
||||||
@@ -60,43 +64,53 @@ def run_configure():
|
|||||||
config.create()
|
config.create()
|
||||||
|
|
||||||
|
|
||||||
def run_posts():
|
def run_posts(skip_confirmation: bool = False):
|
||||||
|
require_confirmation("delete all posts", skip_confirmation)
|
||||||
delete_all_posts()
|
delete_all_posts()
|
||||||
|
|
||||||
|
|
||||||
def run_medias():
|
def run_medias(skip_confirmation: bool = False):
|
||||||
|
require_confirmation("delete all posts with media", skip_confirmation)
|
||||||
delete_posts_with_medias()
|
delete_posts_with_medias()
|
||||||
|
|
||||||
|
|
||||||
def run_likes():
|
def run_likes(skip_confirmation: bool = False):
|
||||||
|
require_confirmation("undo all likes", skip_confirmation)
|
||||||
undo_likes()
|
undo_likes()
|
||||||
|
|
||||||
|
|
||||||
def run_reposts():
|
def run_reposts(skip_confirmation: bool = False):
|
||||||
|
require_confirmation("undo all reposts", skip_confirmation)
|
||||||
undo_reposts()
|
undo_reposts()
|
||||||
|
|
||||||
|
|
||||||
def run_quotes():
|
def run_quotes(skip_confirmation: bool = False):
|
||||||
|
require_confirmation("delete all quote posts", skip_confirmation)
|
||||||
delete_quotes_posts()
|
delete_quotes_posts()
|
||||||
|
|
||||||
|
|
||||||
def run_follows():
|
def run_follows(skip_confirmation: bool = False):
|
||||||
|
require_confirmation("unfollow all accounts", skip_confirmation)
|
||||||
unfollow_all()
|
unfollow_all()
|
||||||
|
|
||||||
|
|
||||||
def run_bookmarks():
|
def run_bookmarks(skip_confirmation: bool = False):
|
||||||
|
require_confirmation("delete all bookmarks", skip_confirmation)
|
||||||
delete_bookmarks()
|
delete_bookmarks()
|
||||||
|
|
||||||
|
|
||||||
def run_all():
|
def run_all(skip_confirmation: bool = False):
|
||||||
logger = get_logger()
|
logger = get_logger()
|
||||||
|
require_confirmation(
|
||||||
|
"run all cleanup commands (posts, likes, reposts, follows, bookmarks)", skip_confirmation)
|
||||||
|
|
||||||
commands = ["posts", "likes", "reposts", "follows", "bookmarks"]
|
commands = ["posts", "likes", "reposts", "follows", "bookmarks"]
|
||||||
|
|
||||||
logger.info("Running all cleanup commands...")
|
logger.info("Running all cleanup commands...")
|
||||||
for cmd in commands:
|
for cmd in commands:
|
||||||
try:
|
try:
|
||||||
logger.info(f"Starting command: {cmd}")
|
logger.info(f"Starting command: {cmd}")
|
||||||
registry.execute(cmd)
|
registry.execute(cmd, skip_confirmation=True)
|
||||||
logger.info(f"Completed command: {cmd}")
|
logger.info(f"Completed command: {cmd}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error running '{cmd}': {e}", exc_info=True)
|
logger.error(f"Error running '{cmd}': {e}", exc_info=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user