-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrun.ps1
More file actions
192 lines (165 loc) · 5.95 KB
/
Copy pathrun.ps1
File metadata and controls
192 lines (165 loc) · 5.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<#
.SYNOPSIS
RSS-Lance runtime commands (daily use)
.DESCRIPTION
Lightweight script for running the fetcher, server, and admin tasks.
Activates the Python venv automatically. Does NOT handle building
or first-time setup - use build.ps1 for that.
.EXAMPLE
.\run.ps1 fetch-once # Fetch articles once and exit
.\run.ps1 fetch-daemon # Run fetcher continuously
.\run.ps1 server # Start the HTTP server
.\run.ps1 demo-data # Insert demo RSS feeds
.\run.ps1 add-feed <url> # Add a single feed URL
.\run.ps1 export-opml out.opml # Export feeds to OPML
.\run.ps1 datafix strip-chrome # Fix existing article data
#>
param(
[Parameter(Position = 0)]
[ValidateSet("fetch-once", "fetch-daemon", "server", "demo-data", "add-feed", "datafix", "export-opml", "benchmark", "help")]
[string]$Command = "help",
[string]$DebugLog = "",
[int]$Port = 0,
[Parameter(Position = 1, ValueFromRemainingArguments)]
[string[]]$ExtraArgs
)
$ErrorActionPreference = "Stop"
$ProjectRoot = $PSScriptRoot
$VenvPath = Join-Path $ProjectRoot ".venv"
$BuildDir = Join-Path $ProjectRoot "build"
$DataDir = Join-Path $ProjectRoot "data"
$FetcherDir = Join-Path $ProjectRoot "fetcher"
function Ensure-Venv {
$pyExe = Join-Path $VenvPath "Scripts\python.exe"
if (-not (Test-Path $pyExe)) {
Write-Host "Python venv not found at: $VenvPath" -ForegroundColor Red
Write-Host "Run build.ps1 setup first." -ForegroundColor Yellow
exit 1
}
& "$VenvPath\Scripts\Activate.ps1"
}
function Cmd-FetchOnce {
Ensure-Venv
Write-Host "Fetching articles (one-shot) ..." -ForegroundColor Cyan
python "$FetcherDir\main.py" --once
}
function Cmd-FetchDaemon {
Ensure-Venv
Write-Host "Starting feed fetcher daemon ..." -ForegroundColor Cyan
python "$FetcherDir\main.py"
}
function Cmd-Server {
$exe = Join-Path $BuildDir "rss-lance-server.exe"
if (-not (Test-Path $exe)) {
Write-Host "Server not built. Run build.ps1 server first." -ForegroundColor Red
exit 1
}
# Parse host/port from config.toml so we can show the URL up front
$configFile = Join-Path $ProjectRoot "config.toml"
$serverHost = "127.0.0.1"
$serverPort = "8080"
if (Test-Path $configFile) {
$toml = Get-Content $configFile -Raw
if ($toml -match '(?m)^\s*host\s*=\s*"([^"]+)"') { $serverHost = $Matches[1] }
if ($toml -match '(?m)^\s*port\s*=\s*(\d+)') { $serverPort = $Matches[1] }
}
Write-Host "Loading RSS-Lance server (please wait) ..." -ForegroundColor Cyan
Write-Host ""
$serverArgs = @()
if ($DebugLog) {
$serverArgs += "--debug", $DebugLog
Write-Host "Debug: $DebugLog" -ForegroundColor Magenta
}
if ($Port -gt 0) {
$serverArgs += "--port", $Port
Write-Host "Port override: $Port" -ForegroundColor Magenta
}
& $exe @serverArgs
}
function Cmd-DemoData {
Ensure-Venv
Write-Host "Inserting demo feeds ..." -ForegroundColor Cyan
python "$FetcherDir\demo_feeds.py" --data "$DataDir"
}
function Cmd-AddFeed {
if (-not $ExtraArgs -or $ExtraArgs.Count -eq 0) {
Write-Host "Usage: .\run.ps1 add-feed <url>" -ForegroundColor Yellow
exit 1
}
Ensure-Venv
Write-Host "Adding feed: $($ExtraArgs[0])" -ForegroundColor Cyan
python "$FetcherDir\main.py" --add $ExtraArgs[0]
}
function Cmd-ExportOpml {
if (-not $ExtraArgs -or $ExtraArgs.Count -eq 0) {
Write-Host "Usage: .\run.ps1 export-opml <output.opml>" -ForegroundColor Yellow
Write-Host " Use '-' to write to stdout" -ForegroundColor Yellow
exit 1
}
Ensure-Venv
$MigrateDir = Join-Path $ProjectRoot "migrate"
Write-Host "Exporting OPML ..." -ForegroundColor Cyan
$passArgs = @($ExtraArgs[0])
if ($ExtraArgs.Count -gt 1) {
$passArgs += $ExtraArgs[1..($ExtraArgs.Count - 1)]
}
python "$MigrateDir\export_opml.py" @passArgs
}
function Cmd-DataFix {
if (-not $ExtraArgs -or $ExtraArgs.Count -eq 0) {
Ensure-Venv
python "$FetcherDir\datafix.py" list
return
}
Ensure-Venv
$fixName = $ExtraArgs[0]
$passArgs = @("--data", $DataDir)
if ($ExtraArgs.Count -gt 1) {
$passArgs += $ExtraArgs[1..($ExtraArgs.Count - 1)]
}
Write-Host "Running datafix: $fixName" -ForegroundColor Cyan
python "$FetcherDir\datafix.py" $fixName @passArgs
}
function Cmd-Benchmark {
Ensure-Venv
Write-Host "Running benchmark ..." -ForegroundColor Cyan
python "$ProjectRoot\tests\benchmark.py" @ExtraArgs
}
function Cmd-Help {
Write-Host @"
RSS-Lance Runtime Commands
==========================
Usage: .\run.ps1 <command> [args]
Commands:
fetch-once Fetch all due feeds once and exit
fetch-daemon Run the fetcher continuously on a schedule
server Start the HTTP server (http://127.0.0.1:8080)
demo-data Insert demo RSS feeds for testing
add-feed <url> Add a single RSS/Atom feed URL
export-opml <file> Export all feeds to an OPML file (use '-' for stdout)
datafix <name> Run a data fix on existing articles (or 'datafix' to list)
benchmark Run insertion & read benchmarks (isolated temp DB)
help Show this help
Options:
-DebugLog <categories> Enable debug logging (client,duckdb,batch,lance,all)
-Port <number> Override server port from config.toml
Examples:
.\run.ps1 server -DebugLog all
.\run.ps1 server -Port 9090
.\run.ps1 server -DebugLog client,duckdb
.\run.ps1 datafix strip-chrome
.\run.ps1 datafix strip-chrome --dry-run
.\run.ps1 datafix strip-chrome --all
"@ -ForegroundColor Yellow
}
switch ($Command) {
"fetch-once" { Cmd-FetchOnce }
"fetch-daemon" { Cmd-FetchDaemon }
"server" { Cmd-Server }
"demo-data" { Cmd-DemoData }
"add-feed" { Cmd-AddFeed }
"export-opml" { Cmd-ExportOpml }
"datafix" { Cmd-DataFix }
"benchmark" { Cmd-Benchmark }
"help" { Cmd-Help }
}