Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
beat
beat.cmdline
Commits
5124609c
Commit
5124609c
authored
May 24, 2018
by
Samuel GAIST
Browse files
Merge branch 'edit_command' into '1.4.x'
Add edit command for all packages and unit tests See merge request
!31
parents
5a4a06a3
93f4860e
Pipeline
#20462
passed with stages
in 25 minutes and 5 seconds
Changes
12
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
beat/cmdline/algorithms.py
View file @
5124609c
...
...
@@ -30,6 +30,7 @@
%(prog)s algorithms list [--remote]
%(prog)s algorithms check [<name>]...
%(prog)s algorithms path [<name>]...
%(prog)s algorithms edit <name>...
%(prog)s algorithms pull [--force] [<name>]...
%(prog)s algorithms push [--force] [--dry-run] [<name>]...
%(prog)s algorithms diff <name>
...
...
@@ -46,6 +47,7 @@
Commands:
list Lists all the algorithms available on the platform
path Displays local path of algorithm files
edit Edit local algorithm file
check Checks a local algorithm for validity
pull Downloads the specified algorithms from the server
push Uploads algorithms to the server
...
...
@@ -356,6 +358,9 @@ def process(args):
elif
args
[
'path'
]:
return
common
.
display_local_path
(
args
[
'config'
].
path
,
'algorithm'
,
args
[
'<name>'
])
elif
args
[
'edit'
]:
return
common
.
edit_local_file
(
args
[
'config'
].
path
,
args
[
'config'
].
editor
,
'algorithm'
,
args
[
'<name>'
][
0
])
elif
args
[
'check'
]:
return
common
.
check
(
args
[
'config'
].
path
,
'algorithm'
,
args
[
'<name>'
])
...
...
beat/cmdline/common.py
View file @
5124609c
...
...
@@ -398,7 +398,7 @@ def make_up_local_list(prefix, type, requirements):
try
:
root
=
os
.
path
.
join
(
prefix
,
TYPE_NOSTORAGE
[
type
])
except
:
logger
.
error
(
"Selected type is not valid: %s"
%
type
)
logger
.
error
(
"Selected type is not valid: %s"
,
type
)
return
1
l
=
glob
.
glob
(
os
.
path
.
join
(
root
,
TYPE_GLOB
[
type
]))
...
...
@@ -506,7 +506,7 @@ def display_local_path(prefix, type, names):
try
:
selected_type
=
TYPE_PLURAL
[
type
]
except
:
logger
.
error
(
"Selected type is not valid: %s"
%
type
)
logger
.
error
(
"Selected type is not valid: %s"
,
type
)
return
1
else
:
selected_type
=
TYPE_NOSTORAGE
[
type
]
...
...
@@ -526,6 +526,74 @@ def display_local_path(prefix, type, names):
return
0
def
edit_local_file
(
prefix
,
editor
,
type
,
name
):
'''Implements the local "path" command
Parameters:
prefix (str): A string representing the root of the path in which the user
objects are stored
type (str): One of ``database``, ``dataformat``, ``algorithm``,
``toolchain`` or ``experiment``.
Returns:
int: Indicating the exit status of the command, to be reported back to the
calling process. This value should be zero if everything works OK,
otherwise, different than zero (POSIX compliance).
'''
selected_type
=
None
if
type
not
in
NOSTORAGE
:
try
:
selected_type
=
TYPE_PLURAL
[
type
]
except
:
logger
.
error
(
"Selected type is not valid: %s"
,
type
)
return
1
else
:
selected_type
=
TYPE_NOSTORAGE
[
type
]
python_objects
=
[
"database"
,
"library"
,
"algorithm"
,
"plotter"
]
json_objects
=
[
"dataformat"
,
"toolchain"
,
"experiment"
,
"plotterparameter"
]
ext
=
None
if
type
in
python_objects
:
ext
=
".py"
elif
type
in
json_objects
:
ext
=
".json"
else
:
logger
.
error
(
"Selected type is not valid: %s"
,
type
)
root
=
os
.
path
.
join
(
prefix
,
selected_type
)
object_path
=
os
.
path
.
join
(
root
,
name
+
ext
)
try
:
if
os
.
path
.
isfile
(
object_path
):
# check if editor set
if
editor
is
None
:
if
len
(
os
.
environ
[
'VISUAL'
])
>
0
:
editor
=
os
.
environ
[
'VISUAL'
]
elif
len
(
os
.
environ
[
'EDITOR'
])
>
0
:
editor
=
os
.
environ
[
'EDITOR'
]
else
:
logger
.
error
(
"No default editor set in your environment variable"
)
return
1
logger
.
info
(
"Editing object of type '%s' and name '%s'"
,
selected_type
,
name
)
cmd
=
"%s %s"
%
(
editor
,
object_path
)
os
.
system
(
cmd
)
else
:
logger
.
error
(
"Not a valid file: %s"
,
object_path
)
return
1
except
:
logger
.
error
(
"File does not exist: %s"
,
object_path
)
return
1
return
0
def
make_webapi
(
c
):
'''Instantiates an usable web-api proxy using the command-line configuration
...
...
beat/cmdline/config.py
View file @
5124609c
...
...
@@ -82,6 +82,7 @@ DEFAULTS = {
'token'
:
None
,
'prefix'
:
os
.
path
.
realpath
(
os
.
path
.
join
(
os
.
curdir
,
'prefix'
)),
'cache'
:
'cache'
,
'editor'
:
None
,
}
"""Default values for the command-line utility"""
...
...
@@ -92,6 +93,7 @@ DOC = {
'token'
:
'Secret key of the user on the BEAT platform'
,
'prefix'
:
'Directory containing BEAT objects'
,
'cache'
:
'Directory to use for data caching (relative to prefix)'
,
'editor'
:
'Editor to be used to edit local files'
,
}
"""Documentation for configuration parameters"""
...
...
beat/cmdline/databases.py
View file @
5124609c
...
...
@@ -29,6 +29,7 @@
"""Usage:
%(prog)s databases list [--remote]
%(prog)s databases path [<name>]...
%(prog)s databases edit <name>...
%(prog)s databases check [<name>]...
%(prog)s databases pull [--force] [<name>]...
%(prog)s databases push [--force] [--dry-run] [<name>]...
...
...
@@ -48,6 +49,7 @@ Arguments:
Commands:
list Lists all the databases available on the platform
path Displays local path of databases files
edit Edit local database file
check Checks a local database for validity
pull Downloads the specified databases from the server
push Uploads databases to the server (must provide a valid admin token)
...
...
@@ -645,6 +647,9 @@ def process(args):
elif
args
[
'path'
]:
return
common
.
display_local_path
(
configuration
.
path
,
'database'
,
db_names
)
elif
args
[
'edit'
]:
return
common
.
edit_local_file
(
configuration
.
path
,
configuration
.
editor
,
'database'
,
db_names
[
0
])
elif
args
[
'check'
]:
return
common
.
check
(
configuration
.
path
,
'database'
,
db_names
)
...
...
beat/cmdline/dataformats.py
View file @
5124609c
...
...
@@ -29,6 +29,7 @@
"""Usage:
%(prog)s dataformats list [--remote]
%(prog)s dataformats path [<name>]...
%(prog)s dataformats edit <name>...
%(prog)s dataformats check [<name>]...
%(prog)s dataformats pull [--force] [<name>]...
%(prog)s dataformats push [--force] [--dry-run] [<name>]...
...
...
@@ -44,6 +45,7 @@
Commands:
list Lists all the dataformats available on the platform
path Displays local path of dataformats files
edit Edit local dataformat file
check Checks a local dataformat for validity
pull Downloads the specified dataformats from the server
push Uploads dataformats to the server
...
...
@@ -156,6 +158,9 @@ def process(args):
elif
args
[
'path'
]:
return
common
.
display_local_path
(
args
[
'config'
].
path
,
'dataformat'
,
args
[
'<name>'
])
elif
args
[
'edit'
]:
return
common
.
edit_local_file
(
args
[
'config'
].
path
,
args
[
'config'
].
editor
,
'dataformat'
,
args
[
'<name>'
][
0
])
elif
args
[
'check'
]:
return
common
.
check
(
args
[
'config'
].
path
,
'dataformat'
,
args
[
'<name>'
])
...
...
beat/cmdline/experiments.py
View file @
5124609c
...
...
@@ -32,6 +32,7 @@
%(prog)s experiments list [--remote]
%(prog)s experiments check [<name>]...
%(prog)s experiments path [<name>]...
%(prog)s experiments edit <name>...
%(prog)s experiments pull [--force] [<name>]...
%(prog)s experiments push [--force] [--dry-run] [<name>]...
%(prog)s experiments diff <name>
...
...
@@ -48,6 +49,7 @@ Commands:
caches Lists all cache files used by this experiment
list Lists all the experiments available on the platform
path Displays local path of experiments files
edit Edit local experiment file
check Checks a local experiment for validity
pull Downloads the specified experiments from the server
push Uploads experiments to the server
...
...
@@ -603,6 +605,9 @@ def process(args):
elif
args
[
'path'
]:
return
common
.
display_local_path
(
config
.
path
,
'experiment'
,
names
)
elif
args
[
'edit'
]:
return
common
.
edit_local_file
(
config
.
path
,
config
.
editor
,
'experiment'
,
names
[
0
])
elif
args
[
'check'
]:
return
common
.
check
(
config
.
path
,
'experiment'
,
names
)
...
...
beat/cmdline/libraries.py
View file @
5124609c
...
...
@@ -29,6 +29,7 @@
"""Usage:
%(prog)s libraries list [--remote]
%(prog)s libraries path [<name>]...
%(prog)s libraries edit <name>...
%(prog)s libraries check [<name>]...
%(prog)s libraries pull [--force] [<name>]...
%(prog)s libraries push [--force] [--dry-run] [<name>]...
...
...
@@ -44,6 +45,7 @@
Commands:
list Lists all the libraries available on the platform
path Displays local path of libraries files
edit Edit local library file
check Checks a local library for validity
pull Downloads the specified libraries from the server
push Uploads libraries to the server
...
...
@@ -151,6 +153,9 @@ def process(args):
elif
args
[
'path'
]:
return
common
.
display_local_path
(
args
[
'config'
].
path
,
'library'
,
args
[
'<name>'
])
elif
args
[
'edit'
]:
return
common
.
edit_local_file
(
args
[
'config'
].
path
,
args
[
'config'
].
editor
,
'library'
,
args
[
'<name>'
][
0
])
elif
args
[
'check'
]:
return
common
.
check
(
args
[
'config'
].
path
,
'library'
,
args
[
'<name>'
])
...
...
beat/cmdline/plotterparameters.py
View file @
5124609c
...
...
@@ -29,6 +29,7 @@
"""Usage:
%(prog)s plotterparameters list [--remote]
%(prog)s plotterparameters path [<name>]...
%(prog)s plotterparameters edit <name>...
%(prog)s plotterparameters check [<name>]...
%(prog)s plotterparameters pull [--force] [<name>]...
%(prog)s plotterparameters create <name>...
...
...
@@ -41,6 +42,7 @@
Commands:
list Lists all the plotterparameters available locally
path Displays local path of plotterparameters files
edit Edit local plotterparameter file
check Checks a local plotterparameter for validity
pull Downloads the specified plotterparameters from the server
create Creates a new local plotterparameter
...
...
@@ -118,6 +120,9 @@ def process(args):
elif
args
[
'path'
]:
return
common
.
display_local_path
(
args
[
'config'
].
path
,
'plotterparameter'
,
args
[
'<name>'
])
elif
args
[
'edit'
]:
return
common
.
edit_local_file
(
args
[
'config'
].
path
,
args
[
'config'
].
editor
,
'plotterparameter'
,
args
[
'<name>'
][
0
])
elif
args
[
'check'
]:
return
common
.
check
(
args
[
'config'
].
path
,
'plotterparameter'
,
args
[
'<name>'
])
...
...
beat/cmdline/plotters.py
View file @
5124609c
...
...
@@ -29,6 +29,7 @@
"""Usage:
%(prog)s plotters list [--remote]
%(prog)s plotters path [<name>]...
%(prog)s plotters edit <name>...
%(prog)s plotters check [<name>]...
%(prog)s plotters pull [--force] [<name>]...
%(prog)s plotters plot [--show] [--force] [--sample_data] [--inputdata=<filename.json>] [--outputimage=<filename.png>] [--plotterparameter=<plotterparameter>] [<name>]...
...
...
@@ -42,6 +43,7 @@
Commands:
list Lists all the plotters available locally
path Displays local path of plotters files
edit Edit local plotter file
check Checks a local plotter for validity
pull Downloads the specified plotters from the server
plot Plots an image
...
...
@@ -283,6 +285,9 @@ def process(args):
elif
args
[
'path'
]:
return
common
.
display_local_path
(
args
[
'config'
].
path
,
'plotter'
,
args
[
'<name>'
])
elif
args
[
'edit'
]:
return
common
.
edit_local_file
(
args
[
'config'
].
path
,
args
[
'config'
].
editor
,
'plotter'
,
args
[
'<name>'
][
0
])
elif
args
[
'check'
]:
return
common
.
check
(
args
[
'config'
].
path
,
'plotter'
,
args
[
'<name>'
])
...
...
beat/cmdline/scripts/beat.py
View file @
5124609c
...
...
@@ -30,7 +30,7 @@
Usage:
%(prog)s [--verbose ...] [--prefix=<path>] [--cache=<path>] [--user=<user>]
[--platform=<url>] [--token=<token>]
[--platform=<url>] [--token=<token>]
[--editor=<editor>]
[--test-mode] <command> [<args>...]
%(prog)s (--help | -h)
%(prog)s (--version | -V)
...
...
@@ -49,6 +49,9 @@ Options:
-t, --token=<token> Overrides the user token for server operations. If not
set, use the value from your RC file. There are no
defaults for this option.
-e, --editor=<editor> Overrides the user editor to edit local files. If not
set, use the value from your environment. There are no
defaults for this option.
-u, --user=<user> Overrides the user name on the remote platform. If not
set, use the value from your RC file.
[default: %(user)s]
...
...
beat/cmdline/test/test_config.py
View file @
5124609c
...
...
@@ -38,6 +38,7 @@ from . import tmp_prefix, temp_cwd
from
..scripts.beat
import
main
from
beat.core.test.utils
import
cleanup
from
..
import
config
from
..
import
common
def
call
(
*
args
,
**
kwargs
):
...
...
@@ -136,3 +137,101 @@ def test_get_bad_config_key():
@
nose
.
tools
.
with_setup
(
teardown
=
cleanup
)
def
test_get_token
():
nose
.
tools
.
eq_
(
call
(
'config'
,
'get'
,
'token'
),
0
)
@
nose
.
tools
.
with_setup
(
teardown
=
cleanup
)
def
test_get_editor
():
nose
.
tools
.
eq_
(
call
(
'config'
,
'get'
,
'editor'
),
0
)
@
nose
.
tools
.
with_setup
(
teardown
=
cleanup
)
def
test_set_local_editor
():
editor_value
=
'editor'
with
temp_cwd
()
as
d
:
nose
.
tools
.
eq_
(
call
(
'config'
,
'set'
,
'--local'
,
'editor'
,
editor_value
),
0
)
config
=
os
.
path
.
join
(
d
,
'.beatrc'
)
assert
os
.
path
.
exists
(
config
)
with
open
(
config
,
'rt'
)
as
f
:
contents
=
simplejson
.
load
(
f
)
assert
contents
[
'editor'
]
==
editor_value
def
create_touch_file
(
tmp_prefix
,
editor
):
cmd
=
"%s %s && %s %s"
%
(
'mkdir -p'
,
os
.
path
.
join
(
tmp_prefix
,
'plotters'
),
'touch'
,
os
.
path
.
join
(
tmp_prefix
,
'plotters'
,
'test.py'
))
os
.
system
(
cmd
)
result
=
common
.
edit_local_file
(
tmp_prefix
,
editor
,
'plotter'
,
"test"
)
return
result
def
read_data
(
tmp_prefix
):
with
open
(
os
.
path
.
join
(
tmp_prefix
,
'plotters'
,
'test.py'
),
'r'
)
as
f
:
read_data
=
f
.
read
().
split
(
'
\n
'
)[
0
]
f
.
closed
return
read_data
def
clean_tmp_files
(
tmp_prefix
):
cmd
=
"%s %s"
%
(
'rm -fr'
,
os
.
path
.
join
(
tmp_prefix
,
'plotters'
))
os
.
system
(
cmd
)
@
nose
.
tools
.
with_setup
(
teardown
=
cleanup
)
def
test_check_editor_system_no_editor_set
():
editor
=
None
os
.
environ
[
'VISUAL'
]
=
''
os
.
environ
[
'EDITOR'
]
=
''
result
=
create_touch_file
(
tmp_prefix
,
editor
)
assert
result
==
1
data
=
read_data
(
tmp_prefix
)
assert
len
(
data
)
==
0
clean_tmp_files
(
tmp_prefix
)
@
nose
.
tools
.
with_setup
(
teardown
=
cleanup
)
def
test_check_editor_system_no_local_editor
():
editor
=
None
os
.
environ
[
'VISUAL'
]
=
'echo "2" >'
os
.
environ
[
'EDITOR'
]
=
'echo "3" >'
result
=
create_touch_file
(
tmp_prefix
,
editor
)
assert
result
==
0
data
=
read_data
(
tmp_prefix
)
assert
len
(
data
)
==
1
assert
data
==
"2"
clean_tmp_files
(
tmp_prefix
)
@
nose
.
tools
.
with_setup
(
teardown
=
cleanup
)
def
test_check_editor_system_local_editor_set
():
editor
=
'echo "1" >'
os
.
environ
[
'VISUAL'
]
=
'echo "2" >'
os
.
environ
[
'EDITOR'
]
=
'echo "3" >'
result
=
create_touch_file
(
tmp_prefix
,
editor
)
assert
result
==
0
data
=
read_data
(
tmp_prefix
)
assert
len
(
data
)
==
1
assert
data
==
"1"
clean_tmp_files
(
tmp_prefix
)
@
nose
.
tools
.
with_setup
(
teardown
=
cleanup
)
def
test_check_editor_system_no_local_editor_no_visual
():
editor
=
None
os
.
environ
[
'VISUAL'
]
=
''
os
.
environ
[
'EDITOR'
]
=
'echo "3" >'
result
=
create_touch_file
(
tmp_prefix
,
editor
)
assert
result
==
0
data
=
read_data
(
tmp_prefix
)
assert
len
(
data
)
==
1
assert
data
==
"3"
clean_tmp_files
(
tmp_prefix
)
beat/cmdline/toolchains.py
View file @
5124609c
...
...
@@ -29,6 +29,7 @@
"""Usage:
%(prog)s toolchains list [--remote]
%(prog)s toolchains path [<name>]...
%(prog)s toolchains edit <name>...
%(prog)s toolchains check [<name>]...
%(prog)s toolchains pull [--force] [<name>]...
%(prog)s toolchains push [--force] [--dry-run] [<name>]...
...
...
@@ -45,6 +46,7 @@
Commands:
list Lists all the toolchains available on the platform
path Displays local path of toolchains files
edit Edit local toolchain file
check Checks a local toolchain for validity
pull Downloads the specified toolchains from the server
push Uploads toolchains to the server
...
...
@@ -81,6 +83,9 @@ def process(args):
elif
args
[
'path'
]:
return
common
.
display_local_path
(
args
[
'config'
].
path
,
'toolchain'
,
args
[
'<name>'
])
elif
args
[
'edit'
]:
return
common
.
edit_local_file
(
args
[
'config'
].
path
,
args
[
'config'
].
editor
,
'toolchain'
,
args
[
'<name>'
][
0
])
elif
args
[
'check'
]:
return
common
.
check
(
args
[
'config'
].
path
,
'toolchain'
,
args
[
'<name>'
])
...
...
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