Skip to content

Commit

Permalink
Added Transactions and dependency resolution. Introduced new Exceptio…
Browse files Browse the repository at this point in the history
…n object.
  • Loading branch information
josip committed Apr 22, 2010
1 parent 812bc87 commit a51c2d8
Show file tree
Hide file tree
Showing 23 changed files with 445 additions and 204 deletions.
124 changes: 87 additions & 37 deletions bin/eerie
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ Kano setUseExternalFile(false)

Eerie do(
_log := getSlot("log")

log = method(str, mode,
(mode == nil or mode == "info" or mode == "error") ifTrue(
self _log(str, mode)))
call delegateToMethod(self, "_log")))
)

Namespaces Env := Namespace clone do(
Expand All @@ -28,79 +29,93 @@ Namespaces Env := Namespace clone do(
active := task(
"""Prints the name of active env."""
Eerie activeEnv name println)
)

Eerie describe do(
setNamespace(Namespaces Env)
task("list") do(
describe("Lists all available environments.")
callsSlot("envs")

after(envs,
envs = envs map(env,
if(env isActive, env name .. " [A]", env name))
envs select(!= nil)\
select(exSlice(0, 1) != "_")\
sort)

returns(List, Map with("joinWith", "\n",
"bullet", "*",
"indent", 1))
)
) done
list := task(
"""Lists all envs. Active environment has an asterisk before its name."""

activeEnv := Eerie activeEnv name
Eerie envs map(name) sort foreach(env,
if(env exSlice(0, 1) == "_",
Eerie log(env, "debug")
,
active := if(activeEnv == env, " * ", " - ")
(active .. env) println
)))
)

Namespaces Pkg := Namespace clone do(
install := task(uri,
"""Installs a new package."""
pkg := Eerie Package fromUri(uri)
pkg install
"Package #{pkg name} has been installed." interpolate println

Eerie Transaction begin
Eerie Transaction install(pkg)
Eerie Transaction run

readme := pkg info at("readme")
readmeFile := File with(pkg path .. "/" .. readme)
readmeFile exists ifTrue(
"Opening readme file..." println
# Allows user to abort with Control+C
System sleep(2)
System sleep(4)

openCommand := if(System platform == "Darwin", "open", System getEnvironmentVariable("EDITOR"))
openCommand isNil ifTrue(openCommand = "most")
openCommand isNil ifTrue(openCommand = "more")

System system(openCommand .. " " .. readmeFile path)))

# We are using Eerie usedEnv here because it will be the same as activeEnv
# unless we modify it - as we do for plugins.
update := task(name,
"""Updates the package and all of its dependencies."""
Eerie activeEnv packageNamed(name) ?update
"Package #{name} has been updated." interpolate println)
Eerie Transaction begin

pkg := Eerie usedEnv packageNamed(name)
pkg isNil ifTrue(
Eerie Exception raise("missingPackage", name))

Eerie Transaction update(pkg)
Eerie Transaction run)

updateAll := task(
"""Updates all packages within current env."""
Eerie activeEnv packages foreach(pkg,
pkg update ifTrue("#{pkg name} has been updated." interpolate println)))
Eerie Transaction begin
Eerie usedEnv packages foreach(pkg,
Eerie Transaction update(pkg))
Eerie Transaction run)

remove := task(name,
"""Removes the package."""
Eerie activeEnv packageNamed(name) ?remove
"Package #{name} has been removed." interpolate println)

pkg := Eerie usedEnv packageNamed(name)
pkg isNil ifTrue(
Exception raise("missingPackage", name))

Eerie Transaction begin
Eerie Transaction remove(pkg)
Eerie Transaction run)

info := task(name,
"""Shows description of a package."""
pkg := Eerie activeEnv packageNamed(name)
pkg := Eerie usedEnv packageNamed(name)
pkg isNil ifTrue(
Exception raise("No such package exists."))
Eerie Exception raise("missingPackage", name))

maxKeySize := pkg info keys map(size) max + 2

meta foreach(key, value,
pkg info foreach(key, value,
value isKindOf(List) ifTrue(value = value join(", "))
value isKindOf(Map) ifTrue(value = value asObject slotSummary)
key = (key asMutable makeFirstCharacterUppercase .. ":") alignLeft(maxKeySize, " ")
(key .. value) println))

list := task(
"""Lists all packages installed within current env."""
Eerie activeEnv packages foreach(pkg,
(pkg name .. " @" .. (pkg info at("version"))) println
Eerie usedEnv packages foreach(pkg,
website := pkg info at("website")
website = if(website isNil, "", " (" .. website .. ")")

(pkg name .. " @" .. (pkg info at("version")) .. website) println
(" " .. (pkg info at("description"))) println))

create := task(name, path,
Expand All @@ -112,7 +127,7 @@ Namespaces Pkg := Namespace clone do(

root := Directory with(path)
root exists ifTrue(
Exception raise("Destination directory already exists (#{path})" interpolate))
Eerie Exception raise("alreadyInstalled", path))

root create
Eerie PackageDownloader clone setPath(path) createSkeleton
Expand All @@ -122,6 +137,8 @@ Namespaces Pkg := Namespace clone do(
| "version": "0.1",
| "description": "My cool new project.",
| "author": "#{User name}",
| "website": "http://#{name}-project.org/",
| "readme": "README",
| "protos": ["#{name}"],
| "dependencies": {
| "libs": [],
Expand All @@ -138,22 +155,55 @@ Namespaces Pkg := Namespace clone do(
"New package structure has been created in #{root path}." interpolate println)
)

Namespaces Plugin := Namespace clone do(
_before := method(
Eerie Env named("_plugins") use)

install := Namespaces Pkg getSlot("install") setSlot("description", "Installs new plugin.")
remove := Namespaces Pkg getSlot("remove") setSlot("description", "Removes a plugin.")
list := Namespaces Pkg getSlot("list") setSlot("description", "Lists all installed plugins.")
)

Namespaces Default do(
selfUpdate := task(
"""Updates Eerie and its dependencies."""
Eerie Env named("_base") use
Eerie usedEnv packages foreach(update))

Eerie Transaction begin
Eerie usedEnv packages foreach(pkg, Eerie Transaction update(pkg))
Eerie Transaction run)

envs := Namespaces Env getSlot("list")
pkgs := Namespaces Pkg getSlot("list")
install := Namespaces Pkg getSlot("install")
remove := Namespaces Pkg getSlot("remove")

update := task(
"""Updates Eerie along with installed packages."""
Namespaces Default selfUpdate
Eerie activeEnv use
Namespaces Pkg updateAll)

releaseLock := task(
"""Removes transaction lock.
Use only if you are sure that process which placed the lock isn't running."""
Eerie Transaction lockFile close remove

"Transaction lock has been removed" println)
)

Namespaces Options do(
s := option(
"""Print nothing to stdout."""
Object println = method())

v := option(
"""Use verbose output."""
Eerie log = Eerie getSlot("_log"))

V := option(
"""Prints Eerie version."""
Eerie Env named("_base") packageNamed("Eerie") info at("version") println)
)

Kano run
38 changes: 28 additions & 10 deletions io/Eerie.io
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,25 @@ Eerie := Object clone do(
//doc Eerie envs List of environmets
envs := List clone

//doc Eerie sh(cmd[, logFailure=true, dir=cwd]) Executes system command.
/*doc Eerie sh(cmd[, logFailure=true, dir=cwd])
Executes system command. If logFailure is true and command exists with non-zero value application will abort.
*/
sh := method(cmd, logFailure, dir,
self log(cmd, "console")
dir isNil ifFalse(
prevDir := nil
if(dir != nil and dir != ".",
cmd = "cd " .. dir .. " && " .. cmd
prevDir := Directory currentWorkingDirectory
prevDir = Directory currentWorkingDirectory
Directory setCurrentWorkingDirectory(dir))

cmdOut := System runCommand(cmd)
stdOut := cmdOut stdout
stdErr := cmdOut stderr

dir isNil ifFalse(
prevDir isNil ifFalse(
Directory setCurrentWorkingDirectory(prevDir))

# System runCommand leaves weird files behind
System system("rm -f *-stdout")
System system("rm -f *-stderr")

Expand All @@ -52,7 +56,7 @@ Eerie := Object clone do(
"console", " > ",
"debug", " # ",
"output", "")
//doc Eerie log(message, mode) Displays the message to the user, mode can be "info", "error", "console" or "output".
//doc Eerie log(message, mode) Displays the message to the user, mode can be "info", "error", "console", "debug" or "output".
log := method(str, mode,
mode ifNil(mode = "info")
((self _logMods at(mode)) .. str) interpolate(call sender) println)
Expand All @@ -69,9 +73,11 @@ Eerie := Object clone do(
activeEnv_ isNil ifFalse(
self setActiveEnv(Eerie Env named(activeEnv_))
self activeEnv use)

self loadPlugins
self)

//doc Eerie updateConfig(key, value) Updates config object.
//doc Eerie updateConfig(key, value) Updates config Map.
updateConfig := method(key, value,
self config atPut(key, value)
self saveConfig)
Expand All @@ -85,10 +91,18 @@ Eerie := Object clone do(
revertConfig := method(
self configFile close remove openForUpdating write(self configBackup)
self setConfig(Yajl parseJson(self configBackup)))

//doc Eerie loadPlugins Loads Eerie plugins.
loadPlugins := method(
self plugins := Object clone

Eerie Env named("_plugins") ?packages ?foreach(pkg,
self log("Loading #{pkg name} plugin", "debug")
self plugins doFile(pkg path .. "/io/main.io")))
)

# Fixing Yajl's not-printing of errors
Yajl do(
# Fixing Yajl's silent treatment of parse errors
Yajl do(
_parseJson := getSlot("parseJson")
parseJson = method(json,
result := Yajl _parseJson(json)
Expand All @@ -98,14 +112,18 @@ Yajl do(
)

Eerie clone = Eerie do(
//doc Eerie Exception [[Exception]]
doRelativeFile("Eerie/Exception.io")
//doc Eerie Env [[Env]]
doRelativeFile("Eerie/Env.io")
//doc Eerie Package [[Pacakge]]
doRelativeFile("Eerie/Package.io")
//doc Eerie PackageDownloader [[PackageDownloader]]
doRelativeFile("Eerie/PackageDownloader.io")
//doc Eerie PackageInstaller [[PackageInstaller]]
doRelativeFile("Eerie/PackageInstaller.io")
//doc Eerie Env [[Env]]
doRelativeFile("Eerie/Env.io")
//doc Eerie Transaction [[Transaction]]
doRelativeFile("Eerie/Transaction.io")

init
)
Loading

0 comments on commit a51c2d8

Please sign in to comment.