Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
LECABashLib
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LECASofts
LECABashLib
Commits
f6605c35
Commit
f6605c35
authored
Feb 01, 2018
by
Eric Coissac
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of git.metabarcoding.org:lecasofts/LECABashLib
parents
6422d5de
f581949d
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
139 additions
and
6 deletions
+139
-6
README.md
README.md
+20
-4
path.sh
path.sh
+86
-0
utils.sh
utils.sh
+33
-2
No files found.
README.md
View file @
f6605c35
...
...
@@ -376,7 +376,6 @@ If the file does not exist it is created
Closes the current logfile and redirect the logging to stderr.
----------------------------------------------------------
...
...
@@ -486,7 +485,6 @@ Closes the current logfile and redirect the logging to stderr.
setintersec <SETNAME1> <SETNAME2> <DESTINATION>
```
----------------------------------------------------------
...
...
@@ -576,7 +574,6 @@ and the return status is set to *1* instead of *0* usually.
tempdirectory <VARIABLE> [MINSIZE]
```
----------------------------------------------------------
...
...
@@ -598,6 +595,26 @@ and the return status is set to *1* instead of *0* usually.
```
----------------------------------------------------------
## path
### Activating the module
> source $LECABASHHOME/utils.sh
> include path
### Functions provided:
#### relative2absolute
relative2absolute <PATH>
#### absolute2relative
```
bash
absolute2relative <PATH> <RELATIVE_TO>
```
----------------------------------------------------------
## irods
...
...
@@ -642,7 +659,6 @@ ex:
fi
```
----------------------------------------------------------
...
...
path.sh
0 → 100644
View file @
f6605c35
# LECA Bash library
#
# The LECA bash library provides a set of function used for helping
# development of bash script mainly to write job script on the luke
# cluster
#
# The files from the LECA Bash library must be sourced from your main script
#
#
include logging
logdebug
"Load path package"
relative2absolute
(){
local
thePath
if
[[
!
"
$1
"
=
~ ^/
]]
;
then
thePath
=
"
$PWD
/
$1
"
else
thePath
=
"
$1
"
fi
echo
"
$thePath
"
|
(
IFS
=
/
read
-a
parr
declare
-a
outp
for
i
in
"
${
parr
[@]
}
"
;
do
case
"
$i
"
in
''
|
.
)
continue
;;
..
)
len
=
${#
outp
[@]
}
if
((
len
==
0
))
;
then
continue
else
unset
outp[
$((
len-1
))
]
fi
;;
*
)
len
=
${#
outp
[@]
}
outp[
$len
]=
"
$i
"
;;
esac
done
echo
/
"
${
outp
[*]
}
"
)
}
function
absolute2relative
()
{
# both $1 and $2 are absolute paths beginning with /
# returns relative path to $2/$target from $1/$source
source
=
$1
target
=
$2
common_part
=
$source
# for now
result
=
""
# for now
while
[[
"
${
target
#
$common_part
}
"
==
"
${
target
}
"
]]
;
do
# no match, means that candidate common part is not correct
# go up one level (reduce common part)
common_part
=
"
$(
dirname
$common_part
)
"
# and record that we went back, with correct / handling
if
[[
-z
$result
]]
;
then
result
=
".."
else
result
=
"../
$result
"
fi
done
if
[[
$common_part
==
"/"
]]
;
then
# special case for root (no common path)
result
=
"
$result
/"
fi
# since we now have identified the common part,
# compute the non-common part
forward_part
=
"
${
target
#
$common_part
}
"
# and now stick all parts together
if
[[
-n
$result
]]
&&
[[
-n
$forward_part
]]
;
then
result
=
"
$result$forward_part
"
elif
[[
-n
$forward_part
]]
;
then
# extra slash removal
result
=
"
${
forward_part
:1
}
"
fi
echo
$result
}
utils.sh
View file @
f6605c35
...
...
@@ -13,6 +13,10 @@ if [[ -z "${LECALIB_UTIL_SH}" ]]; then
LECALIB_UTIL_SH
=
1
LECABASHLIB_RELOADING
=
0
if
[[
-z
"
$LECABASHLIB_PATH
"
]]
;
then
export
LECABASHLIB_PATH
=
""
fi
THIS_DIR
=
"
$(
dirname
${
BASH_SOURCE
[0]
})
"
source
"
${
THIS_DIR
}
/utils.sh"
...
...
@@ -40,11 +44,36 @@ if [[ -z "${LECALIB_UTIL_SH}" ]]; then
local
MODULE
=
$(
upper
$1
)
local
LOADED_MODULE_VAR
=
"LECALIB_
${
MODULE
}
_SH"
local
LOADED_MODULE
=
$(
indirect
$LOADED_MODULE_VAR
)
if
[[
-z
"
${
LOADED_MODULE
}
"
||
"
$LECABASHLIB_RELOADING
"
==
1
]]
;
then
local
found
=
""
for
path
in
$(
echo
$LECABASHLIB_PATH
| sed
's/:/ /g'
)
;
do
if
[[
-z
"
$found
"
&&
\
(
-z
"
${
LOADED_MODULE
}
"
||
\
"
$LECABASHLIB_RELOADING
"
==
1
)
&&
\
-f
"
${
path
}
/
${
1
}
.sh"
]]
;
then
source
"
${
path
}
/
${
1
}
.sh"
eval
$LOADED_MODULE_VAR
=
1
found
=
1
fi
done
if
[[
-z
"
$found
"
&&
\
(
-z
"
${
LOADED_MODULE
}
"
||
\
"
$LECABASHLIB_RELOADING
"
==
1
)
&&
\
-f
"
${
LECALIB_DIR
}
/
${
1
}
.sh"
]]
;
then
source
"
${
LECALIB_DIR
}
/
${
1
}
.sh"
eval
$LOADED_MODULE_VAR
=
1
found
=
1
fi
if
((
found
==
1
))
;
then
if
((
LECABASHLIB_RELOADING
==
1
))
;
then
loginfo
"Module
$1
reloaded..."
logdebug
"Module
$1
reloaded..."
else
logdebug
"Module
$1
loaded..."
fi
else
if
[[
-z
"
${
LOADED_MODULE
}
"
]]
;
then
logerror
"Cannot load module
$1
"
fi
fi
}
...
...
@@ -72,5 +101,7 @@ if [[ -z "${LECALIB_UTIL_SH}" ]]; then
command popd
"
$@
"
>
/dev/null
}
include logging
fi
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment