Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ML
lib
Binary Storage
Commits
7c91d2e8
Commit
7c91d2e8
authored
Apr 08, 2020
by
Sasha Z
Browse files
Reorg for packaging
parent
ea90038e
Changes
4
Hide whitespace changes
Inline
Side-by-side
py/README.md
0 → 100644
View file @
7c91d2e8
# SNS RAD
Currently only reading of binary files is implemented.
\ No newline at end of file
py/read_binary.py
deleted
100644 → 0
View file @
ea90038e
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 27 16:11:06 2020
@author: az9
"""
from
sns_rad.binary
import
ReadStorage
import
argparse
from
argparse
import
RawTextHelpFormatter
epilog_text
=
'''
Examples:
python read_file.py filename
# will read and print out all records from <filename>
python read_file.py -i n1 -i n2 filename
# will read and print out records with indices n1 and n2 from <filename>
'''
parser
=
argparse
.
ArgumentParser
(
epilog
=
epilog_text
,
formatter_class
=
RawTextHelpFormatter
)
parser
.
add_argument
(
'--index'
,
'-i'
,
action
=
'append'
,
default
=
[],
type
=
int
,
help
=
'indices of records to read'
)
parser
.
add_argument
(
'file'
,
help
=
'file to read'
)
args
=
parser
.
parse_args
()
file
=
ReadStorage
(
args
.
file
)
print
(
args
.
file
,
'has'
,
len
(
file
),
'records'
)
def
show
(
record
):
if
'value'
in
record
:
value
=
record
[
'value'
]
# if isinstance(value,(str,list,tuple)):
if
hasattr
(
value
,
'__len__'
)
and
len
(
value
)
>
4
:
record
[
'value'
]
=
[
value
[
0
],
value
[
1
],
'...'
,
value
[
len
(
value
)
-
1
]]
return
record
def
show2
(
record
):
return
str
(
record
[
'name'
])
+
' '
+
str
(
record
[
'timestamp'
])
if
not
args
.
index
:
for
record
in
file
:
print
(
show2
(
record
))
else
:
for
i
in
args
.
index
:
print
(
i
,
":"
,
show2
(
file
[
i
]))
file
.
close
()
py/setup.py
0 → 100644
View file @
7c91d2e8
import
setuptools
with
open
(
"README.md"
,
"r"
)
as
fh
:
long_description
=
fh
.
read
()
setuptools
.
setup
(
name
=
"sns_rad"
,
version
=
"0.0.1"
,
author
=
"Alexander Zhukov"
,
author_email
=
"zhukovap@ornl.gov"
,
description
=
"Package for code developed at SNS RAD."
,
long_description
=
long_description
,
long_description_content_type
=
"text/markdown"
,
url
=
"https://"
,
# scripts=['read_binary'],
entry_points
=
{
"console_scripts"
:
[
"read_binary = sns_rad.read_binary:main"
,
]},
packages
=
setuptools
.
find_packages
(),
classifiers
=
[
"Programming Language :: Python :: 3"
,
"License :: OSI Approved :: MIT License"
,
"Operating System :: OS Independent"
,
],
python_requires
=
'>=3.6'
,
)
\ No newline at end of file
py/sns_rad/read_binary.py
0 → 100644
View file @
7c91d2e8
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 27 16:11:06 2020
@author: az9
"""
from
sns_rad.binary
import
ReadStorage
import
argparse
from
argparse
import
RawTextHelpFormatter
def
main
():
epilog_text
=
'''
Examples:
python read_file.py filename
# will read and print out all records from <filename>
python read_file.py -i n1 -i n2 filename
# will read and print out records with indices n1 and n2 from <filename>
'''
parser
=
argparse
.
ArgumentParser
(
epilog
=
epilog_text
,
formatter_class
=
RawTextHelpFormatter
)
parser
.
add_argument
(
'--index'
,
'-i'
,
action
=
'append'
,
default
=
[],
type
=
int
,
help
=
'indices of records to read'
)
parser
.
add_argument
(
'file'
,
help
=
'file to read'
)
args
=
parser
.
parse_args
()
file
=
ReadStorage
(
args
.
file
)
print
(
args
.
file
,
'has'
,
len
(
file
),
'records'
)
def
show
(
record
):
if
'value'
in
record
:
value
=
record
[
'value'
]
# if isinstance(value,(str,list,tuple)):
if
hasattr
(
value
,
'__len__'
)
and
len
(
value
)
>
4
:
record
[
'value'
]
=
[
value
[
0
],
value
[
1
],
'...'
,
value
[
len
(
value
)
-
1
]]
return
record
def
show2
(
record
):
return
str
(
record
[
'name'
])
+
' '
+
str
(
record
[
'timestamp'
])
if
not
args
.
index
:
for
record
in
file
:
print
(
show2
(
record
))
else
:
for
i
in
args
.
index
:
print
(
i
,
":"
,
show2
(
file
[
i
]))
file
.
close
()
if
__name__
==
"__main__"
:
main
()
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