Skip to content

Commit

Permalink
Created new proto for Transaction actions. Moved most of setup.io cod…
Browse files Browse the repository at this point in the history
…e to hooks/beforeInstall.io
  • Loading branch information
josip committed Apr 25, 2010
1 parent a51c2d8 commit e0b59c7
Show file tree
Hide file tree
Showing 18 changed files with 295 additions and 212 deletions.
74 changes: 39 additions & 35 deletions bin/eerie
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ Kano setUseExternalFile(false)

Eerie do(
_log := getSlot("log")
_allowedModes := list("info", "error", "transaction", "install")

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

System systemInterruptHandler := method(
Eerie Transaction releaseLock)

Namespaces Env := Namespace clone do(
create := task(name,
"""Creates a new environment."""
Expand All @@ -23,8 +27,12 @@ Namespaces Env := Namespace clone do(

remove := task(name,
"""Removes an env with all its packages."""
Eerie Env named(name) remove
"Env #{name} was removed." interpolate println)
env := Eerie Env named(name)
if(Eerie Env activeEnv == env,
"Can't remove active environment." println
,
Eerie Env named(name) remove
"Env #{name} was removed." interpolate println))

active := task(
"""Prints the name of active env."""
Expand All @@ -47,10 +55,8 @@ Namespaces Pkg := Namespace clone do(
install := task(uri,
"""Installs a new package."""
pkg := Eerie Package fromUri(uri)

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

Eerie Transaction clone install(pkg) run

readme := pkg info at("readme")
readmeFile := File with(pkg path .. "/" .. readme)
Expand All @@ -68,21 +74,18 @@ Namespaces Pkg := Namespace clone do(
# unless we modify it - as we do for plugins.
update := task(name,
"""Updates the package and all of its dependencies."""
Eerie Transaction begin

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

Eerie Transaction update(pkg)
Eerie Transaction run)
Eerie Exception clone update(pkg) run)

updateAll := task(
"""Updates all packages within current env."""
Eerie Transaction begin
t := Eerie Transaction clone
Eerie usedEnv packages foreach(pkg,
Eerie Transaction update(pkg))
Eerie Transaction run)
t update(pkg))
t run)

remove := task(name,
"""Removes the package."""
Expand All @@ -91,9 +94,7 @@ Namespaces Pkg := Namespace clone do(
pkg isNil ifTrue(
Exception raise("missingPackage", name))

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

info := task(name,
"""Shows description of a package."""
Expand Down Expand Up @@ -165,31 +166,33 @@ Namespaces Plugin := Namespace clone do(
)

Namespaces Default do(
# Aliases
envs := Namespaces Env getSlot("list")
activate := Namespaces Env getSlot("activate")
pkgs := Namespaces Pkg getSlot("list")
install := Namespaces Pkg getSlot("install")
remove := Namespaces Pkg getSlot("remove")
update := Namespaces Pkg getSlot("update")

selfUpdate := task(
"""Updates Eerie and its dependencies."""
Eerie Env named("_base") use

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")

t := Eerie Transaction clone
Eerie usedEnv packages foreach(pkg, t update(pkg))
t run)

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
lockFile := Eerie Transaction lockFile
lockFile exists ifFalse(
return("There was no lock at all." println))

"Transaction lock has been removed" println)
# TODO: Check if process which has lock exists and kill it.

Eerie Transaction lockFile close remove
"Transaction lock has been removed." println)
)

Namespaces Options do(
Expand All @@ -198,7 +201,8 @@ Namespaces Options do(
Object println = method())

v := option(
"""Use verbose output."""
"""Uses verbose output - debug messages, shell commands - everything will be printed.
Watch out for information overload."""
Eerie log = Eerie getSlot("_log"))

V := option(
Expand Down
4 changes: 4 additions & 0 deletions hooks/afterInstall.io
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env io

Eerie Env named("default") activate

63 changes: 63 additions & 0 deletions hooks/beforeInstall.io
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env io

homePath := User homeDirectory path
eeriePath := homePath .. "/.eerie"
eerieDir := Directory with(eeriePath)

appendEnvVariables := method(
# select() should eliminate symlinks
bashFiles := list("bashrc", "profile", "bash_profile") map(f,
Path with(homePath, "/." .. f)) select(p, File with(p) isRegularFile)

bashScript := """|
|# Four Commandments of Eerie
|EERIEDIR=#{eeriePath}
|PATH=$PATH:$EERIEDIR/base/bin:$EERIEDIR/activeEnv/bin
|export EERIEDIR PATH
|# That's all folks""" fixMultiline interpolate

bashFiles foreach(path,
f := File with(path) openForAppending
f contents containsSeq("EERIEDIR") ifFalse(
f appendToContents(bashScript))
f close))

appendAddonLoaderPaths := method(
iorc := File with(homePath .. "/.iorc")
iorc exists ifFalse(iorc create)
loaderCode := """
AddonLoader appendSearchPath(System getEnvironmentVariable("EERIEDIR") .. "/base/addons")
AddonLoader appendSearchPath(System getEnvironmentVariable("EERIEDIR") .. "/activeEnv)"""

iorc openForAppending contents containsSeq("EERIEDIR") ifFalse(
iorc appendToContents(loaderCode .. "\n"))
iorc close

System setEnvironmentVariable("EERIEDIR", eeriePath))

createDirectories := method(
eerieDir create
eerieDir directoryNamed("env") create
eerieDir directoryNamed("tmp") create

eerieDir fileNamed("/config.json")\
create openForUpdating write("{\"envs\": {}}") close)

createDefaultEnvs := method(
baseEnv := Eerie Env with("_base") create activate use
Eerie sh("ln -s #{baseEnv path} #{eeriePath}/base" interpolate)

Eerie Env with("_plugins") create
Eerie Env with("default") create
Eerie saveConfig)

Sequence fixMultiline := method(
self splitNoEmpties("\n") map(split("|") last) join("\n") strip)

eerieDir exists ifFalse(
appendEnvVariables
appendAddonLoaderPaths
createDirectories
createDefaultEnvs)


23 changes: 14 additions & 9 deletions io/Eerie.io
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,22 @@ Eerie := Object clone do(
sh := method(cmd, logFailure, dir,
self log(cmd, "console")
prevDir := nil
dirPrefix := ""
if(dir != nil and dir != ".",
cmd = "cd " .. dir .. " && " .. cmd
dirPrefix = "cd " .. dir .. " && "
prevDir = Directory currentWorkingDirectory
Directory setCurrentWorkingDirectory(dir))

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

prevDir isNil ifFalse(
Directory setCurrentWorkingDirectory(prevDir))

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

if(cmdOut exitStatus != 0,
if(logFailure == false,
Expand All @@ -51,11 +52,13 @@ Eerie := Object clone do(
true))

_logMods := Map with(
"info", " - ",
"error", " ! ",
"console", " > ",
"debug", " # ",
"output", "")
"info", " - ",
"error", " ! ",
"console", " > ",
"debug", " # ",
"install", " + ",
"transaction", "-> ",
"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")
Expand Down Expand Up @@ -124,6 +127,8 @@ Eerie clone = Eerie do(
doRelativeFile("Eerie/PackageInstaller.io")
//doc Eerie Transaction [[Transaction]]
doRelativeFile("Eerie/Transaction.io")
//doc Eerie TransactionAction [[TransactionAction]]
doRelativeFile("Eerie/TransactionAction.io")

init
)
2 changes: 1 addition & 1 deletion io/Eerie/Exception.io
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Eerie Exception := Exception clone do(

//doc Exception raise(problem, description) Returns a new Eerie Exception.
raise := method(problemKey, msg,
self setProblem(problemKey) setProblemMsg(msg)
self setProblem(problemKey) setMsg(msg)
self super(raise("Eerie: " .. self problem .. ": " .. self problemMsg)))

forward := method(
Expand Down
6 changes: 5 additions & 1 deletion io/Eerie/Package.io
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ Package := Object clone do(
f := File with("#{self path}/hooks/#{hook}.io" interpolate)
f exists ifTrue(
Eerie log("Launching #{hook} hook for #{self name}", "debug")
try(Thread createThread(f contents))
ctx := Object clone
e := try(ctx doFile(f path))
e catch(
Eerie log("#{hook} failed.", "error")
Eerie log(e message, "debug"))
f close))

//doc Package loadInfo Loads package.json file.
Expand Down
13 changes: 10 additions & 3 deletions io/Eerie/PackageDownloader/Directory.io
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ DirectoryDownloader := Eerie PackageDownloader clone do(
Directory with(uri) exists)

download := method(
# Should we copy dot files also? Not copying .git/.svn/etc folders
# is ok, but what about the rest?
Eerie sh("cp -R #{self uri}/* #{self path}" interpolate))

update := getSlot("download")

hasUpdates := method(
# It actually checks if there were any changes on the directory itself
# not really what we need.
# TODO:
# Directory doesen't provide lastDataChange method
original := File with(self uri) lastDataChangeDate
copy := File with(self path) lastDataChangeDate
original > copy)
#original := File with(self uri) lastDataChangeDate
#copy := File with(self path) lastDataChangeDate
#original > copy

true)
)
22 changes: 13 additions & 9 deletions io/Eerie/PackageDownloader/vcs/git.io
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@ git := Object clone do(
download := list("clone #{self uri} #{self path}", "submodule init", "submodule update")
update := list("pull", "submodule update")

hasUpdates := method(path,
# Unfortunately, this isn't working as expected and there seems to be
# no actual way of checking for updates in a repo without pulling it
#hasUpdates := method(path,
# git ls-remote reference: ftp.sunet.se/pub/Linux/kernel.org/software/scm/git/docs/git-ls-remote.html
r := System runCommand("git ls-remote " .. path)
refs := r stdout split("\n") map(split("\t") reverse)
#r := System runCommand("git ls-remote " .. path)
#refs := r stdout split("\n") map(split("\t") reverse)

head := refs detect(first == "HEAD") second
remoteHead := refs detect(first == "refs/remotes/origin/HEAD") second
#head := refs detect(first == "HEAD") second
#remoteHead := refs detect(first == "refs/remotes/origin/HEAD") second

Eerie log("Git repo changes (#{path}):", "debug")
Eerie log("HEAD: #{head}", "debug")
Eerie log("refs/remotes/origin/HEAD: #{remoteHead}", "debug")
#Eerie log("Git repo changes (#{path}):", "debug")
#Eerie log("HEAD: #{head}", "debug")
#Eerie log("refs/remotes/origin/HEAD: #{remoteHead}", "debug")

head != remoteHead)
#head != remoteHead)

hasUpdates := method(true)
)
4 changes: 2 additions & 2 deletions io/Eerie/PackageInstaller.io
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ PackageInstaller := Object clone do(

//doc PackageInstaller copyBinaries Creates symlinks for files <code>bin</code> directory in active environment's <code>bin</code>.
copyBinaries := method(
Eerie sh("chmod +x #{self path}/bin/*" interpolate)
Eerie sh("chmod u+x #{self path}/bin/*" interpolate)
self dirNamed("bin") files foreach(original,
link := File with(Eerie usedEnv path .. "/bin/" .. original name)
link exists ifFalse(
Expand All @@ -132,6 +132,6 @@ PackageInstaller instances := Object clone do(
doRelativeFile("PackageInstaller/File.io")
//doc PackageInstaller Directory Installs whole directories.
doRelativeFile("PackageInstaller/Directory.io")
//doc PacakgeInstaller IoAddon Installs directories with structure of an Io addon.
//doc PacakgeInstaller IoAddon Installs directories structured as an Io addon.
doRelativeFile("PackageInstaller/IoAddon.io")
)
Loading

0 comments on commit e0b59c7

Please sign in to comment.