dexter has uploaded this change for review. (
https://gerrit.osmocom.org/c/pysim/+/39859?usp=email )
Change subject: saip-tool: add function to write PE sequence
......................................................................
saip-tool: add function to write PE sequence
To prevent code duplication and to make the implementation simpler,
let's add a function that takes care of writing the PE sequnece
to an output file.
Change-Id: I38733422270f5b9c18187b7f247b84bf21f9121b
---
M contrib/saip-tool.py
1 file changed, 8 insertions(+), 6 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/59/39859/1
diff --git a/contrib/saip-tool.py b/contrib/saip-tool.py
index 763e18d..b7282bd 100755
--- a/contrib/saip-tool.py
+++ b/contrib/saip-tool.py
@@ -65,6 +65,12 @@
parser_info = subparsers.add_parser('tree', help='Display the filesystem
tree')
+def write_pes(pes: ProfileElementSequence, output_file:str):
+ """write the PE sequence to a file"""
+ print("Writing %u PEs to file '%s'..." % (len(pes.pe_list),
output_file))
+ with open(output_file, 'wb') as f:
+ f.write(pes.to_der())
+
def do_split(pes: ProfileElementSequence, opts):
i = 0
for pe in pes.pe_list:
@@ -132,9 +138,7 @@
pes.pe_list = new_pe_list
pes._process_pelist()
- print("Writing %u PEs to file '%s'..." % (len(pes.pe_list),
opts.output_file))
- with open(opts.output_file, 'wb') as f:
- f.write(pes.to_der())
+ write_pes(pes, opts.output_file)
def do_remove_naa(pes: ProfileElementSequence, opts):
if not opts.naa_type in NAAs:
@@ -142,9 +146,7 @@
naa = NAAs[opts.naa_type]
print("Removing NAAs of type '%s' from Sequence..." %
opts.naa_type)
pes.remove_naas_of_type(naa)
- print("Writing %u PEs to file '%s'..." % (len(pes.pe_list),
opts.output_file))
- with open(opts.output_file, 'wb') as f:
- f.write(pes.to_der())
+ write_pes(pes, opts.output_file)
def do_info(pes: ProfileElementSequence, opts):
def get_naa_count(pes: ProfileElementSequence) -> dict:
--
To view, visit
https://gerrit.osmocom.org/c/pysim/+/39859?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I38733422270f5b9c18187b7f247b84bf21f9121b
Gerrit-Change-Number: 39859
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>