Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
tango
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LOFAR2.0
tango
Commits
83091a58
Commit
83091a58
authored
Dec 13, 2021
by
Stefano Di Frischia
Browse files
Options
Downloads
Patches
Plain Diff
L2SS-528
: remove duplicate code
parent
f0b982cb
No related branches found
No related tags found
1 merge request
!193
Resolve L2SS-528 "Timescaledb defaults"
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tangostationcontrol/tangostationcontrol/toolkit/archiver.py
+25
-21
25 additions, 21 deletions
tangostationcontrol/tangostationcontrol/toolkit/archiver.py
with
25 additions
and
21 deletions
tangostationcontrol/tangostationcontrol/toolkit/archiver.py
+
25
−
21
View file @
83091a58
...
@@ -42,6 +42,25 @@ def parse_device_name(device_name:str, tango_host:str = 'databaseds:10000'):
...
@@ -42,6 +42,25 @@ def parse_device_name(device_name:str, tango_host:str = 'databaseds:10000'):
else
:
else
:
raise
ValueError
(
f
'
{
device_name
}
is a wrong device name
'
)
raise
ValueError
(
f
'
{
device_name
}
is a wrong device name
'
)
def
split_tango_name
(
tango_fqname
:
str
,
tango_type
:
str
):
"""
Helper function to split device or attribute Tango full qualified names
into its components
"""
if
tango_type
.
lower
()
==
'
device
'
:
try
:
domain
,
family
,
member
=
tango_fqname
.
split
(
'
/
'
)
return
domain
,
family
,
member
except
:
raise
AttributeFormatException
(
f
"
Could not parse device name
{
tango_fqname
}
. Please provide FQDN, e.g. STAT/Device/1
"
)
elif
tango_type
.
lower
()
==
'
attribute
'
:
try
:
domain
,
family
,
member
,
name
=
tango_fqname
.
split
(
'
/
'
)
return
domain
,
family
,
member
,
name
except
:
raise
AttributeFormatException
(
f
"
Could not parse attribute name
{
tango_fqname
}
. Please provide FQDN, e.g. STAT/Device/1/Attribute
"
)
else
:
raise
ValueError
(
f
"
Invalid value:
{
tango_type
}
. Please set
'
device
'
or
'
attribute
'"
)
class
Archiver
():
class
Archiver
():
"""
"""
...
@@ -528,10 +547,7 @@ class Retriever():
...
@@ -528,10 +547,7 @@ class Retriever():
"""
"""
Takes as input the fully-qualified name of a device and returns a list of its archived attributes
Takes as input the fully-qualified name of a device and returns a list of its archived attributes
"""
"""
try
:
domain
,
family
,
member
=
split_tango_name
(
device_fqname
,
"
device
"
)
domain
,
family
,
member
=
device_fqname
.
split
(
'
/
'
)
except
:
raise
AttributeFormatException
(
f
"
Could not parse device name
{
device_fqname
}
. Please provide FQDN, e.g. STAT/Device/1
"
)
attrs
=
self
.
session
.
query
(
self
.
ab
.
Attribute
).
filter
(
and_
(
self
.
ab
.
Attribute
.
domain
==
domain
,
self
.
ab
.
Attribute
.
family
==
family
,
\
attrs
=
self
.
session
.
query
(
self
.
ab
.
Attribute
).
filter
(
and_
(
self
.
ab
.
Attribute
.
domain
==
domain
,
self
.
ab
.
Attribute
.
family
==
family
,
\
self
.
ab
.
Attribute
.
member
==
member
)).
all
()
self
.
ab
.
Attribute
.
member
==
member
)).
all
()
# Returns the representation as set in __repr__ method of the mapper class
# Returns the representation as set in __repr__ method of the mapper class
...
@@ -541,10 +557,7 @@ class Retriever():
...
@@ -541,10 +557,7 @@ class Retriever():
"""
"""
Takes as input the fully-qualified name of an attribute and returns its id.
Takes as input the fully-qualified name of an attribute and returns its id.
"""
"""
try
:
domain
,
family
,
member
,
name
=
split_tango_name
(
attribute_fqname
,
"
attribute
"
)
domain
,
family
,
member
,
name
=
attribute_fqname
.
split
(
'
/
'
)
except
:
raise
AttributeFormatException
(
f
"
Could not parse attribute name
{
attribute_fqname
}
. Please provide FQDN, e.g. STAT/Device/1/Attribute
"
)
try
:
try
:
result
=
self
.
session
.
query
(
self
.
ab
.
Attribute
.
att_conf_id
).
filter
(
and_
(
self
.
ab
.
Attribute
.
domain
==
domain
,
self
.
ab
.
Attribute
.
family
==
family
,
\
result
=
self
.
session
.
query
(
self
.
ab
.
Attribute
.
att_conf_id
).
filter
(
and_
(
self
.
ab
.
Attribute
.
domain
==
domain
,
self
.
ab
.
Attribute
.
family
==
family
,
\
self
.
ab
.
Attribute
.
member
==
member
,
self
.
ab
.
Attribute
.
name
==
name
)).
one
()
self
.
ab
.
Attribute
.
member
==
member
,
self
.
ab
.
Attribute
.
name
==
name
)).
one
()
...
@@ -560,10 +573,7 @@ class Retriever():
...
@@ -560,10 +573,7 @@ class Retriever():
Data Type name indicates the type (e.g. string, int, ...) and the read/write property. The name is used
Data Type name indicates the type (e.g. string, int, ...) and the read/write property. The name is used
as DB table name suffix in which values are stored.
as DB table name suffix in which values are stored.
"""
"""
try
:
domain
,
family
,
member
,
name
=
split_tango_name
(
attribute_fqname
,
"
attribute
"
)
domain
,
family
,
member
,
name
=
attribute_fqname
.
split
(
'
/
'
)
except
:
raise
AttributeFormatException
(
f
"
Could not parse attribute name
{
attribute_fqname
}
. Please provide FQDN, e.g. STAT/Device/1/Attribute
"
)
try
:
try
:
if
self
.
dbms
==
'
mysql
'
:
if
self
.
dbms
==
'
mysql
'
:
result
=
self
.
session
.
query
(
self
.
ab
.
DataType
.
data_type
).
join
(
self
.
ab
.
Attribute
,
self
.
ab
.
Attribute
.
att_conf_data_type_id
==
self
.
ab
.
DataType
.
att_conf_data_type_id
).
\
result
=
self
.
session
.
query
(
self
.
ab
.
DataType
.
data_type
).
join
(
self
.
ab
.
Attribute
,
self
.
ab
.
Attribute
.
att_conf_data_type_id
==
self
.
ab
.
DataType
.
att_conf_data_type_id
).
\
...
@@ -583,10 +593,7 @@ class Retriever():
...
@@ -583,10 +593,7 @@ class Retriever():
Formats are basically three: Scalar, Spectrum and Image.
Formats are basically three: Scalar, Spectrum and Image.
* Works only for POSTGRESQL *
* Works only for POSTGRESQL *
"""
"""
try
:
domain
,
family
,
member
,
name
=
split_tango_name
(
attribute_fqname
,
"
attribute
"
)
domain
,
family
,
member
,
name
=
attribute_fqname
.
split
(
'
/
'
)
except
:
raise
AttributeFormatException
(
f
"
Could not parse attribute name
{
attribute_fqname
}
. Please provide FQDN, e.g. STAT/Device/1/Attribute
"
)
try
:
try
:
result
=
self
.
session
.
query
(
self
.
ab
.
Format
.
format
).
join
(
self
.
ab
.
Attribute
,
self
.
ab
.
Attribute
.
att_conf_format_id
==
self
.
ab
.
Format
.
att_conf_format_id
).
\
result
=
self
.
session
.
query
(
self
.
ab
.
Format
.
format
).
join
(
self
.
ab
.
Attribute
,
self
.
ab
.
Attribute
.
att_conf_format_id
==
self
.
ab
.
Format
.
att_conf_format_id
).
\
filter
(
and_
(
self
.
ab
.
Attribute
.
domain
==
domain
,
self
.
ab
.
Attribute
.
family
==
family
,
self
.
ab
.
Attribute
.
member
==
member
,
self
.
ab
.
Attribute
.
name
==
name
)).
one
()
filter
(
and_
(
self
.
ab
.
Attribute
.
domain
==
domain
,
self
.
ab
.
Attribute
.
family
==
family
,
self
.
ab
.
Attribute
.
member
==
member
,
self
.
ab
.
Attribute
.
name
==
name
)).
one
()
...
@@ -597,10 +604,7 @@ class Retriever():
...
@@ -597,10 +604,7 @@ class Retriever():
raise
Exception
(
f
"
No records of attribute
{
attribute_fqname
}
found in DB
"
)
from
e
raise
Exception
(
f
"
No records of attribute
{
attribute_fqname
}
found in DB
"
)
from
e
def
get_attribute_tablename
(
self
,
attribute_fqname
:
str
):
def
get_attribute_tablename
(
self
,
attribute_fqname
:
str
):
try
:
domain
,
family
,
member
,
name
=
split_tango_name
(
attribute_fqname
,
"
attribute
"
)
[
domain
,
family
,
member
,
name
]
=
attribute_fqname
.
split
(
'
/
'
)
except
:
raise
AttributeFormatException
(
f
"
Could not parse attribute name
{
attribute_fqname
}
. Please provide FQDN, e.g. STAT/Device/1/Attribute
"
)
try
:
try
:
result
=
self
.
session
.
query
(
self
.
ab
.
Attribute
.
table_name
).
filter
(
and_
(
self
.
ab
.
Attribute
.
domain
==
domain
,
self
.
ab
.
Attribute
.
family
==
family
,
\
result
=
self
.
session
.
query
(
self
.
ab
.
Attribute
.
table_name
).
filter
(
and_
(
self
.
ab
.
Attribute
.
domain
==
domain
,
self
.
ab
.
Attribute
.
family
==
family
,
\
self
.
ab
.
Attribute
.
member
==
member
,
self
.
ab
.
Attribute
.
name
==
name
)).
one
()
self
.
ab
.
Attribute
.
member
==
member
,
self
.
ab
.
Attribute
.
name
==
name
)).
one
()
...
...
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