dotctl 1.0.7__tar.gz → 1.0.9__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dotctl-1.0.7/src/dotctl.egg-info → dotctl-1.0.9}/PKG-INFO +25 -2
- {dotctl-1.0.7 → dotctl-1.0.9}/README.md +24 -1
- {dotctl-1.0.7 → dotctl-1.0.9}/pyproject.toml +1 -1
- {dotctl-1.0.7 → dotctl-1.0.9}/src/dotctl/actions/activator.py +3 -3
- {dotctl-1.0.7 → dotctl-1.0.9}/src/dotctl/actions/creator.py +2 -2
- {dotctl-1.0.7 → dotctl-1.0.9}/src/dotctl/actions/exporter.py +2 -2
- {dotctl-1.0.7 → dotctl-1.0.9}/src/dotctl/actions/importer.py +5 -5
- {dotctl-1.0.7 → dotctl-1.0.9}/src/dotctl/actions/initializer.py +1 -1
- {dotctl-1.0.7 → dotctl-1.0.9}/src/dotctl/actions/puller.py +1 -1
- {dotctl-1.0.7 → dotctl-1.0.9}/src/dotctl/actions/remover.py +7 -7
- {dotctl-1.0.7 → dotctl-1.0.9}/src/dotctl/actions/saver.py +50 -4
- {dotctl-1.0.7 → dotctl-1.0.9}/src/dotctl/actions/switcher.py +5 -5
- {dotctl-1.0.7 → dotctl-1.0.9}/src/dotctl/actions/wiper.py +4 -4
- {dotctl-1.0.7 → dotctl-1.0.9}/src/dotctl/arg_manager.py +7 -1
- {dotctl-1.0.7 → dotctl-1.0.9}/src/dotctl/handlers/data_handler.py +80 -24
- {dotctl-1.0.7 → dotctl-1.0.9}/src/dotctl/handlers/git_handler.py +11 -8
- {dotctl-1.0.7 → dotctl-1.0.9}/src/dotctl/main.py +2 -1
- {dotctl-1.0.7 → dotctl-1.0.9/src/dotctl.egg-info}/PKG-INFO +25 -2
- {dotctl-1.0.7 → dotctl-1.0.9}/LICENSE +0 -0
- {dotctl-1.0.7 → dotctl-1.0.9}/setup.cfg +0 -0
- {dotctl-1.0.7 → dotctl-1.0.9}/src/dotctl/__init__.py +0 -0
- {dotctl-1.0.7 → dotctl-1.0.9}/src/dotctl/actions/__init__.py +0 -0
- {dotctl-1.0.7 → dotctl-1.0.9}/src/dotctl/actions/lister.py +0 -0
- {dotctl-1.0.7 → dotctl-1.0.9}/src/dotctl/exception.py +0 -0
- {dotctl-1.0.7 → dotctl-1.0.9}/src/dotctl/handlers/__init__.py +0 -0
- {dotctl-1.0.7 → dotctl-1.0.9}/src/dotctl/handlers/config_handler.py +0 -0
- {dotctl-1.0.7 → dotctl-1.0.9}/src/dotctl/handlers/hooks_handler.py +0 -0
- {dotctl-1.0.7 → dotctl-1.0.9}/src/dotctl/hooks/post_apply.sh +0 -0
- {dotctl-1.0.7 → dotctl-1.0.9}/src/dotctl/hooks/pre_apply.sh +0 -0
- {dotctl-1.0.7 → dotctl-1.0.9}/src/dotctl/paths.py +0 -0
- {dotctl-1.0.7 → dotctl-1.0.9}/src/dotctl/templates/__init__.py +0 -0
- {dotctl-1.0.7 → dotctl-1.0.9}/src/dotctl/templates/dev.yaml +0 -0
- {dotctl-1.0.7 → dotctl-1.0.9}/src/dotctl/templates/kde.yaml +0 -0
- {dotctl-1.0.7 → dotctl-1.0.9}/src/dotctl/templates/other.yaml +0 -0
- {dotctl-1.0.7 → dotctl-1.0.9}/src/dotctl/utils.py +0 -0
- {dotctl-1.0.7 → dotctl-1.0.9}/src/dotctl/validators.py +0 -0
- {dotctl-1.0.7 → dotctl-1.0.9}/src/dotctl.egg-info/SOURCES.txt +0 -0
- {dotctl-1.0.7 → dotctl-1.0.9}/src/dotctl.egg-info/dependency_links.txt +0 -0
- {dotctl-1.0.7 → dotctl-1.0.9}/src/dotctl.egg-info/entry_points.txt +0 -0
- {dotctl-1.0.7 → dotctl-1.0.9}/src/dotctl.egg-info/requires.txt +0 -0
- {dotctl-1.0.7 → dotctl-1.0.9}/src/dotctl.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dotctl
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.9
|
|
4
4
|
Summary: A powerful CLI tool to profile your OS by saving, applying, exporting, and importing system configurations as named profiles. Designed to manage dot files and service configurations in a centralized Git repository (local or remote), dotctl enables seamless system replication across machines. Supports pre/post hook scripts, making it ideal for setting up servers or desktops with consistent environments.
|
|
5
5
|
Author-email: Pankaj Jackson <pankajackson@live.co.uk>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -57,6 +57,7 @@ Designed for developers and sysadmins, it supports pre/post hook scripts and is
|
|
|
57
57
|
- [🆕 `create` / `new`](#-create--new)
|
|
58
58
|
- [❌ `remove` / `rm` / `delete` / `del`](#-remove--rm--delete--del)
|
|
59
59
|
- [🧪 `apply`](#-apply)
|
|
60
|
+
- [🔄 `pull`](#-pull)
|
|
60
61
|
- [📤 `export`](#-export)
|
|
61
62
|
- [📥 `import`](#-import)
|
|
62
63
|
- [🔥 `wipe`](#-wipe)
|
|
@@ -77,6 +78,7 @@ Designed for developers and sysadmins, it supports pre/post hook scripts and is
|
|
|
77
78
|
- 🔄 **Git Integration** — Sync profiles with local or remote Git repositories.
|
|
78
79
|
- 📁 **Portable Configs** — Export/import profiles using `.dtsv` files for easy backups and sharing.
|
|
79
80
|
- ⚙️ **Custom Configs** — Define tracking rules via `dotctl.yaml`.
|
|
81
|
+
- 🧹 **Prune Support** — Clean stale files no longer listed in your profile with --prune.
|
|
80
82
|
|
|
81
83
|
---
|
|
82
84
|
|
|
@@ -381,7 +383,7 @@ dotctl init -c ./my_custom_config.yaml
|
|
|
381
383
|
Save current system state to the active profile.
|
|
382
384
|
|
|
383
385
|
```sh
|
|
384
|
-
dotctl save [-h] [-p <password>] [--skip-sudo] [profile]
|
|
386
|
+
dotctl save [-h] [-p <password>] [--skip-sudo] [--prune] [profile]
|
|
385
387
|
```
|
|
386
388
|
|
|
387
389
|
**Examples:**
|
|
@@ -390,12 +392,17 @@ dotctl save [-h] [-p <password>] [--skip-sudo] [profile]
|
|
|
390
392
|
dotctl save
|
|
391
393
|
dotctl save my_web_server --skip-sudo
|
|
392
394
|
dotctl save my_web_server -p mYsecretp@ssw0rd
|
|
395
|
+
dotctl save --prune
|
|
393
396
|
```
|
|
394
397
|
|
|
398
|
+
> Tip: Use --prune to clean files that were saved before but are no longer listed in the config.
|
|
399
|
+
|
|
395
400
|
**Options:**
|
|
396
401
|
|
|
397
402
|
- `--skip-sudo` – Ignore restricted resources.
|
|
398
403
|
- `-p, --password` – Password for restricted resources.
|
|
404
|
+
- `--prune` – Remove stale files from the dot repo that are no longer listed in the current `dotctl.yaml` config.
|
|
405
|
+
- `profile` – Target profile to save into (defaults to the active one if not provided)
|
|
399
406
|
|
|
400
407
|
---
|
|
401
408
|
|
|
@@ -524,6 +531,22 @@ dotctl apply MyProfile --skip-pre-hooks --ignore-hook-errors
|
|
|
524
531
|
|
|
525
532
|
---
|
|
526
533
|
|
|
534
|
+
### 🔄 `pull`
|
|
535
|
+
|
|
536
|
+
Pull the latest changes from the dotfiles repository.
|
|
537
|
+
|
|
538
|
+
```sh
|
|
539
|
+
dotctl pull [-h]
|
|
540
|
+
```
|
|
541
|
+
|
|
542
|
+
**Examples:**
|
|
543
|
+
|
|
544
|
+
```sh
|
|
545
|
+
dotctl pull
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
---
|
|
549
|
+
|
|
527
550
|
### 📤 `export`
|
|
528
551
|
|
|
529
552
|
Export a profile to `.dtsv`.
|
|
@@ -31,6 +31,7 @@ Designed for developers and sysadmins, it supports pre/post hook scripts and is
|
|
|
31
31
|
- [🆕 `create` / `new`](#-create--new)
|
|
32
32
|
- [❌ `remove` / `rm` / `delete` / `del`](#-remove--rm--delete--del)
|
|
33
33
|
- [🧪 `apply`](#-apply)
|
|
34
|
+
- [🔄 `pull`](#-pull)
|
|
34
35
|
- [📤 `export`](#-export)
|
|
35
36
|
- [📥 `import`](#-import)
|
|
36
37
|
- [🔥 `wipe`](#-wipe)
|
|
@@ -51,6 +52,7 @@ Designed for developers and sysadmins, it supports pre/post hook scripts and is
|
|
|
51
52
|
- 🔄 **Git Integration** — Sync profiles with local or remote Git repositories.
|
|
52
53
|
- 📁 **Portable Configs** — Export/import profiles using `.dtsv` files for easy backups and sharing.
|
|
53
54
|
- ⚙️ **Custom Configs** — Define tracking rules via `dotctl.yaml`.
|
|
55
|
+
- 🧹 **Prune Support** — Clean stale files no longer listed in your profile with --prune.
|
|
54
56
|
|
|
55
57
|
---
|
|
56
58
|
|
|
@@ -355,7 +357,7 @@ dotctl init -c ./my_custom_config.yaml
|
|
|
355
357
|
Save current system state to the active profile.
|
|
356
358
|
|
|
357
359
|
```sh
|
|
358
|
-
dotctl save [-h] [-p <password>] [--skip-sudo] [profile]
|
|
360
|
+
dotctl save [-h] [-p <password>] [--skip-sudo] [--prune] [profile]
|
|
359
361
|
```
|
|
360
362
|
|
|
361
363
|
**Examples:**
|
|
@@ -364,12 +366,17 @@ dotctl save [-h] [-p <password>] [--skip-sudo] [profile]
|
|
|
364
366
|
dotctl save
|
|
365
367
|
dotctl save my_web_server --skip-sudo
|
|
366
368
|
dotctl save my_web_server -p mYsecretp@ssw0rd
|
|
369
|
+
dotctl save --prune
|
|
367
370
|
```
|
|
368
371
|
|
|
372
|
+
> Tip: Use --prune to clean files that were saved before but are no longer listed in the config.
|
|
373
|
+
|
|
369
374
|
**Options:**
|
|
370
375
|
|
|
371
376
|
- `--skip-sudo` – Ignore restricted resources.
|
|
372
377
|
- `-p, --password` – Password for restricted resources.
|
|
378
|
+
- `--prune` – Remove stale files from the dot repo that are no longer listed in the current `dotctl.yaml` config.
|
|
379
|
+
- `profile` – Target profile to save into (defaults to the active one if not provided)
|
|
373
380
|
|
|
374
381
|
---
|
|
375
382
|
|
|
@@ -498,6 +505,22 @@ dotctl apply MyProfile --skip-pre-hooks --ignore-hook-errors
|
|
|
498
505
|
|
|
499
506
|
---
|
|
500
507
|
|
|
508
|
+
### 🔄 `pull`
|
|
509
|
+
|
|
510
|
+
Pull the latest changes from the dotfiles repository.
|
|
511
|
+
|
|
512
|
+
```sh
|
|
513
|
+
dotctl pull [-h]
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
**Examples:**
|
|
517
|
+
|
|
518
|
+
```sh
|
|
519
|
+
dotctl pull
|
|
520
|
+
```
|
|
521
|
+
|
|
522
|
+
---
|
|
523
|
+
|
|
501
524
|
### 📤 `export`
|
|
502
525
|
|
|
503
526
|
Export a profile to `.dtsv`.
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "dotctl"
|
|
7
|
-
version = "v1.0.
|
|
7
|
+
version = "v1.0.9"
|
|
8
8
|
description = "A powerful CLI tool to profile your OS by saving, applying, exporting, and importing system configurations as named profiles. Designed to manage dot files and service configurations in a centralized Git repository (local or remote), dotctl enables seamless system replication across machines. Supports pre/post hook scripts, making it ideal for setting up servers or desktops with consistent environments."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "MIT"
|
|
@@ -54,13 +54,13 @@ def apply(props: ActivatorProps) -> None:
|
|
|
54
54
|
checkout_branch(repo, profile)
|
|
55
55
|
log(f"Switched to profile: {profile}")
|
|
56
56
|
else:
|
|
57
|
-
log(f"Profile {profile} is not available.")
|
|
57
|
+
log(f"❌ Profile {profile} is not available.")
|
|
58
58
|
return
|
|
59
59
|
|
|
60
60
|
config = conf_reader(config_file=Path(app_config_file))
|
|
61
61
|
|
|
62
62
|
if pull_changes(repo):
|
|
63
|
-
log("
|
|
63
|
+
log("Pulled latest changes from cloud successfully.")
|
|
64
64
|
|
|
65
65
|
if not props.skip_hooks and not props.skip_pre_hooks:
|
|
66
66
|
run_hooks(
|
|
@@ -95,4 +95,4 @@ def apply(props: ActivatorProps) -> None:
|
|
|
95
95
|
ignore_errors=props.ignore_hook_errors,
|
|
96
96
|
timeout=props.hooks_timeout,
|
|
97
97
|
)
|
|
98
|
-
log("✅ Profile
|
|
98
|
+
log("✅ Profile applied successfully!")
|
|
@@ -53,7 +53,7 @@ def create(props: CreatorProps):
|
|
|
53
53
|
|
|
54
54
|
_, _, _, all_profiles = get_repo_branches(repo)
|
|
55
55
|
if props.profile in all_profiles:
|
|
56
|
-
log(f"Profile '{props.profile}' already exists.")
|
|
56
|
+
log(f"❌ Profile '{props.profile}' already exists.")
|
|
57
57
|
return
|
|
58
58
|
if props.env or props.config:
|
|
59
59
|
if props.config is not None and isinstance(props.config, str):
|
|
@@ -86,4 +86,4 @@ def create(props: CreatorProps):
|
|
|
86
86
|
else:
|
|
87
87
|
push_existing_branch(repo=repo)
|
|
88
88
|
|
|
89
|
-
log(f"Profile '{props.profile}' created and activated successfully.")
|
|
89
|
+
log(f"✅ Profile '{props.profile}' created and activated successfully.")
|
|
@@ -67,7 +67,7 @@ def exporter(props: ExporterProps) -> None:
|
|
|
67
67
|
checkout_branch(repo, profile)
|
|
68
68
|
log(f"Switched to profile: {profile}")
|
|
69
69
|
else:
|
|
70
|
-
log(f"Profile '{profile}' not found.")
|
|
70
|
+
log(f"❌ Profile '{profile}' not found.")
|
|
71
71
|
return
|
|
72
72
|
|
|
73
73
|
# Copy profile files
|
|
@@ -117,7 +117,7 @@ def exporter(props: ExporterProps) -> None:
|
|
|
117
117
|
shutil.move(archive_file, export_profile_path.with_suffix(__EXPORT_EXTENSION__))
|
|
118
118
|
|
|
119
119
|
log(
|
|
120
|
-
f"Successfully exported to {export_profile_path.with_suffix(__EXPORT_EXTENSION__)}"
|
|
120
|
+
f"✅ Successfully exported to {export_profile_path.with_suffix(__EXPORT_EXTENSION__)}"
|
|
121
121
|
)
|
|
122
122
|
finally:
|
|
123
123
|
shutil.rmtree(export_profile_path, ignore_errors=True)
|
|
@@ -40,17 +40,17 @@ importer_default_props = ImporterProps(
|
|
|
40
40
|
def importer(props: ImporterProps) -> None:
|
|
41
41
|
log("Importing profile...")
|
|
42
42
|
if not props.profile:
|
|
43
|
-
log("No profile specified")
|
|
43
|
+
log("❌ No profile specified")
|
|
44
44
|
return
|
|
45
45
|
|
|
46
46
|
profile_path = Path(props.profile)
|
|
47
47
|
|
|
48
48
|
if not is_zipfile(profile_path):
|
|
49
|
-
log("Invalid Profile file")
|
|
49
|
+
log("❌ Invalid Profile file")
|
|
50
50
|
return
|
|
51
51
|
|
|
52
52
|
if profile_path.suffix != __EXPORT_EXTENSION__:
|
|
53
|
-
log("Unsupported Profile file")
|
|
53
|
+
log("❌ Unsupported Profile file")
|
|
54
54
|
return
|
|
55
55
|
|
|
56
56
|
# Setup variables
|
|
@@ -62,7 +62,7 @@ def importer(props: ImporterProps) -> None:
|
|
|
62
62
|
# Create profile branch
|
|
63
63
|
_, remote_profiles, active_profile, all_profiles = get_repo_branches(repo)
|
|
64
64
|
if profile_name in all_profiles:
|
|
65
|
-
log(f"Profile '{profile_name}' already exists")
|
|
65
|
+
log(f"❌ Profile '{profile_name}' already exists")
|
|
66
66
|
return
|
|
67
67
|
|
|
68
68
|
create_branch(repo=repo, branch=profile_name)
|
|
@@ -127,7 +127,7 @@ def importer(props: ImporterProps) -> None:
|
|
|
127
127
|
checkout_branch(repo, active_profile)
|
|
128
128
|
log(f"Switched back to profile: {active_profile}")
|
|
129
129
|
|
|
130
|
-
log("Profile Imported successfully!")
|
|
130
|
+
log("✅ Profile Imported successfully!")
|
|
131
131
|
|
|
132
132
|
finally:
|
|
133
133
|
shutil.rmtree(temp_profile_dir, ignore_errors=True)
|
|
@@ -39,7 +39,7 @@ def remove(props: RemoverProps):
|
|
|
39
39
|
|
|
40
40
|
try:
|
|
41
41
|
if repo.bare:
|
|
42
|
-
print("The repository is bare. No profiles available.")
|
|
42
|
+
print("❌ The repository is bare. No profiles available.")
|
|
43
43
|
return
|
|
44
44
|
|
|
45
45
|
if props.fetch:
|
|
@@ -54,16 +54,16 @@ def remove(props: RemoverProps):
|
|
|
54
54
|
# Delete local branch if it exists
|
|
55
55
|
if profile in local_profiles:
|
|
56
56
|
delete_local_branch(repo, profile)
|
|
57
|
-
log(f"Local profile '{profile}' removed successfully.")
|
|
57
|
+
log(f"✅ Local profile '{profile}' removed successfully.")
|
|
58
58
|
else:
|
|
59
|
-
log(f"Profile '{profile}' does not exist locally.")
|
|
59
|
+
log(f"❎ Profile '{profile}' does not exist locally.")
|
|
60
60
|
|
|
61
61
|
# Delete remote branch if it exists
|
|
62
62
|
if is_remote_repo(repo=repo):
|
|
63
63
|
if profile in remote_profiles:
|
|
64
64
|
if props.no_confirm:
|
|
65
65
|
delete_remote_branch(repo, profile)
|
|
66
|
-
log(f"Remote profile '{profile}' removed successfully.")
|
|
66
|
+
log(f"✅ Remote profile '{profile}' removed successfully.")
|
|
67
67
|
return
|
|
68
68
|
else:
|
|
69
69
|
# Ask for confirmation
|
|
@@ -72,13 +72,13 @@ def remove(props: RemoverProps):
|
|
|
72
72
|
)
|
|
73
73
|
if confirm.lower() == "y":
|
|
74
74
|
delete_remote_branch(repo, profile)
|
|
75
|
-
log(f"Remote profile '{profile}' removed successfully.")
|
|
75
|
+
log(f"✅ Remote profile '{profile}' removed successfully.")
|
|
76
76
|
return
|
|
77
77
|
else:
|
|
78
|
-
log("Remote profile deletion aborted by user.")
|
|
78
|
+
log("🛑 Remote profile deletion aborted by user.")
|
|
79
79
|
return
|
|
80
80
|
|
|
81
|
-
log(f"Profile '{profile}' does not exist on cloud.")
|
|
81
|
+
log(f"❎ Profile '{profile}' does not exist on cloud.")
|
|
82
82
|
|
|
83
83
|
except Exception as e:
|
|
84
84
|
raise Exception(f"Unexpected error: {e}")
|
|
@@ -3,7 +3,7 @@ import socket
|
|
|
3
3
|
from datetime import datetime
|
|
4
4
|
from pathlib import Path
|
|
5
5
|
from dotctl.utils import log
|
|
6
|
-
from dotctl.handlers.data_handler import copy
|
|
6
|
+
from dotctl.handlers.data_handler import copy, delete
|
|
7
7
|
from dotctl.paths import app_profile_directory, app_config_file
|
|
8
8
|
from dotctl.handlers.config_handler import conf_reader
|
|
9
9
|
from dotctl.handlers.git_handler import (
|
|
@@ -28,12 +28,14 @@ class SaverProps:
|
|
|
28
28
|
skip_sudo: bool
|
|
29
29
|
password: str | None
|
|
30
30
|
profile: str | None
|
|
31
|
+
prune: bool
|
|
31
32
|
|
|
32
33
|
|
|
33
34
|
saver_default_props = SaverProps(
|
|
34
35
|
skip_sudo=False,
|
|
35
36
|
password=None,
|
|
36
37
|
profile=None,
|
|
38
|
+
prune=False,
|
|
37
39
|
)
|
|
38
40
|
|
|
39
41
|
|
|
@@ -56,7 +58,7 @@ def save(props: SaverProps) -> None:
|
|
|
56
58
|
create_branch(repo=repo, branch=profile)
|
|
57
59
|
log(f"Profile '{profile}' created and activated successfully.")
|
|
58
60
|
if pull_changes(repo):
|
|
59
|
-
log("
|
|
61
|
+
log("Pulled latest changes from cloud successfully.")
|
|
60
62
|
|
|
61
63
|
config = conf_reader(config_file=Path(app_config_file))
|
|
62
64
|
|
|
@@ -69,7 +71,11 @@ def save(props: SaverProps) -> None:
|
|
|
69
71
|
source = source_base_dir / entry
|
|
70
72
|
dest = dest_base_dir / entry
|
|
71
73
|
result = copy(
|
|
72
|
-
source,
|
|
74
|
+
source,
|
|
75
|
+
dest,
|
|
76
|
+
skip_sudo=props.skip_sudo,
|
|
77
|
+
sudo_pass=props.password,
|
|
78
|
+
prune=props.prune,
|
|
73
79
|
)
|
|
74
80
|
|
|
75
81
|
# Updated props
|
|
@@ -80,6 +86,46 @@ def save(props: SaverProps) -> None:
|
|
|
80
86
|
if sudo_pass is not None:
|
|
81
87
|
props.password = sudo_pass
|
|
82
88
|
|
|
89
|
+
# Dots Config Cleanup
|
|
90
|
+
if props.prune:
|
|
91
|
+
dot_list = [
|
|
92
|
+
p
|
|
93
|
+
for p in profile_dir.iterdir()
|
|
94
|
+
if p.is_dir() and p.name not in [".git", "hooks"]
|
|
95
|
+
]
|
|
96
|
+
for dot in dot_list:
|
|
97
|
+
if dot.name not in config.save.keys():
|
|
98
|
+
log(f'Removing "{dot.name}"...')
|
|
99
|
+
result = delete(
|
|
100
|
+
path=profile_dir / dot.name,
|
|
101
|
+
skip_sudo=props.skip_sudo,
|
|
102
|
+
sudo_pass=props.password,
|
|
103
|
+
)
|
|
104
|
+
# Updated props
|
|
105
|
+
if result is not None:
|
|
106
|
+
skip_sudo, sudo_pass = result
|
|
107
|
+
if skip_sudo is not None:
|
|
108
|
+
props.skip_sudo = skip_sudo
|
|
109
|
+
if sudo_pass is not None:
|
|
110
|
+
props.password = sudo_pass
|
|
111
|
+
else:
|
|
112
|
+
entry_list = dot.iterdir()
|
|
113
|
+
for entry in entry_list:
|
|
114
|
+
if entry.name not in config.save[dot.name].entries:
|
|
115
|
+
log(f'Removing "{dot.name}:{entry.name}"...')
|
|
116
|
+
result = delete(
|
|
117
|
+
path=profile_dir / dot.name / entry.name,
|
|
118
|
+
skip_sudo=props.skip_sudo,
|
|
119
|
+
sudo_pass=props.password,
|
|
120
|
+
)
|
|
121
|
+
# Updated props
|
|
122
|
+
if result is not None:
|
|
123
|
+
skip_sudo, sudo_pass = result
|
|
124
|
+
if skip_sudo is not None:
|
|
125
|
+
props.skip_sudo = skip_sudo
|
|
126
|
+
if sudo_pass is not None:
|
|
127
|
+
props.password = sudo_pass
|
|
128
|
+
|
|
83
129
|
add_changes(repo=repo)
|
|
84
130
|
if is_repo_changed(repo=repo):
|
|
85
131
|
hostname = socket.gethostname()
|
|
@@ -97,4 +143,4 @@ def save(props: SaverProps) -> None:
|
|
|
97
143
|
push_existing_branch(repo=repo)
|
|
98
144
|
log("✅ Profile saved successfully!")
|
|
99
145
|
else:
|
|
100
|
-
log("No changes detected!")
|
|
146
|
+
log("ℹ️ No changes detected!")
|
|
@@ -34,7 +34,7 @@ def switch(props: SwitcherProps):
|
|
|
34
34
|
repo = get_repo(props.profile_dir)
|
|
35
35
|
|
|
36
36
|
if repo.bare:
|
|
37
|
-
log("The repository is bare. No Profile available.")
|
|
37
|
+
log("❌ The repository is bare. No Profile available.")
|
|
38
38
|
sys.exit(1)
|
|
39
39
|
|
|
40
40
|
local_profiles, remote_profiles, active_profile, all_profiles = get_repo_branches(
|
|
@@ -52,7 +52,7 @@ def switch(props: SwitcherProps):
|
|
|
52
52
|
)
|
|
53
53
|
|
|
54
54
|
if profile_name == active_profile:
|
|
55
|
-
log(f"Already on the current profile: {profile_name}")
|
|
55
|
+
log(f"ℹ️ Already on the current profile: {profile_name}")
|
|
56
56
|
return
|
|
57
57
|
|
|
58
58
|
# Fetch remote branches if requested
|
|
@@ -64,10 +64,10 @@ def switch(props: SwitcherProps):
|
|
|
64
64
|
if profile_name in local_profiles:
|
|
65
65
|
# Checkout local branch
|
|
66
66
|
checkout_branch(repo, profile_name)
|
|
67
|
-
log(f"Switched to profile: {profile_name}")
|
|
67
|
+
log(f"✅ Switched to profile: {profile_name}")
|
|
68
68
|
elif profile_name in remote_profiles:
|
|
69
69
|
# Checkout and track remote branch automatically
|
|
70
70
|
checkout_branch(repo, profile_name)
|
|
71
|
-
log(f"Downloaded and switched to new profile from cloud: {profile_name}")
|
|
71
|
+
log(f"✅ Downloaded and switched to new profile from cloud: {profile_name}")
|
|
72
72
|
else:
|
|
73
|
-
log(f"Profile '{profile_name}' is not available in the repository.")
|
|
73
|
+
log(f"❌ Profile '{profile_name}' is not available in the repository.")
|
|
@@ -29,7 +29,7 @@ def wipe(props: WiperProps):
|
|
|
29
29
|
try:
|
|
30
30
|
if props.no_confirm:
|
|
31
31
|
shutil.rmtree(props.profile_dir)
|
|
32
|
-
log(f"Profile directory '{props.profile_dir}' removed successfully.")
|
|
32
|
+
log(f"🗑️ Profile directory '{props.profile_dir}' removed successfully.")
|
|
33
33
|
return
|
|
34
34
|
else:
|
|
35
35
|
# Ask for confirmation
|
|
@@ -42,12 +42,12 @@ def wipe(props: WiperProps):
|
|
|
42
42
|
timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
|
|
43
43
|
backup_dir = f"{props.profile_dir}_backup_{timestamp}"
|
|
44
44
|
shutil.copytree(props.profile_dir, backup_dir)
|
|
45
|
-
log(f"Backup directory '{backup_dir}' created successfully.")
|
|
45
|
+
log(f"💾 Backup directory '{backup_dir}' created successfully.")
|
|
46
46
|
shutil.rmtree(props.profile_dir)
|
|
47
|
-
log(f"Profile directory '{props.profile_dir}' removed successfully.")
|
|
47
|
+
log(f"🗑️ Profile directory '{props.profile_dir}' removed successfully.")
|
|
48
48
|
return
|
|
49
49
|
else:
|
|
50
|
-
log("Profile wipe process aborted by user.")
|
|
50
|
+
log("🛑 Profile wipe process aborted by user.")
|
|
51
51
|
return
|
|
52
52
|
except Exception as e:
|
|
53
53
|
raise Exception(f"Unexpected error: {e}")
|
|
@@ -70,11 +70,17 @@ def get_parser() -> argparse.ArgumentParser:
|
|
|
70
70
|
action="store_true",
|
|
71
71
|
help="Skip all sudo operations",
|
|
72
72
|
)
|
|
73
|
+
save_parser.add_argument(
|
|
74
|
+
"--prune",
|
|
75
|
+
required=False,
|
|
76
|
+
action="store_true",
|
|
77
|
+
help="Prune all previously saved data not present in the current profile",
|
|
78
|
+
)
|
|
73
79
|
save_parser.add_argument(
|
|
74
80
|
"profile",
|
|
75
81
|
nargs="?", # Makes positional argument optional
|
|
76
82
|
type=str,
|
|
77
|
-
help="
|
|
83
|
+
help="Target profile to save into (defaults to the active one if not provided)",
|
|
78
84
|
default=None,
|
|
79
85
|
)
|
|
80
86
|
|
|
@@ -49,6 +49,35 @@ def rsync(
|
|
|
49
49
|
return stdout.strip()
|
|
50
50
|
|
|
51
51
|
|
|
52
|
+
def remove_file_or_dir(
|
|
53
|
+
location: Path,
|
|
54
|
+
sudo_pass: str | None = None,
|
|
55
|
+
):
|
|
56
|
+
command = ["rm", "-rf", str(location)]
|
|
57
|
+
if sudo_pass:
|
|
58
|
+
command = ["sshpass", "-p", sudo_pass, "sudo"] + command
|
|
59
|
+
|
|
60
|
+
process = subprocess.Popen(
|
|
61
|
+
command,
|
|
62
|
+
stdin=subprocess.PIPE,
|
|
63
|
+
stdout=subprocess.PIPE,
|
|
64
|
+
stderr=subprocess.PIPE,
|
|
65
|
+
text=True,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
stdout, stderr = process.communicate()
|
|
69
|
+
|
|
70
|
+
if process.returncode != 0:
|
|
71
|
+
log(f"cleanup failed: {stderr.strip()}")
|
|
72
|
+
|
|
73
|
+
if "Permission denied" in stderr or process.returncode == 13:
|
|
74
|
+
raise PermissionError(stdout.strip() or stderr.strip())
|
|
75
|
+
|
|
76
|
+
raise subprocess.CalledProcessError(process.returncode, command, stderr)
|
|
77
|
+
|
|
78
|
+
return stdout.strip()
|
|
79
|
+
|
|
80
|
+
|
|
52
81
|
def get_sudo_pass(path: Path, sudo_max_attempts: int = 3):
|
|
53
82
|
"""Prompt for sudo password and handle user choices."""
|
|
54
83
|
log(f"Required sudo to process {path}")
|
|
@@ -104,39 +133,66 @@ def run_command(command: str, sudo_pass: str | None = None):
|
|
|
104
133
|
return False, e.stderr.strip() if e.stderr else "", e.returncode # Failure
|
|
105
134
|
|
|
106
135
|
|
|
136
|
+
def delete(path: Path, skip_sudo=False, sudo_pass: str | None = None):
|
|
137
|
+
temp_pass = None
|
|
138
|
+
path_exists = False
|
|
139
|
+
try:
|
|
140
|
+
path_exists = path.exists()
|
|
141
|
+
except PermissionError:
|
|
142
|
+
if skip_sudo:
|
|
143
|
+
log(f"PermissionError: skipping {path}")
|
|
144
|
+
return skip_sudo, sudo_pass
|
|
145
|
+
else:
|
|
146
|
+
if not temp_pass and not sudo_pass:
|
|
147
|
+
temp_pass, sudo_pass, skip_sudo = get_sudo_pass(path)
|
|
148
|
+
success, _, _ = run_command(f"ls {path}", temp_pass or sudo_pass)
|
|
149
|
+
path_exists = success
|
|
150
|
+
|
|
151
|
+
if path_exists:
|
|
152
|
+
try:
|
|
153
|
+
remove_file_or_dir(path, temp_pass or sudo_pass)
|
|
154
|
+
except PermissionError:
|
|
155
|
+
log(f"PermissionError: {path} requires sudo access.")
|
|
156
|
+
if not skip_sudo:
|
|
157
|
+
temp_pass, sudo_pass, skip_sudo = get_sudo_pass(path)
|
|
158
|
+
if temp_pass or sudo_pass:
|
|
159
|
+
remove_file_or_dir(path, temp_pass or sudo_pass)
|
|
160
|
+
|
|
161
|
+
|
|
107
162
|
@exception_handler
|
|
108
|
-
def copy(source: Path, dest: Path, skip_sudo=False, sudo_pass=None):
|
|
163
|
+
def copy(source: Path, dest: Path, skip_sudo=False, sudo_pass=None, prune=False):
|
|
109
164
|
"""Copies files/directories using rsync and handles sudo permission issues."""
|
|
110
165
|
temp_pass = None
|
|
111
166
|
source_exists = False
|
|
112
167
|
is_dir = False # Default to file
|
|
113
168
|
|
|
114
169
|
try:
|
|
170
|
+
source_exists = source.exists()
|
|
171
|
+
is_dir = source.is_dir()
|
|
172
|
+
except PermissionError:
|
|
173
|
+
if skip_sudo:
|
|
174
|
+
log(f"PermissionError: skipping {source}")
|
|
175
|
+
return skip_sudo, sudo_pass
|
|
176
|
+
else:
|
|
177
|
+
if not temp_pass and not sudo_pass:
|
|
178
|
+
temp_pass, sudo_pass, skip_sudo = get_sudo_pass(source)
|
|
179
|
+
success, _, _ = run_command(f"ls {source}", temp_pass or sudo_pass)
|
|
180
|
+
source_exists = success
|
|
181
|
+
_, _, exit_code = run_command(f"test -d {source}", temp_pass or sudo_pass)
|
|
182
|
+
is_dir = exit_code == 0
|
|
183
|
+
if source_exists:
|
|
115
184
|
try:
|
|
116
|
-
source_exists = source.exists()
|
|
117
|
-
is_dir = source.is_dir()
|
|
118
|
-
except PermissionError:
|
|
119
|
-
if skip_sudo:
|
|
120
|
-
log(f"PermissionError: skipping {source}")
|
|
121
|
-
return skip_sudo, sudo_pass
|
|
122
|
-
else:
|
|
123
|
-
if not temp_pass and not sudo_pass:
|
|
124
|
-
temp_pass, sudo_pass, skip_sudo = get_sudo_pass(source)
|
|
125
|
-
success, _, _ = run_command(f"ls {source}", temp_pass or sudo_pass)
|
|
126
|
-
source_exists = success
|
|
127
|
-
_, _, exit_code = run_command(
|
|
128
|
-
f"test -d {source}", temp_pass or sudo_pass
|
|
129
|
-
)
|
|
130
|
-
is_dir = exit_code == 0
|
|
131
|
-
|
|
132
|
-
if source_exists:
|
|
133
185
|
assert source != dest, "Source and destination can't be the same"
|
|
134
186
|
rsync(source, dest, temp_pass or sudo_pass, is_dir=is_dir)
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
187
|
+
except PermissionError:
|
|
188
|
+
log(f"PermissionError: {source} requires sudo access.")
|
|
189
|
+
if not skip_sudo:
|
|
190
|
+
temp_pass, sudo_pass, skip_sudo = get_sudo_pass(source)
|
|
191
|
+
if temp_pass or sudo_pass:
|
|
192
|
+
rsync(source, dest, temp_pass or sudo_pass, is_dir=is_dir)
|
|
193
|
+
else:
|
|
194
|
+
if prune:
|
|
195
|
+
log(f'Removing "{dest.parent.name}:{dest.name}"...')
|
|
196
|
+
delete(dest, skip_sudo, temp_pass or sudo_pass)
|
|
141
197
|
|
|
142
198
|
return skip_sudo, sudo_pass
|
|
@@ -228,8 +228,8 @@ def push_new_branch(repo: Repo) -> None:
|
|
|
228
228
|
|
|
229
229
|
def pull_changes(repo: Repo) -> bool | None:
|
|
230
230
|
is_remote, origin = is_remote_repo(repo)
|
|
231
|
-
if not is_remote or origin
|
|
232
|
-
log("Warning: Skipping pull
|
|
231
|
+
if not is_remote or not origin:
|
|
232
|
+
log("Warning: Skipping pull from remote repository! Not a remote repo.")
|
|
233
233
|
return None
|
|
234
234
|
|
|
235
235
|
if repo.bare:
|
|
@@ -237,17 +237,20 @@ def pull_changes(repo: Repo) -> bool | None:
|
|
|
237
237
|
|
|
238
238
|
git_fetch(repo)
|
|
239
239
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
240
|
+
_, remote_profiles, active_profile, _ = get_repo_branches(repo)
|
|
241
|
+
|
|
242
|
+
if active_profile not in remote_profiles:
|
|
243
|
+
return None
|
|
244
|
+
|
|
245
|
+
local_commit = repo.commit(active_profile)
|
|
246
|
+
remote_commit = repo.commit(f"origin/{active_profile}")
|
|
243
247
|
|
|
244
248
|
if local_commit.hexsha == remote_commit.hexsha:
|
|
245
249
|
return None
|
|
246
250
|
|
|
247
251
|
log("📥 Update found:")
|
|
248
|
-
for commit in repo.iter_commits(f"{
|
|
249
|
-
log(f"
|
|
250
|
-
|
|
252
|
+
for commit in repo.iter_commits(f"{active_profile}..origin/{active_profile}"):
|
|
253
|
+
log(f" - {commit.summary} ({commit.hexsha[:7]})")
|
|
251
254
|
origin.pull()
|
|
252
255
|
return True
|
|
253
256
|
|
|
@@ -82,7 +82,7 @@ class DotCtl:
|
|
|
82
82
|
def save_dots(self):
|
|
83
83
|
"""Save current dotfiles."""
|
|
84
84
|
props = self._build_props(
|
|
85
|
-
saver_default_props, "skip_sudo", "password", "profile"
|
|
85
|
+
saver_default_props, "skip_sudo", "password", "profile", "prune"
|
|
86
86
|
)
|
|
87
87
|
save(props)
|
|
88
88
|
|
|
@@ -186,6 +186,7 @@ def main():
|
|
|
186
186
|
"details": getattr(args, "details", False),
|
|
187
187
|
"fetch": getattr(args, "fetch", False),
|
|
188
188
|
"no_confirm": getattr(args, "no_confirm", False),
|
|
189
|
+
"prune": getattr(args, "prune", False),
|
|
189
190
|
}
|
|
190
191
|
|
|
191
192
|
dot_ctl_obj = DotCtl(**common_args)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dotctl
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.9
|
|
4
4
|
Summary: A powerful CLI tool to profile your OS by saving, applying, exporting, and importing system configurations as named profiles. Designed to manage dot files and service configurations in a centralized Git repository (local or remote), dotctl enables seamless system replication across machines. Supports pre/post hook scripts, making it ideal for setting up servers or desktops with consistent environments.
|
|
5
5
|
Author-email: Pankaj Jackson <pankajackson@live.co.uk>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -57,6 +57,7 @@ Designed for developers and sysadmins, it supports pre/post hook scripts and is
|
|
|
57
57
|
- [🆕 `create` / `new`](#-create--new)
|
|
58
58
|
- [❌ `remove` / `rm` / `delete` / `del`](#-remove--rm--delete--del)
|
|
59
59
|
- [🧪 `apply`](#-apply)
|
|
60
|
+
- [🔄 `pull`](#-pull)
|
|
60
61
|
- [📤 `export`](#-export)
|
|
61
62
|
- [📥 `import`](#-import)
|
|
62
63
|
- [🔥 `wipe`](#-wipe)
|
|
@@ -77,6 +78,7 @@ Designed for developers and sysadmins, it supports pre/post hook scripts and is
|
|
|
77
78
|
- 🔄 **Git Integration** — Sync profiles with local or remote Git repositories.
|
|
78
79
|
- 📁 **Portable Configs** — Export/import profiles using `.dtsv` files for easy backups and sharing.
|
|
79
80
|
- ⚙️ **Custom Configs** — Define tracking rules via `dotctl.yaml`.
|
|
81
|
+
- 🧹 **Prune Support** — Clean stale files no longer listed in your profile with --prune.
|
|
80
82
|
|
|
81
83
|
---
|
|
82
84
|
|
|
@@ -381,7 +383,7 @@ dotctl init -c ./my_custom_config.yaml
|
|
|
381
383
|
Save current system state to the active profile.
|
|
382
384
|
|
|
383
385
|
```sh
|
|
384
|
-
dotctl save [-h] [-p <password>] [--skip-sudo] [profile]
|
|
386
|
+
dotctl save [-h] [-p <password>] [--skip-sudo] [--prune] [profile]
|
|
385
387
|
```
|
|
386
388
|
|
|
387
389
|
**Examples:**
|
|
@@ -390,12 +392,17 @@ dotctl save [-h] [-p <password>] [--skip-sudo] [profile]
|
|
|
390
392
|
dotctl save
|
|
391
393
|
dotctl save my_web_server --skip-sudo
|
|
392
394
|
dotctl save my_web_server -p mYsecretp@ssw0rd
|
|
395
|
+
dotctl save --prune
|
|
393
396
|
```
|
|
394
397
|
|
|
398
|
+
> Tip: Use --prune to clean files that were saved before but are no longer listed in the config.
|
|
399
|
+
|
|
395
400
|
**Options:**
|
|
396
401
|
|
|
397
402
|
- `--skip-sudo` – Ignore restricted resources.
|
|
398
403
|
- `-p, --password` – Password for restricted resources.
|
|
404
|
+
- `--prune` – Remove stale files from the dot repo that are no longer listed in the current `dotctl.yaml` config.
|
|
405
|
+
- `profile` – Target profile to save into (defaults to the active one if not provided)
|
|
399
406
|
|
|
400
407
|
---
|
|
401
408
|
|
|
@@ -524,6 +531,22 @@ dotctl apply MyProfile --skip-pre-hooks --ignore-hook-errors
|
|
|
524
531
|
|
|
525
532
|
---
|
|
526
533
|
|
|
534
|
+
### 🔄 `pull`
|
|
535
|
+
|
|
536
|
+
Pull the latest changes from the dotfiles repository.
|
|
537
|
+
|
|
538
|
+
```sh
|
|
539
|
+
dotctl pull [-h]
|
|
540
|
+
```
|
|
541
|
+
|
|
542
|
+
**Examples:**
|
|
543
|
+
|
|
544
|
+
```sh
|
|
545
|
+
dotctl pull
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
---
|
|
549
|
+
|
|
527
550
|
### 📤 `export`
|
|
528
551
|
|
|
529
552
|
Export a profile to `.dtsv`.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|