X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FNBI.git;a=blobdiff_plain;f=osm_nbi%2Ftests%2Fupload.py;h=dfd73020213480ca39b47c3253d4b6aa18c2f475;hp=742f973fb1d5e0709703f6722d0c8849ca2dd0b5;hb=5758955b7b394517ff5caf5506a4400cdc5aa372;hpb=e128118419c3bb413de4cff8445b9b6c5598a5ed diff --git a/osm_nbi/tests/upload.py b/osm_nbi/tests/upload.py index 742f973..dfd7302 100755 --- a/osm_nbi/tests/upload.py +++ b/osm_nbi/tests/upload.py @@ -1,6 +1,19 @@ #! /usr/bin/python3 # -*- coding: utf-8 -*- +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import getopt import sys import requests @@ -28,8 +41,11 @@ def usage(): if __name__ == "__main__": try: # load parameters and configuration - opts, args = getopt.getopt(sys.argv[1:], "hvu:s:f:t:", - ["url=", "help", "version", "verbose", "file=", "chunk-size=", "token="]) + opts, args = getopt.getopt( + sys.argv[1:], + "hvu:s:f:t:", + ["url=", "help", "version", "verbose", "file=", "chunk-size=", "token="], + ) url = None chunk_size = 500 pkg_file = None @@ -38,7 +54,7 @@ if __name__ == "__main__": for o, a in opts: if o == "--version": - print("upload version " + __version__ + ' ' + version_date) + print("upload version " + __version__ + " " + version_date) sys.exit() elif o in ("-v", "--verbose"): verbose += 1 @@ -59,7 +75,7 @@ if __name__ == "__main__": index = 0 transaction_id = None file_md5 = md5() - with open(pkg_file, 'rb') as f: + with open(pkg_file, "rb") as f: headers = { "Content-type": "application/gzip", "Content-Filename": basename(pkg_file), @@ -74,10 +90,12 @@ if __name__ == "__main__": # "chunk_size": chunk_size} if transaction_id: headers["Transaction-Id"] = transaction_id - if index+len(chunk_data) == total_size: + if index + len(chunk_data) == total_size: headers["Content-File-MD5"] = file_md5.hexdigest() # payload["id"] = transaction_id - headers["Content-range"] = "bytes {}-{}/{}".format(index, index+len(chunk_data)-1, total_size) + headers["Content-range"] = "bytes {}-{}/{}".format( + index, index + len(chunk_data) - 1, total_size + ) # refers to rfc2616: https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html if verbose: print("TX chunk Headers: {}".format(headers)) @@ -95,5 +113,5 @@ if __name__ == "__main__": print("RX {}: {}".format(r.status_code, r.text)) if "id" in response: print("---\nid: {}".format(response["id"])) - except Exception as e: + except Exception: raise