Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
beat.backend.python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
beat
beat.backend.python
Commits
b7abdaff
Commit
b7abdaff
authored
6 years ago
by
Flavio TARSETTI
Browse files
Options
Downloads
Plain Diff
Merge branch '23_clean_storage_classes' into 'master'
Create a base class for Storage and CodeStorage Closes
#23
See merge request
!47
parents
49181315
b81b23ae
No related branches found
No related tags found
1 merge request
!47
Create a base class for Storage and CodeStorage
Pipeline
#30009
passed
6 years ago
Stage: build
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
beat/backend/python/utils.py
+51
-25
51 additions, 25 deletions
beat/backend/python/utils.py
with
51 additions
and
25 deletions
beat/backend/python/utils.py
+
51
−
25
View file @
b7abdaff
...
...
@@ -216,8 +216,7 @@ class File(object):
# ----------------------------------------------------------
class
Storage
(
object
):
"""
Resolves paths for objects that provide only a description
"""
class
AbstractStorage
(
object
):
asset_type
=
None
asset_folder
=
None
...
...
@@ -233,37 +232,64 @@ class Storage(object):
self
.
json
=
File
(
self
.
path
+
"
.json
"
)
self
.
doc
=
File
(
self
.
path
+
"
.rst
"
)
def
hash
(
self
,
description
=
"
description
"
):
"""
The 64-character hash of the database declaration JSON
"""
return
hash
.
hashJSONFile
(
self
.
json
.
path
,
description
)
def
exists
(
self
):
"""
If the database declaration file exists
"""
return
self
.
json
.
exists
()
def
remove
(
self
):
"""
Removes the object from the disk
"""
self
.
json
.
remove
()
self
.
doc
.
remove
()
def
hash
(
self
):
"""
The 64-character hash of the database declaration JSON
"""
raise
NotImplementedError
def
load
(
self
):
"""
Loads the JSON declaration as a file
"""
raise
NotImplementedError
def
save
(
self
):
"""
Saves the JSON declaration as files
"""
raise
NotImplementedError
class
Storage
(
AbstractStorage
):
"""
Resolves paths for objects that provide only a description
"""
def
__init__
(
self
,
path
):
super
(
Storage
,
self
).
__init__
(
path
)
def
hash
(
self
,
description
=
"
description
"
):
"""
Re-imp
"""
return
hash
.
hashJSONFile
(
self
.
json
.
path
,
description
)
def
load
(
self
):
"""
Re-imp
"""
tp
=
collections
.
namedtuple
(
"
Storage
"
,
[
"
declaration
"
,
"
description
"
])
return
tp
(
self
.
json
.
load
(),
self
.
doc
.
try_load
())
def
save
(
self
,
declaration
,
description
=
None
):
"""
Saves the JSON declaration as files
"""
"""
Re-imp
"""
if
description
:
self
.
doc
.
save
(
description
.
encode
(
"
utf8
"
))
if
not
isinstance
(
declaration
,
six
.
string_types
):
declaration
=
simplejson
.
dumps
(
declaration
,
indent
=
4
)
self
.
json
.
save
(
declaration
)
def
remove
(
self
):
"""
Removes the object from the disk
"""
self
.
json
.
remove
()
self
.
doc
.
remove
()
# ----------------------------------------------------------
class
CodeStorage
(
object
):
class
CodeStorage
(
AbstractStorage
):
"""
Resolves paths for objects that provide a description and code
Parameters:
...
...
@@ -273,10 +299,7 @@ class CodeStorage(object):
"""
def
__init__
(
self
,
path
,
language
=
None
):
self
.
path
=
path
self
.
json
=
File
(
self
.
path
+
"
.json
"
)
self
.
doc
=
File
(
self
.
path
+
"
.rst
"
)
super
(
CodeStorage
,
self
).
__init__
(
path
)
self
.
_language
=
language
or
self
.
__auto_discover_language
()
self
.
code
=
File
(
...
...
@@ -304,7 +327,7 @@ class CodeStorage(object):
)
def
hash
(
self
):
"""
The 64-character hash of the database declaration JSON
"""
"""
Re-imp
"""
if
self
.
code
.
exists
():
return
hash
.
hash
(
...
...
@@ -319,18 +342,21 @@ class CodeStorage(object):
)
def
exists
(
self
):
"""
If the database declaration file exists
"""
return
self
.
json
.
exists
()
and
self
.
code
.
exists
()
"""
Re-imp
"""
return
super
(
CodeStorage
,
self
).
exists
()
and
self
.
code
.
exists
()
def
load
(
self
):
"""
Loads the JSON declaration as a file
"""
"""
Re-imp
"""
tp
=
collections
.
namedtuple
(
"
CodeStorage
"
,
[
"
declaration
"
,
"
code
"
,
"
description
"
]
)
return
tp
(
self
.
json
.
load
(),
self
.
code
.
try_load
(),
self
.
doc
.
try_load
())
def
save
(
self
,
declaration
,
code
=
None
,
description
=
None
):
"""
Saves the JSON declaration and the code as files
"""
"""
Re-imp
"""
if
description
:
self
.
doc
.
save
(
description
.
encode
(
"
utf8
"
))
...
...
@@ -344,9 +370,9 @@ class CodeStorage(object):
self
.
code
.
save
(
code
)
def
remove
(
self
):
"""
Re
moves the object from the disk
"""
self
.
json
.
remove
()
s
elf
.
doc
.
remove
()
"""
Re
-imp
"""
s
uper
(
CodeStorage
,
self
)
.
remove
()
self
.
code
.
remove
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment