Skip to content

Commit 266d687

Browse files
authored
Add files via upload
1 parent 271ed52 commit 266d687

3 files changed

Lines changed: 209 additions & 0 deletions

File tree

start-http-server.bat

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
@echo off
2+
setlocal EnableDelayedExpansion
3+
chcp 65001 >nul
4+
5+
cls
6+
7+
:: ---------- 0. Banner ----------
8+
echo.
9+
echo =============================================
10+
echo HTTP Server Launcher (Bulky Edition v1.0)
11+
echo =============================================
12+
echo.
13+
14+
:: ---------- 1. Python existence check ----------
15+
call :logHeader "STEP 1/4 Detecting Python Interpreter"
16+
python --version >nul 2>&1
17+
if errorlevel 1 (
18+
call :logError "Python interpreter not found or not executable."
19+
exit /b 1
20+
)
21+
for /f "tokens=2 delims= " %%V in ('python --version') do set PY_VER=%%V
22+
call :logInfo "Python %PY_VER% detected."
23+
24+
:: ---------- 2. Version sanity check ----------
25+
call :logHeader "STEP 2/4 Checking Minimum Version"
26+
python -c "import sys; exit(0 if sys.version_info>=(3,6) else 1)" 2>nul
27+
if errorlevel 1 (
28+
call :logError "Python 3.6+ required. Current: %PY_VER%"
29+
exit /b 1
30+
)
31+
call :logInfo "Version constraint satisfied."
32+
33+
:: ---------- 3. Fake progress bar ----------
34+
call :logHeader "STEP 3/4 Initialising Sub-modules"
35+
set MODULES=urllib,ssl,argparse,http,datetime,platform,sys,os,random
36+
call :fakeProgress 20
37+
38+
:: ---------- 4. Random tip ----------
39+
call :randomTip
40+
41+
:: ---------- 5. Launch server ----------
42+
call :logHeader "STEP 4/4 Starting HTTP Server"
43+
call :logInfo "Serving on http://localhost:8080 [Ctrl-C to stop]"
44+
python -m http.server 8080
45+
pause
46+
exit /b 0
47+
48+
:: ---------- helper functions ----------
49+
:logHeader
50+
echo [INFO] %~1
51+
echo ----------------------------------------
52+
goto :eof
53+
54+
:logInfo
55+
echo [INFO] %~1
56+
goto :eol
57+
58+
:logError
59+
echo [ERROR] %~1
60+
goto :eof
61+
62+
:fakeProgress
63+
set /a steps=%~1
64+
for /L %%i in (1,1,%steps%) do (
65+
set /a pct=%%i*100/%steps%
66+
set /a bar=%%i*40/%steps%
67+
set "str="
68+
for /L %%b in (1,1,!bar!) do set "str=!str!#"
69+
<nul set /p=[!pct!%%] !str!
70+
ping -n 1 127.0.0.1 >nul
71+
)
72+
echo.
73+
goto :eof
74+
75+
:randomTip
76+
set /a r=%random%%%4
77+
if %r%==0 echo [TIP] Press Ctrl-C twice to force-stop the server.
78+
if %r%==1 echo [TIP] Add '--directory %USERPROFILE%' to serve your home folder.
79+
if %r%==2 echo [TIP] Use 8000 instead of 8080 if the port is taken.
80+
if %r%==3 echo [TIP] Run 'python -m http.server --help' for more options.
81+
goto :eof

start-http-server.ps1

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#Requires -Version 5.1
2+
$ErrorActionPreference = "Stop"
3+
4+
function Write-Info { param($m) Write-Host "[INFO] $m" -ForegroundColor Cyan }
5+
function Write-Error { param($m) Write-Host "[ERROR] $m" -ForegroundColor Red }
6+
function Write-Tip { param($m) Write-Host "[TIP] $m" -ForegroundColor Yellow }
7+
8+
function Show-Banner {
9+
Write-Host "==============================================" -ForegroundColor Green
10+
Write-Host " HTTP Server Launcher (Bulky Edition v1.0) " -ForegroundColor Green
11+
Write-Host "==============================================" -ForegroundColor Green
12+
}
13+
14+
function Test-Python {
15+
Write-Info "STEP 1/4 Detecting Python Interpreter"
16+
try {
17+
$py = Get-Command python -ErrorAction Stop
18+
$ver = & python --version 2>&1
19+
Write-Info "Python $ver detected."
20+
return $true
21+
} catch {
22+
Write-Error "Python interpreter not found or not executable."
23+
return $false
24+
}
25+
}
26+
27+
function Test-Version {
28+
Write-Info "STEP 2/4 Checking Minimum Version"
29+
$ok = & python -c "import sys,os; os.exit(0 if sys.version_info>=(3,6) else 1)" 2>$null
30+
if ($LASTEXITCODE -ne 0) {
31+
Write-Error "Python 3.6+ required."
32+
return $false
33+
}
34+
Write-Info "Version constraint satisfied."
35+
return $true
36+
}
37+
38+
function Show-FakeProgress {
39+
param($Seconds = 3)
40+
Write-Info "STEP 3/4 Initialising Sub-modules"
41+
$jobs = @('urllib','ssl','argparse','http.server','datetime','platform','sys','os','random')
42+
$step = 1 / $jobs.Count
43+
foreach ($j in $jobs) {
44+
Write-Progress -Activity "Loading $j" -PercentComplete ($step*100)
45+
Start-Sleep -Milliseconds (Get-Random -Min 80 -Max 220)
46+
$step++
47+
}
48+
Write-Progress -Activity "Done" -Completed
49+
}
50+
51+
function Show-RandomTip {
52+
$tips = @(
53+
"Press Ctrl-C twice to force-stop the server.",
54+
"Add '--directory $HOME' to serve your home folder.",
55+
"Use 8000 instead of 8080 if the port is taken.",
56+
"Run 'python -m http.server --help' for more options."
57+
)
58+
Write-Tip ($tips | Get-Random)
59+
}
60+
61+
# ---------- main ----------
62+
Show-Banner
63+
if (-not (Test-Python)) { exit 1 }
64+
if (-not (Test-Version)) { exit 1 }
65+
Show-FakeProgress
66+
Show-RandomTip
67+
Write-Info "STEP 4/4 Starting HTTP Server"
68+
Write-Info "Serving on http://localhost:8080 [Ctrl-C to stop]"
69+
try {
70+
python -m http.server 8080
71+
} catch {
72+
Write-Error $_.Exception.Message
73+
exit 1
74+
}

start-http-server.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# ---------- helpers ----------
5+
log_info () { printf '\033[36m[INFO] %s\033[0m\n' "$*"; }
6+
log_error () { printf '\033[31m[ERROR] %s\033[0m\n' "$*" >&2; }
7+
log_tip () { printf '\033[33m[TIP] %s\033[0m\n' "$*"; }
8+
die () { log_error "$*"; exit 1; }
9+
10+
fake_progress () {
11+
local jobs=(urllib ssl argparse http.server datetime platform sys os random)
12+
local total=${#jobs[@]}
13+
for i in "${!jobs[@]}"; do
14+
pct=$(( (i+1)*100/total ))
15+
printf '\r[%-20s] %3d%%' "$(printf '%0.s#' $(seq 1 $((pct/5))))" "$pct"
16+
sleep 0.$(shuf -i 15-25 -n1)
17+
done
18+
echo
19+
}
20+
21+
random_tip (){
22+
tips=(
23+
"Press Ctrl-C twice to force-stop the server."
24+
"Add '--directory \$HOME' to serve your home folder."
25+
"Use 8000 instead of 8080 if the port is taken."
26+
"Run 'python -m http.server --help' for more options."
27+
)
28+
log_tip "${tips[RANDOM % ${#tips[@]}]}"
29+
}
30+
31+
# ---------- main ----------
32+
cat <<'BANNER'
33+
==============================================
34+
HTTP Server Launcher (Bulky Edition v1.0)
35+
==============================================
36+
BANNER
37+
38+
log_info "STEP 1/4 Detecting Python Interpreter"
39+
command -v python >/dev/null || die "Python interpreter not found or not executable."
40+
PY_VER=$(python --version 2>&1)
41+
log_info "$PY_VER detected."
42+
43+
log_info "STEP 2/4 Checking Minimum Version"
44+
python -c 'import sys; sys.exit(0 if sys.version_info>=(3,6) else 1)' \
45+
|| die "Python 3.6+ required."
46+
log_info "Version constraint satisfied."
47+
48+
log_info "STEP 3/4 Initialising Sub-modules"
49+
fake_progress
50+
random_tip
51+
52+
log_info "STEP 4/4 Starting HTTP Server"
53+
log_info "Serving on http://localhost:8080 [Ctrl-C to stop]"
54+
exec python -m http.server 8080

0 commit comments

Comments
 (0)