socialcli 0.3.0__py3-none-any.whl
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.
Potentially problematic release.
This version of socialcli might be problematic. Click here for more details.
- socialcli-0.3.0.dist-info/METADATA +168 -0
- socialcli-0.3.0.dist-info/RECORD +224 -0
- socialcli-0.3.0.dist-info/WHEEL +4 -0
- socialcli-0.3.0.dist-info/entry_points.txt +3 -0
- socialcli-0.3.0.dist-info/licenses/LICENSE +21 -0
- socialctl/__init__.py +0 -0
- socialctl/__main__.py +6 -0
- socialctl/adapters/__init__.py +6 -0
- socialctl/adapters/base.py +68 -0
- socialctl/adapters/errores.py +56 -0
- socialctl/adapters/facebook.py +180 -0
- socialctl/adapters/instagram.py +442 -0
- socialctl/adapters/tiktok.py +535 -0
- socialctl/adapters/youtube.py +331 -0
- socialctl/agent_errors.py +176 -0
- socialctl/agent_guide.py +23 -0
- socialctl/approval_cli.py +27 -0
- socialctl/auth.py +139 -0
- socialctl/authflow.py +344 -0
- socialctl/brands.py +194 -0
- socialctl/capabilities.py +57 -0
- socialctl/capabilities.yml +5945 -0
- socialctl/cli.py +1766 -0
- socialctl/connection_service/__init__.py +0 -0
- socialctl/connection_service/__main__.py +33 -0
- socialctl/connection_service/app.py +496 -0
- socialctl/connection_service/assets/PLATFORM-LOGOS-LICENSE.txt +50 -0
- socialctl/connection_service/assets/connection.css +75 -0
- socialctl/connection_service/assets/facebook.webp +0 -0
- socialctl/connection_service/assets/instagram.svg +194 -0
- socialctl/connection_service/assets/socialcli-logo.png +0 -0
- socialctl/connection_service/assets/tiktok.png +0 -0
- socialctl/connection_service/assets/youtube.svg +1 -0
- socialctl/connection_service/landing.py +146 -0
- socialctl/connection_service/legacy.py +48 -0
- socialctl/connection_service/peer.py +13 -0
- socialctl/connection_service/providers.py +324 -0
- socialctl/connection_service/settings.py +76 -0
- socialctl/connection_service/store.py +124 -0
- socialctl/connections/__init__.py +0 -0
- socialctl/connections/account_cli.py +438 -0
- socialctl/connections/cli.py +379 -0
- socialctl/connections/client.py +126 -0
- socialctl/connections/credential_cli.py +224 -0
- socialctl/connections/credential_store.py +49 -0
- socialctl/connections/file_store.py +193 -0
- socialctl/connections/keychain.py +78 -0
- socialctl/connections/meta_user.py +81 -0
- socialctl/connections/rotation_cli.py +116 -0
- socialctl/connections/saas_client.py +91 -0
- socialctl/connections/temporary_media.py +62 -0
- socialctl/delivery_options.py +70 -0
- socialctl/engagement.py +200 -0
- socialctl/engagement_cli.py +50 -0
- socialctl/executor.py +135 -0
- socialctl/formatter.py +291 -0
- socialctl/hosted_media.py +152 -0
- socialctl/identity.py +200 -0
- socialctl/inbox.py +298 -0
- socialctl/inbox_cli.py +46 -0
- socialctl/inventory.py +155 -0
- socialctl/inventory_cli.py +171 -0
- socialctl/inventory_sources.py +101 -0
- socialctl/management/__init__.py +1 -0
- socialctl/management/batch_cli.py +115 -0
- socialctl/management/batches.py +325 -0
- socialctl/management/changes.py +485 -0
- socialctl/management/cli.py +227 -0
- socialctl/management/comments_cli.py +352 -0
- socialctl/management/community_batch_cli.py +63 -0
- socialctl/management/community_batches.py +294 -0
- socialctl/management/community_changes.py +370 -0
- socialctl/management/community_cli.py +142 -0
- socialctl/management/community_schema.py +119 -0
- socialctl/management/facebook_groups.py +1118 -0
- socialctl/management/groups_cli.py +274 -0
- socialctl/management/inbox_readers.py +87 -0
- socialctl/management/meta_changes.py +197 -0
- socialctl/management/meta_cli.py +342 -0
- socialctl/management/meta_client.py +631 -0
- socialctl/management/meta_comment_inbox.py +565 -0
- socialctl/management/meta_comments.py +587 -0
- socialctl/management/meta_errors.py +59 -0
- socialctl/management/meta_pagination.py +52 -0
- socialctl/management/meta_schema.py +128 -0
- socialctl/management/meta_webhooks.py +147 -0
- socialctl/management/metadata_parts.py +144 -0
- socialctl/management/owned_assets.py +85 -0
- socialctl/management/owned_changes.py +470 -0
- socialctl/management/owned_cli.py +128 -0
- socialctl/management/owned_reorder.py +62 -0
- socialctl/management/owned_schema.py +368 -0
- socialctl/management/reply_context.py +24 -0
- socialctl/management/reply_evidence.py +80 -0
- socialctl/management/resource_changes.py +407 -0
- socialctl/management/resource_cli.py +136 -0
- socialctl/management/snippet_readback.py +26 -0
- socialctl/management/stories.py +713 -0
- socialctl/management/stories_cli.py +172 -0
- socialctl/management/youtube.py +323 -0
- socialctl/management/youtube_community.py +326 -0
- socialctl/management/youtube_metadata.py +122 -0
- socialctl/management/youtube_owned.py +259 -0
- socialctl/management/youtube_resources.py +305 -0
- socialctl/media.py +269 -0
- socialctl/media_cli.py +183 -0
- socialctl/media_ingress.py +211 -0
- socialctl/media_preflight.py +114 -0
- socialctl/media_registry.py +301 -0
- socialctl/media_requirements.py +52 -0
- socialctl/metricas/__init__.py +6 -0
- socialctl/metricas/almacen.py +133 -0
- socialctl/metricas/analytics_changes.py +295 -0
- socialctl/metricas/analytics_cli.py +191 -0
- socialctl/metricas/analytics_client.py +304 -0
- socialctl/metricas/analytics_ingest.py +260 -0
- socialctl/metricas/analytics_schema.py +174 -0
- socialctl/metricas/base.py +147 -0
- socialctl/metricas/facebook.py +418 -0
- socialctl/metricas/insights.py +227 -0
- socialctl/metricas/instagram.py +133 -0
- socialctl/metricas/modelos.py +87 -0
- socialctl/metricas/piezas.py +134 -0
- socialctl/metricas/reach.py +94 -0
- socialctl/metricas/reporting_client.py +112 -0
- socialctl/metricas/resumen.py +251 -0
- socialctl/metricas/slugs.py +89 -0
- socialctl/metricas/tiktok.py +185 -0
- socialctl/metricas/youtube.py +403 -0
- socialctl/migration_cli.py +60 -0
- socialctl/migration_files.py +68 -0
- socialctl/models.py +150 -0
- socialctl/native_schedule/__init__.py +13 -0
- socialctl/native_schedule/api_delivery.py +15 -0
- socialctl/native_schedule/api_reconcile.py +40 -0
- socialctl/native_schedule/approval.py +160 -0
- socialctl/native_schedule/cadence.py +73 -0
- socialctl/native_schedule/cli.py +510 -0
- socialctl/native_schedule/dispatcher.py +120 -0
- socialctl/native_schedule/facebook.py +112 -0
- socialctl/native_schedule/facebook_reels.py +140 -0
- socialctl/native_schedule/first_comment.py +181 -0
- socialctl/native_schedule/handoff.py +193 -0
- socialctl/native_schedule/instagram_delivery.py +224 -0
- socialctl/native_schedule/instagram_runtime.py +66 -0
- socialctl/native_schedule/inventory.py +70 -0
- socialctl/native_schedule/migration.py +310 -0
- socialctl/native_schedule/models.py +103 -0
- socialctl/native_schedule/reconcile.py +83 -0
- socialctl/native_schedule/remote_data.py +177 -0
- socialctl/native_schedule/report.py +151 -0
- socialctl/native_schedule/store.py +560 -0
- socialctl/native_schedule/verification.py +32 -0
- socialctl/native_schedule/youtube.py +339 -0
- socialctl/operation_output.py +87 -0
- socialctl/plantillas/accounts.yml +33 -0
- socialctl/plantillas/brand.md +95 -0
- socialctl/plantillas/estrategia.md +64 -0
- socialctl/postfile.py +240 -0
- socialctl/preflight.py +73 -0
- socialctl/publication_policy.py +34 -0
- socialctl/publication_status.py +75 -0
- socialctl/publication_steps.py +398 -0
- socialctl/publish_output.py +96 -0
- socialctl/publisher.py +445 -0
- socialctl/queue_migration.py +302 -0
- socialctl/read_budget.py +224 -0
- socialctl/read_reports.py +91 -0
- socialctl/rutas.py +103 -0
- socialctl/saas/__init__.py +1 -0
- socialctl/saas/access.py +75 -0
- socialctl/saas/auth.py +213 -0
- socialctl/saas/backup.py +124 -0
- socialctl/saas/billing.py +327 -0
- socialctl/saas/billing_enrollment.py +1237 -0
- socialctl/saas/billing_enrollment_schema.py +519 -0
- socialctl/saas/billing_inventory.py +775 -0
- socialctl/saas/billing_reconcile.py +127 -0
- socialctl/saas/billing_routes.py +27 -0
- socialctl/saas/budget.py +66 -0
- socialctl/saas/connections.py +374 -0
- socialctl/saas/consent.py +52 -0
- socialctl/saas/lifecycle.py +341 -0
- socialctl/saas/mail.py +89 -0
- socialctl/saas/maintenance.py +68 -0
- socialctl/saas/meta_user.py +298 -0
- socialctl/saas/meta_webhooks.py +358 -0
- socialctl/saas/migration.py +107 -0
- socialctl/saas/models.py +8 -0
- socialctl/saas/operations.py +102 -0
- socialctl/saas/pages.py +126 -0
- socialctl/saas/pairing.py +158 -0
- socialctl/saas/permissions.py +57 -0
- socialctl/saas/reminders.py +128 -0
- socialctl/saas/renewal.py +74 -0
- socialctl/saas/restore_guard.py +229 -0
- socialctl/saas/revocation.py +97 -0
- socialctl/saas/rotation.py +114 -0
- socialctl/saas/routes.py +221 -0
- socialctl/saas/settings.py +34 -0
- socialctl/saas/store.py +106 -0
- socialctl/saas/temporary_media.py +245 -0
- socialctl/saas/webhooks.py +76 -0
- socialctl/schedule_remote.py +262 -0
- socialctl/schedule_sqlite.py +44 -0
- socialctl/scheduler.py +581 -0
- socialctl/scheduler_launchd.py +319 -0
- socialctl/scheduler_systemd.py +167 -0
- socialctl/source_links.py +119 -0
- socialctl/ui/__init__.py +1 -0
- socialctl/ui/assets/agent-manual.md +850 -0
- socialctl/ui/assets/agents.md +27 -0
- socialctl/ui/assets/components.css +20 -0
- socialctl/ui/assets/connection-layout.css +53 -0
- socialctl/ui/assets/otp.template.html +10 -0
- socialctl/ui/assets/tokens.css +1 -0
- socialctl/ui/assets/trial.template.html +11 -0
- socialctl/ui/assets/web-layout.css +38 -0
- socialctl/ui/email/otp.html +10 -0
- socialctl/ui/email/trial.html +11 -0
- socialctl/upload_consent.py +13 -0
- socialctl/workspace.py +8 -0
- socialctl/youtube_data.py +471 -0
- socialctl/youtube_data_service.py +225 -0
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"""Opt-in daily local retention supervisor, separate from publication scheduling.
|
|
2
|
+
|
|
3
|
+
No shell or cleanup runs inside the installer. The user manager runs the existing
|
|
4
|
+
brand-scoped data-cleanup command later. Sleep, power-off, logout, removed Python
|
|
5
|
+
environments and exported copies remain outside a physical-erasure guarantee.
|
|
6
|
+
"""
|
|
7
|
+
import hashlib
|
|
8
|
+
import json
|
|
9
|
+
import os
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
import plistlib
|
|
12
|
+
import re
|
|
13
|
+
import shutil
|
|
14
|
+
import subprocess
|
|
15
|
+
import sys
|
|
16
|
+
|
|
17
|
+
from socialctl.scheduler_systemd import SupervisorError, _quote, _atomic, _directory
|
|
18
|
+
|
|
19
|
+
LIMITS = ('Cleanup requires this machine, the selected Python environment and the user '
|
|
20
|
+
'supervisor to remain available. Offline or logged-out machines and exported '
|
|
21
|
+
'third-party copies cannot be guaranteed erased on schedule. This task does '
|
|
22
|
+
'not publish, reconnect, or remove customer-supplied originals.')
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def unit_name(brand, root):
|
|
26
|
+
identity=str(Path(root).resolve())+'\0'+brand
|
|
27
|
+
return 'com.socialcli.'+hashlib.sha256(identity.encode()).hexdigest()[:20]+'.data-cleanup'
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _workspace(brand,root):
|
|
31
|
+
from socialctl.rutas import validar_componente_de_ruta
|
|
32
|
+
root=Path(root).resolve()
|
|
33
|
+
_quote(root);_quote(brand)
|
|
34
|
+
selected=validar_componente_de_ruta(root,brand,SupervisorError,'brand name')
|
|
35
|
+
if not root.is_dir() or not selected.is_dir() or not (selected/'brand.md').is_file():
|
|
36
|
+
raise SupervisorError('Select an existing brand and its explicit workspace root.')
|
|
37
|
+
return root
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _argv(brand,root):
|
|
41
|
+
# Do not resolve the interpreter symlink: that can bypass the installed venv.
|
|
42
|
+
executable=Path(sys.executable).absolute()
|
|
43
|
+
_quote(executable)
|
|
44
|
+
if not executable.is_file() or not os.access(executable,os.X_OK):
|
|
45
|
+
raise SupervisorError('The current Python interpreter must remain executable for scheduled cleanup.')
|
|
46
|
+
return [str(executable),'-m','socialctl','data-cleanup','--brand',brand,'--root',str(root)]
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def preview(brand,root):
|
|
50
|
+
root=_workspace(brand,root);name=unit_name(brand,root);argv=_argv(brand,root)
|
|
51
|
+
if sys.platform.startswith('linux'):
|
|
52
|
+
kind='systemd_user';directory=_directory()
|
|
53
|
+
working=str(root)
|
|
54
|
+
if working!=working.rstrip() or working.endswith('\\'):
|
|
55
|
+
raise SupervisorError('The workspace must not end with whitespace or a backslash.')
|
|
56
|
+
service=('# Managed by SocialCli data cleanup\n[Unit]\nDescription=SocialCli local data retention\n\n'
|
|
57
|
+
'[Service]\nType=oneshot\nWorkingDirectory='+working.replace('%','%%')+
|
|
58
|
+
'\nExecStart='+' '.join(_quote(arg,command=True) for arg in argv)+
|
|
59
|
+
'\nUMask=0077\nStandardOutput=null\nStandardError=null\nTimeoutStartSec=1h\n')
|
|
60
|
+
timer=('# Managed by SocialCli data cleanup\n[Unit]\nDescription=SocialCli daily data retention\n\n'
|
|
61
|
+
'[Timer]\nOnCalendar=daily\nPersistent=true\nAccuracySec=1s\nUnit='+name+
|
|
62
|
+
'.service\n\n[Install]\nWantedBy=timers.target\n')
|
|
63
|
+
files=[{'path':str(directory/(name+suffix)),'content':content}
|
|
64
|
+
for suffix,content in (('.service',service),('.timer',timer))]
|
|
65
|
+
actions=[['systemctl','--user','daemon-reload'],['systemctl','--user','enable','--now',name+'.timer']]
|
|
66
|
+
elif sys.platform=='darwin':
|
|
67
|
+
kind='launchd_user';directory=Path.home()/'Library'/'LaunchAgents'
|
|
68
|
+
path=directory/(name+'.plist')
|
|
69
|
+
payload={'Label':name,'ProgramArguments':argv,'WorkingDirectory':str(root),
|
|
70
|
+
'StartCalendarInterval':{'Hour':12,'Minute':0},'RunAtLoad':False,
|
|
71
|
+
'Umask':0o077,'ProcessType':'Background'}
|
|
72
|
+
files=[{'path':str(path),'content':plistlib.dumps(payload,sort_keys=False).decode()}]
|
|
73
|
+
actions=[['launchctl','enable',f'gui/{os.getuid()}/{name}'],
|
|
74
|
+
['launchctl','bootstrap',f'gui/{os.getuid()}',str(path)]]
|
|
75
|
+
else:
|
|
76
|
+
raise SupervisorError('Daily cleanup installation supports Linux user systemd and macOS launchd only.')
|
|
77
|
+
return {'version':1,'status':'preview','kind':kind,'unit':name,'brand':brand,'root':str(root),
|
|
78
|
+
'argv':argv,'files':files,'actions':actions,'interval':'daily',
|
|
79
|
+
'physical_erasure_guaranteed':False,'limits':LIMITS}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _run(tool,args,*,check=True):
|
|
83
|
+
executable=shutil.which(tool)
|
|
84
|
+
if not executable:raise SupervisorError('The user supervisor is unavailable; no active cleanup task was verified.')
|
|
85
|
+
try:
|
|
86
|
+
result=subprocess.run([executable,*args],capture_output=True,text=True,timeout=15,check=False)
|
|
87
|
+
except (OSError,subprocess.TimeoutExpired):
|
|
88
|
+
raise SupervisorError('Could not contact the user supervisor; inspect its status before retrying.') from None
|
|
89
|
+
if check and result.returncode:
|
|
90
|
+
raise SupervisorError('The user supervisor rejected the operation; inspect its status before retrying.')
|
|
91
|
+
return result
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def _private_regular(path):
|
|
95
|
+
return (not path.is_symlink() and not any(parent.is_symlink() for parent in path.parents) and path.is_file() and path.stat().st_uid==os.getuid()
|
|
96
|
+
and path.stat().st_mode&0o777==0o600)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _check_destinations(files):
|
|
100
|
+
# Never replace an existing unrelated/modified file, even at our hashed name.
|
|
101
|
+
for item in files:
|
|
102
|
+
path=Path(item['path'])
|
|
103
|
+
if any(parent.is_symlink() for parent in path.parents):
|
|
104
|
+
raise SupervisorError('Refusing a symlinked supervisor configuration directory.')
|
|
105
|
+
if path.is_symlink() or (path.exists() and (not path.is_file()
|
|
106
|
+
or path.stat().st_uid!=os.getuid() or path.read_text()!=item['content'])):
|
|
107
|
+
raise SupervisorError('Existing supervisor configuration differs or is unsafe. Review it manually; nothing was replaced.')
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _mkdir_private(directory):
|
|
111
|
+
missing=[];current=directory
|
|
112
|
+
while not current.exists():missing.append(current);current=current.parent
|
|
113
|
+
for path in reversed(missing):path.mkdir(mode=0o700)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def _properties(output):
|
|
117
|
+
return dict(line.split('=',1) for line in output.splitlines() if '=' in line)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _launchd_matches(output,plan):
|
|
121
|
+
observed={}
|
|
122
|
+
for line in output.splitlines():
|
|
123
|
+
if ' = ' in line:
|
|
124
|
+
key,value=line.strip().split(' = ',1);observed[key]=value
|
|
125
|
+
arguments=re.search(r'^\s*arguments = \{\s*\n(.*?)^\s*\}',output,re.M|re.S)
|
|
126
|
+
argv=[line.strip() for line in arguments.group(1).splitlines() if line.strip()] if arguments else []
|
|
127
|
+
return observed.get('path')==plan['files'][0]['path'] and observed.get('program')==plan['argv'][0] and argv==plan['argv']
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def inspect(brand,root):
|
|
131
|
+
plan=preview(brand,root)
|
|
132
|
+
report={key:plan[key] for key in ('version','kind','unit','brand','root','interval','physical_erasure_guaranteed','limits')}
|
|
133
|
+
report.update(status='attention_required',reason='configuration_missing',configuration_matches=False,
|
|
134
|
+
registered=False,enabled=False,active=False,last_exit_code=None,survives_logout=None)
|
|
135
|
+
try:
|
|
136
|
+
matches=all(_private_regular(Path(item['path'])) and Path(item['path']).read_text()==item['content'] for item in plan['files'])
|
|
137
|
+
if not matches:
|
|
138
|
+
if any(Path(item['path']).exists() or Path(item['path']).is_symlink() for item in plan['files']):
|
|
139
|
+
report['reason']='configuration_mismatch'
|
|
140
|
+
return report
|
|
141
|
+
report['configuration_matches']=True
|
|
142
|
+
name=plan['unit']
|
|
143
|
+
if plan['kind']=='systemd_user':
|
|
144
|
+
for item in plan['files']:
|
|
145
|
+
path=Path(item['path'])
|
|
146
|
+
observed=_run('systemctl',['--user','show','--property=NeedDaemonReload,DropInPaths,FragmentPath,ActiveState,Result,ExecMainStatus',path.name])
|
|
147
|
+
props=_properties(observed.stdout)
|
|
148
|
+
if props.get('NeedDaemonReload')!='no' or props.get('DropInPaths')!='' or props.get('FragmentPath')!=str(path):
|
|
149
|
+
report.update(configuration_matches=False,reason='loaded_configuration_mismatch');return report
|
|
150
|
+
if path.suffix=='.service':
|
|
151
|
+
code=props.get('ExecMainStatus','')
|
|
152
|
+
report['last_exit_code']=int(code) if code.isdigit() else None
|
|
153
|
+
if props.get('Result') not in {'','success'}:report['last_exit_code']=report['last_exit_code'] or 1
|
|
154
|
+
report['registered']=True
|
|
155
|
+
enabled=_run('systemctl',['--user','is-enabled',name+'.timer'],check=False)
|
|
156
|
+
active=_run('systemctl',['--user','is-active',name+'.timer'],check=False)
|
|
157
|
+
report['enabled']=enabled.returncode==0 and enabled.stdout.strip()=='enabled'
|
|
158
|
+
report['active']=active.returncode==0 and active.stdout.strip()=='active'
|
|
159
|
+
linger=_run('loginctl',['show-user',str(os.getuid()),'--property=Linger','--value'],check=False)
|
|
160
|
+
if linger.returncode==0 and linger.stdout.strip() in {'yes','no'}:report['survives_logout']=linger.stdout.strip()=='yes'
|
|
161
|
+
else:
|
|
162
|
+
domain=f'gui/{os.getuid()}'
|
|
163
|
+
observed=_run('launchctl',['print',domain+'/'+name],check=False)
|
|
164
|
+
disabled=_run('launchctl',['print-disabled',domain],check=False)
|
|
165
|
+
report['registered']=observed.returncode==0
|
|
166
|
+
report['active']=report['registered'] and _launchd_matches(observed.stdout,plan)
|
|
167
|
+
report['enabled']=disabled.returncode==0 and not re.search(r'"'+re.escape(name)+r'"\s*=>\s*true',disabled.stdout)
|
|
168
|
+
report['survives_logout']=False
|
|
169
|
+
last=re.search(r'^\s*last exit code = (\d+)\s*$',observed.stdout,re.M)
|
|
170
|
+
if last:report['last_exit_code']=int(last.group(1))
|
|
171
|
+
if report['last_exit_code'] not in {None,0}:report['reason']='last_cleanup_failed'
|
|
172
|
+
elif report['registered'] and report['enabled'] and report['active']:
|
|
173
|
+
report.update(status='scheduled',reason='scheduled')
|
|
174
|
+
else:report['reason']='supervisor_not_active'
|
|
175
|
+
except (SupervisorError,OSError,ValueError):
|
|
176
|
+
report['reason']='supervisor_unavailable'
|
|
177
|
+
return report
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def install(brand,root):
|
|
181
|
+
plan=preview(brand,root)
|
|
182
|
+
_check_destinations(plan['files'])
|
|
183
|
+
if plan['kind']=='systemd_user':
|
|
184
|
+
_run('systemctl',['--user','show','--property=Version','--value'])
|
|
185
|
+
existing=None
|
|
186
|
+
else:
|
|
187
|
+
domain=f'gui/{os.getuid()}'
|
|
188
|
+
_run('launchctl',['print',domain])
|
|
189
|
+
existing=_run('launchctl',['print',domain+'/'+plan['unit']],check=False)
|
|
190
|
+
if existing.returncode==0 and not _launchd_matches(existing.stdout,plan):
|
|
191
|
+
raise SupervisorError('An existing launchd job differs. Review it manually; nothing was replaced.')
|
|
192
|
+
for item in plan['files']:
|
|
193
|
+
path=Path(item['path']);_mkdir_private(path.parent);_atomic(path,item['content'])
|
|
194
|
+
for action in plan['actions']:
|
|
195
|
+
if existing is not None and existing.returncode==0 and action[1]=='bootstrap':continue
|
|
196
|
+
_run(action[0],action[1:])
|
|
197
|
+
report=inspect(brand,root)
|
|
198
|
+
if report['status']!='scheduled':
|
|
199
|
+
raise SupervisorError('Cleanup configuration was saved, but a working task was not verified. Run data-cleanup-status; no cleanup was run by the installer.')
|
|
200
|
+
return report
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def register(app):
|
|
204
|
+
import typer
|
|
205
|
+
def output(operation,brand,root):
|
|
206
|
+
try:result=operation(brand,root)
|
|
207
|
+
except (SupervisorError,OSError) as exc:
|
|
208
|
+
message=str(exc) if isinstance(exc,SupervisorError) else 'Could not access the local supervisor configuration.'
|
|
209
|
+
typer.echo(json.dumps({'version':1,'status':'error','message':message}))
|
|
210
|
+
raise typer.Exit(1) from None
|
|
211
|
+
typer.echo(json.dumps(result,ensure_ascii=False))
|
|
212
|
+
if result['status']=='attention_required':raise typer.Exit(1)
|
|
213
|
+
|
|
214
|
+
@app.command('data-cleanup-install')
|
|
215
|
+
def data_cleanup_install(brand:str=typer.Option(...,'--brand'),root:Path=typer.Option(...,'--root'),
|
|
216
|
+
yes:bool=typer.Option(False,'--yes',help='Install and enable this exact brand/workspace daily cleanup task.'),
|
|
217
|
+
dry_run:bool=typer.Option(False,'--dry-run',help='Show the complete configuration and actions without installing (the default).')):
|
|
218
|
+
"""Preview a daily local cleanup task; install only with explicit --yes."""
|
|
219
|
+
if yes and dry_run:raise typer.BadParameter('Choose --dry-run or --yes, not both.')
|
|
220
|
+
output(install if yes else preview,brand,root)
|
|
221
|
+
|
|
222
|
+
@app.command('data-cleanup-status')
|
|
223
|
+
def data_cleanup_status(brand:str=typer.Option(...,'--brand'),root:Path=typer.Option(...,'--root')):
|
|
224
|
+
"""Inspect the local cleanup supervisor without changing it or running cleanup."""
|
|
225
|
+
output(inspect,brand,root)
|