import os import osproc import strutils import re import cgi import parseopt # -------- # get variable value from configuration shell file # -------- proc confVar(variable: string, confFile = "/etc/slitaz/tazpanel.conf"): string = var tmpFile = JoinPath(getTempDir(), "tazpanel.tmp") writeFile(tmpFile, "#!/bin/sh\n. " & confFile & "\necho -n $" & variable & "\n") result = execCmdEx("sh " & tmpFile).output.strip removeFile(tmpFile) return # ======== # List installed packages. Generate table body only # ======== proc list = var installed = confVar("INSTALLED") images = confVar("IMAGES") blockedF = JoinPath(confVar("LOCALSTATE"), "blocked-packages.list") blocked = "" if existsFile(blockedF): blocked = readfile(blockedF) # get installed pkgs list setCurrentDir(installed) var installed_ls = execCmdEx("ls -1") for pkg in installed_ls.output.splitLines: if pkg != "": var version, description, web = "" var receipt = readfile(JoinPath(installed, pkg, "receipt")) for line in receipt.splitLines: if line =~ re"\s*VERSION\s*\=\s*\042([^\042]+)\042\s*": version = matches[0] elif line =~ re"\s*SHORT_DESC\s*\=\s*\042([^\042]+)\042\s*": description = matches[0] elif line =~ re"\s*WEB_SITE\s*\=\s*\042([^\042]+)\042\s*": web = matches[0] # if version need to be calculated (slow) # if version =~ re".*\$.*": version = confVar("VERSION", JoinPath(installed, pkg, "receipt")) # colorize blocked pkgs var colorpkg = pkg for blk in blocked.splitLines: if blk == pkg: colorpkg = "" & pkg & "" echo( "" & "" & "" & "" & "" & colorpkg & "" & "" & "" & version & "" & "" & description.XMLencode & "" & "" & "" & "" & "" & "") # end proc list() # ======== # List all available packages by category on mirror. Generate table body only # ======== proc cat(repo: string, cat_filter = "all") = var installed = confVar("INSTALLED") images = confVar("IMAGES") desc_file = readfile(JoinPath(repo, "packages.desc")) for line in desc_file.splitLines: if line != "": var fields = line.split('|') pkg_name = fields[0].strip version = fields[1].strip short_desc = fields[2].strip category = fields[3].strip web_site = fields[4].strip image = "tazpkg.png" if existsDir(JoinPath(installed, pkg_name)): image = "tazpkg-installed.png" if (cat_filter == "all") or (category == cat_filter): echo( "" & "" & "" & "" & "" & pkg_name & "" & "" & version & "" & "" & short_desc.XMLencode & "" & "" & "" & "" & "") # end proc parse_packages_desc() var op = initOptParser() op.next() case op.key of "list": list() of "cat": op.next() var category = op.key if category == "": category = "base" op.next() var repo = op.key if repo == "": repo = "/var/lib/tazpkg" cat(repo, category)