Skip to content

Commit

Permalink
--module=module --call=module/action preload_modules(var)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpapis committed Aug 2, 2011
1 parent 16e5774 commit 4ae40f9
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 86 deletions.
10 changes: 10 additions & 0 deletions extensions/builtin/core/modules/shell/core/cli
Expand Up @@ -38,6 +38,16 @@ do
debug_flag=1
;;

--module=*)
preload_modules+=( ${token##--module=} )
;;

--call=*)
call_action="${token##--call=}"
[[ "$call_action" =~ \/ ]] && preload_modules+=( ${call_action%/*} ) || true
call_action="${call_action##*/}"
;;

--)
shift #end of processing
extension_args=("$@")
Expand Down
13 changes: 13 additions & 0 deletions extensions/builtin/core/modules/shell/core/initialize
Expand Up @@ -54,6 +54,9 @@ true \
"${active_path:="${packages_path}/active"}" \
"${extension_args:=""}"

# Make sure preload_modules is an array
export preload_modules=( ${preload_modules[@]} )

if [[ -d "${active_path}/bin" ]]
then
export PATH="${active_path}/bin:${active_path}/sbin:${PATH}"
Expand Down Expand Up @@ -81,6 +84,16 @@ if [[ -n $bdsm_script ]]
then
# load script
. $bdsm_script
elif [[ -n "${call_action}" ]]
then
if ! declare -F "${call_action}" >/dev/null
then
error "${call_action} is not a valid function name"
else
trace_filter action
"${call_action}" "${extension_args[@]}"
trace_filter
fi
elif set | grep '^extension_args=(' >/dev/null
then
case "${extension_args[0]}" in
Expand Down
6 changes: 6 additions & 0 deletions extensions/builtin/core/modules/shell/modules/initialize
Expand Up @@ -14,3 +14,9 @@ do
module_path="${module_def//*=}"
log_search preload "$module_name" "${module_path}"
done

for module in ${preload_modules[@]}
do
module_or_error ${module} \
"Can not load preload_module: ${module}"
done
75 changes: 1 addition & 74 deletions extensions/builtin/ext/modules/shell/project/dsl
Expand Up @@ -43,8 +43,7 @@ project_initialize()
: \
"${shared_path:=${project_path}/shared}" \
"${release_path:=${project_path}/current}" \
"${environment:="production"}" \
"${vcs:=$(vcs "${shared_path}/${project}")}"
"${environment:="production"}"

# Set the project log path into the shared path's log directory
project_log_path="$shared_path/log"
Expand All @@ -63,75 +62,3 @@ project_initialize()
source_files ".${project}rc"
fi
}

#
# ## vcs()
#
# Detect and set the vcs, if any, for the current project.
#
# ### Input Parameters
#
# First parameter must be the path to a repository for determining the VCS.
#
# ### Stream Outputs
#
# None.
#
# ### Environmental effects
#
# The environment variable 'vcs' will be set to the VCS detected, or 'git' by
# default.
#
# ### Return Codes
#
# 0 for success
#
# ### Failure Scenarios
#
# Fails if no repository path is given.
#
# ### Usage Examples
#
# user$ vcs /home/appuser/shared/appuser
# user$ echo $vcs
# git
#
# ##### Code Walkthrough
vcs()
{
# Store the first parameter in the path variable. This is the path that we
# will check to see what vcs it contains.
local _path="$1"

# if the path variable is nonempty
if variable_is_nonempty _path
then
# and if there is a .git directory in the given path
if path_exists "${_path}/.git"
then
# Then set the vcs variable to git.
vcs="git"

# and if there is a .svn directory in the given path
elif path_exists "${_path}/.svn"
then
# Then set the vcs variable to svn.
vcs="svn"

# and if there is a .hg directory in the given path
elif path_exists "${_path}/.hg"
then
# Then set the vcs variable to hg.
vcs="hg"

# # TODO: detect when vcs="fossil"
else
# otherwise default the scm to git
vcs="git"
fi
else
# Programming error, no path was passed in in order to determine the vcs
fail "Repository path must be given in order to detect the VCS used."
fi
}

30 changes: 22 additions & 8 deletions extensions/builtin/ext/modules/shell/vcs/dsl
Expand Up @@ -49,7 +49,7 @@ directory_get()

if cp -r ${_source} "${_target}" >/dev/null 2>&1
then
write "$(cd "${_source}"; pwd)" to "${_target}/.uri"
echo "$(cd "${_source}"; pwd)" > "${_target}/.uri"
else
fail "There was an error copying '${_source}'"
fi
Expand All @@ -67,7 +67,14 @@ git_get()

local _target="${scm_path}/$( scm_identifier "${_url}" )"

if path_exists "$_target/.git"
_final_target=$(
builtin cd "${initial_pwd}"
mkdir -p "${_final_target}"
builtin cd "${_final_target}"
pwd
)

if [[ -d "$_target/.git" ]]
then
builtin cd "${_target}"
git checkout master -f -q 2>&1 >/dev/null
Expand Down Expand Up @@ -101,28 +108,29 @@ git_get()
fail "Git pull failed."
fi
else
ensure_paths_exist "${_target}"
mkdir -p "${_target}"
if git clone --depth 1 ${_url} "${_target}" 2>&1 >/dev/null
then
echo "${_url}" > "${_target}/.uri"
else
local _url_https="${_url/git:\/\//https:\/\/}"
if git clone --depth 1 ${_url_https} "${_target}" 2>&1 >/dev/null
then
write "${_url_https}" to "${_target}/.uri"
echo "${_url_https}" > "${_target}/.uri"
else
fail "There was an error while cloning the repository from the url '${_url}'"
fi
fi
fi

rm -rf "${_final_target}" 2>&1 >/dev/null

if ! cp -r "${_target}" "${_final_target}" 2>&1 >/dev/null
if ! cp -frT "${_target}" "${_final_target}" 2>&1 >/dev/null
then
fail "There was an error copying '${_target}' -> '${_final_target}'"
fi

enter "$initial_pwd"
builtin cd "$initial_pwd"
}

hg_get()
Expand Down Expand Up @@ -163,7 +171,7 @@ github_get()
# use git for fetching github repo
git_get "git://github.com/${_url}.git" "${_target}" "$@"
# and overwrite repo uri
write "${_url}" to "${_target}/.uri"
echo "${_url}" > "${_target}/.uri"
}

archive_get() {
Expand Down Expand Up @@ -225,6 +233,7 @@ is_archive_uri() {
return 0
;;
esac
return 1
}

# ## fetch\_uri()
Expand All @@ -242,7 +251,7 @@ fetch_uri()
log "${log_prefix}Fetching $1"
unset scm_type

if path_exists "$1" # check for directory
if [[ -d "$1" ]] # check for directory
then
scm_type='directory'
directory_get "$@"
Expand Down Expand Up @@ -286,6 +295,11 @@ fetch_uri()
esac
}

fetch()
{
fetch_uri "$@"
}

scm_help()
{
NIY "display help for scm"
Expand Down
1 change: 1 addition & 0 deletions extensions/builtin/ext/modules/shell/vcs/modules
@@ -0,0 +1 @@
bdsm/variables
3 changes: 0 additions & 3 deletions extensions/builtin/install/actions/install

This file was deleted.

1 change: 1 addition & 0 deletions extensions/builtin/install/modules/shell/modules
@@ -1,2 +1,3 @@
bdsm/filesystem
ext/vcs
ext/users
3 changes: 2 additions & 1 deletion install
Expand Up @@ -37,7 +37,8 @@ bdsm_path="$PWD" # Path to load everything from
modules_path="${bdsm_path}/extensions/builtin/core/modules"
export initial_pwd bdsm_path modules_path

extension_args=(install install)
preload_modules=( install )
call_action=install_bdsm
# basic options parsing
. "${modules_path}/shell/core/cli"
# initialize BDSM
Expand Down

0 comments on commit 4ae40f9

Please sign in to comment.