/ laxyfile / scripts / create_chocolatey_package.py
swadhin biswas Ok batman Β· 7/28/2025
fb9342e
298 lines Β· 9.7 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#!/usr/bin/env python3
"""
Chocolatey Package Generator

Creates and updates Chocolatey package for LaxyFile
"""

import os
import sys
from pathlib import Path
import argparse
import datetime


def create_nuspec_file(version: str) -> str:
    """Create Chocolatey nuspec file content"""

    current_year = datetime.datetime.now().year

    nuspec_content = f'''<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
  <metadata>
    <id>laxyfile</id>
    <version>{version}</version>
    <packageSourceUrl>https://github.com/swadhinbiswas/laxyfile</packageSourceUrl>
    <owners>LaxyFile Team</owners>
    <title>LaxyFile - Advanced Terminal File Manager</title>
    <authors>LaxyFile Team</authors>
    <projectUrl>https://github.com/swadhinbiswas/laxyfile</projectUrl>
    <iconUrl>https://raw.githubusercontent.com/swadhinbiswas/laxyfile/main/docs/assets/icon.png</iconUrl>
    <copyright>{current_year} LaxyFile Team</copyright>
    <licenseUrl>https://github.com/swadhinbiswas/laxyfile/blob/main/LICENSE</licenseUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <projectSourceUrl>https://github.com/swadhinbiswas/laxyfile</projectSourceUrl>
    <docsUrl>https://github.com/swadhinbiswas/laxyfile#readme</docsUrl>
    <bugTrackerUrl>https://github.com/swadhinbiswas/laxyfile/issues</bugTrackerUrl>
    <tags>file-manager terminal cli python ai superfile</tags>
    <summary>Beautiful, AI-powered terminal file manager inspired by Superfile</summary>
    <description><![CDATA[
LaxyFile is an advanced terminal file manager that combines the elegant interface of Superfile with powerful AI capabilities.

## Features

- **Beautiful Interface**: Dual-pane layout with modern terminal UI
- **AI Assistant**: Intelligent file analysis, organization, and security auditing
- **Media Support**: Image preview, video analysis, and metadata extraction
- **File Operations**: Copy, move, delete, batch operations with progress tracking
- **Cross-Platform**: Native support for Windows, macOS, and Linux
- **Themes**: 5 beautiful built-in themes with customization options
- **Performance**: Optimized for large directories and file collections

## Requirements

- Python 3.8 or higher
- Modern terminal with color support
- 256MB+ RAM
- 50MB+ free disk space

## AI Setup

1. Get a free API key from OpenRouter (https://openrouter.ai/)
2. Set environment variable: `$env:OPENROUTER_API_KEY="your-key"`
3. Launch LaxyFile and enjoy AI features!

## Usage

After installation, simply run `laxyfile` in your terminal to start the application.

For more information, visit: https://github.com/swadhinbiswas/laxyfile
]]></description>
    <releaseNotes>https://github.com/swadhinbiswas/laxyfile/releases/tag/v{version}</releaseNotes>
    <dependencies>
      <dependency id="python3" version="3.8.0" />
    </dependencies>
  </metadata>
  <files>
    <file src="tools\\**" target="tools" />
  </files>
</package>
'''

    return nuspec_content


def create_install_script(version: str) -> str:
    """Create Chocolatey install script"""

    install_script = f'''$ErrorActionPreference = 'Stop'

$packageName = 'laxyfile'
$version = '{version}'

Write-Host "Installing LaxyFile v$version..." -ForegroundColor Green

# Check for Python
$pythonCmd = $null
$pythonPaths = @("python", "python3", "py")

foreach ($cmd in $pythonPaths) {{
    try {{
        $result = & $cmd --version 2>$null
        if ($LASTEXITCODE -eq 0 -and $result -match "Python 3\.([8-9]|1[0-9])") {{
            $pythonCmd = $cmd
            Write-Host "Found Python: $result" -ForegroundColor Green
            break
        }}
    }} catch {{
        # Command not found, continue
    }}
}}

if (-not $pythonCmd) {{
    throw @"
Python 3.8+ is required but not found in PATH.

Please install Python from:
- Microsoft Store: https://apps.microsoft.com/store/detail/python-311/9NRWMJP3717K
- Python.org: https://www.python.org/downloads/windows/
- Chocolatey: choco install python

After installation, restart your terminal and try again.
"@
}}

# Upgrade pip
Write-Host "Upgrading pip..." -ForegroundColor Yellow
& $pythonCmd -m pip install --upgrade pip

# Install LaxyFile
Write-Host "Installing LaxyFile from PyPI..." -ForegroundColor Yellow
$installResult = & $pythonCmd -m pip install "laxyfile==$version" 2>&1

if ($LASTEXITCODE -ne 0) {{
    Write-Host "Failed to install from PyPI, trying latest version..." -ForegroundColor Yellow
    $installResult = & $pythonCmd -m pip install laxyfile 2>&1

    if ($LASTEXITCODE -ne 0) {{
        throw "Failed to install LaxyFile: $installResult"
    }}
}}

# Verify installation
Write-Host "Verifying installation..." -ForegroundColor Yellow
$verifyResult = & $pythonCmd -c "import laxyfile; print('LaxyFile installed successfully!')" 2>&1

if ($LASTEXITCODE -ne 0) {{
    throw "Installation verification failed: $verifyResult"
}}

# Create launcher script in a location that's likely to be in PATH
$launcherDir = "$env:LOCALAPPDATA\\Microsoft\\WindowsApps"
$launcherPath = "$launcherDir\\laxyfile.cmd"

if (Test-Path $launcherDir) {{
    $launcherContent = @"
@echo off
$pythonCmd -m laxyfile %*
"@

    try {{
        Set-Content -Path $launcherPath -Value $launcherContent -Encoding ASCII
        Write-Host "Created launcher: $launcherPath" -ForegroundColor Green
    }} catch {{
        Write-Host "Could not create launcher in $launcherDir" -ForegroundColor Yellow
    }}
}}

Write-Host ""
Write-Host "πŸŽ‰ LaxyFile v$version installed successfully!" -ForegroundColor Green
Write-Host ""
Write-Host "πŸ“‹ Usage:" -ForegroundColor Cyan
Write-Host "  laxyfile          # Start LaxyFile"
Write-Host "  laxyfile --help   # Show help"
Write-Host ""
Write-Host "πŸ€– AI Setup (Optional):" -ForegroundColor Cyan
Write-Host "  1. Get free API key from https://openrouter.ai/"
Write-Host "  2. Set environment variable:"
Write-Host "     `$env:OPENROUTER_API_KEY=`"your-key`""
Write-Host "  3. Restart terminal and enjoy AI features!"
Write-Host ""
Write-Host "πŸ“š Documentation: https://github.com/swadhinbiswas/laxyfile#readme" -ForegroundColor Cyan
Write-Host "πŸ› Issues: https://github.com/swadhinbiswas/laxyfile/issues" -ForegroundColor Cyan
'''

    return install_script


def create_uninstall_script() -> str:
    """Create Chocolatey uninstall script"""

    uninstall_script = '''$ErrorActionPreference = 'Stop'

$packageName = 'laxyfile'

Write-Host "Uninstalling LaxyFile..." -ForegroundColor Yellow

# Find Python command
$pythonCmd = $null
$pythonPaths = @("python", "python3", "py")

foreach ($cmd in $pythonPaths) {
    try {
        $result = & $cmd --version 2>$null
        if ($LASTEXITCODE -eq 0) {
            $pythonCmd = $cmd
            break
        }
    } catch {
        # Command not found, continue
    }
}

if ($pythonCmd) {
    # Uninstall LaxyFile
    Write-Host "Removing LaxyFile package..." -ForegroundColor Yellow
    & $pythonCmd -m pip uninstall laxyfile -y 2>$null

    if ($LASTEXITCODE -eq 0) {
        Write-Host "LaxyFile package removed successfully" -ForegroundColor Green
    } else {
        Write-Host "LaxyFile package was not found or already removed" -ForegroundColor Yellow
    }
} else {
    Write-Host "Python not found, skipping package removal" -ForegroundColor Yellow
}

# Remove launcher script
$launcherPath = "$env:LOCALAPPDATA\\Microsoft\\WindowsApps\\laxyfile.cmd"
if (Test-Path $launcherPath) {
    try {
        Remove-Item $launcherPath -Force
        Write-Host "Removed launcher: $launcherPath" -ForegroundColor Green
    } catch {
        Write-Host "Could not remove launcher: $launcherPath" -ForegroundColor Yellow
    }
}

Write-Host "LaxyFile uninstalled successfully!" -ForegroundColor Green
'''

    return uninstall_script


def main():
    """Main entry point"""
    parser = argparse.ArgumentParser(description="Create Chocolatey package for LaxyFile")
    parser.add_argument("--version", required=True, help="Version to create package for")
    parser.add_argument("--output-dir", help="Output directory (default: packaging/chocolatey)")

    args = parser.parse_args()

    # Determine output directory
    if args.output_dir:
        output_dir = Path(args.output_dir)
    else:
        project_root = Path(__file__).parent.parent
        output_dir = project_root / "packaging" / "chocolatey"

    # Create output directories
    output_dir.mkdir(parents=True, exist_ok=True)
    tools_dir = output_dir / "tools"
    tools_dir.mkdir(exist_ok=True)

    print(f"🍫 Creating Chocolatey package for LaxyFile v{args.version}")

    # Create nuspec file
    nuspec_content = create_nuspec_file(args.version)
    nuspec_path = output_dir / "laxyfile.nuspec"
    nuspec_path.write_text(nuspec_content, encoding='utf-8')
    print(f"βœ… Created nuspec: {nuspec_path}")

    # Create install script
    install_content = create_install_script(args.version)
    install_path = tools_dir / "chocolateyinstall.ps1"
    install_path.write_text(install_content, encoding='utf-8')
    print(f"βœ… Created install script: {install_path}")

    # Create uninstall script
    uninstall_content = create_uninstall_script()
    uninstall_path = tools_dir / "chocolateyuninstall.ps1"
    uninstall_path.write_text(uninstall_content, encoding='utf-8')
    print(f"βœ… Created uninstall script: {uninstall_path}")

    print()
    print("πŸ“‹ Next steps:")
    print("1. Test the package locally:")
    print(f"   choco pack {nuspec_path}")
    print(f"   choco install laxyfile -s . -f")
    print("2. Submit to Chocolatey Community Repository:")
    print("   https://docs.chocolatey.org/en-us/community-repository/moderation/")
    print("3. Or host in your own repository:")
    print("   https://docs.chocolatey.org/en-us/guides/organizations/organizational-deployment-guide")

    return 0


if __name__ == "__main__":
    sys.exit(main())