add possibily to upload radiosounding file send_rs_data

Wed, 08 Aug 2018 11:50:12 +0200

author
madrouin@astronotus.lmd.polytechnique.fr
date
Wed, 08 Aug 2018 11:50:12 +0200
branch
send_rs_data
changeset 20
111f05973553
parent 16
ddaea4327bd5
child 21
4fcec88bfe3d

add possibily to upload radiosounding file

scc_access/scc_access.py file | annotate | diff | comparison | revisions
--- a/scc_access/scc_access.py	Wed Jan 10 18:06:02 2018 +0200
+++ b/scc_access/scc_access.py	Wed Aug 08 11:50:12 2018 +0200
@@ -25,8 +25,8 @@
     """ A simple class that will attempt to upload a file on the SCC server.
 
     The uploading is done by simulating a normal browser session. In the current
-    version no check is performed, and no feedback is given if the upload 
-    was successful. If everything is setup correctly, it will work. 
+    version no check is performed, and no feedback is given if the upload
+    was successful. If everything is setup correctly, it will work.
     """
 
     def __init__(self, auth, output_dir, base_url):
@@ -63,7 +63,7 @@
             sys.exit(1)
 
         logger.debug("Submiting credentials.")
-        
+
         # Submit the login data
         login_submit = self.session.post(self.login_url,
                                          data=self.login_credentials,
@@ -76,8 +76,8 @@
     def logout(self):
         pass
 
-    def upload_file(self, filename, system_id):
-        """ Upload a filename for processing with a specific system. If the 
+    def upload_file(self, filename, system_id, rs_filename=None):
+        """ Upload a filename for processing with a specific system. If the
         upload is successful, it returns the measurement id. """
         # Get submit page
         upload_page = self.session.get(self.upload_url,
@@ -88,6 +88,9 @@
         upload_data = {'system': system_id}
         files = {'data': open(filename, 'rb')}
 
+        if rs_filename is not None:
+            files['sounding_file'] = open(rs_filename, 'rb')
+
         logger.info("Uploading of file %s started." % filename)
 
         upload_submit = self.session.post(self.upload_url,
@@ -114,7 +117,7 @@
 
     def download_files(self, measurement_id, subdir, download_url):
         """ Downloads some files from the download_url to the specified
-        subdir. This method is used to download preprocessed file, optical 
+        subdir. This method is used to download preprocessed file, optical
         files etc.
         """
         # Get the file
@@ -276,8 +279,8 @@
 
     def delete_measurement(self, measurement_id):
         """ Deletes a measurement with the provided measurement id. The user
-        should have the appropriate permissions. 
-        
+        should have the appropriate permissions.
+
         The procedures is performed directly through the web interface and
         NOT through the API.
         """
@@ -337,7 +340,7 @@
 
     def measurement_id_for_date(self, t1, call_sign='bu', base_number=0):
         """ Give the first available measurement id on the SCC for the specific
-        date. 
+        date.
         """
         date_str = t1.strftime('%Y%m%d')
         search_url = urlparse.urljoin(self.api_base_url, 'measurements/?id__startswith=%s' % date_str)
@@ -415,13 +418,13 @@
                                    self.processing)
 
 
-def upload_file(filename, system_id, settings):
+def upload_file(filename, system_id, settings, rs_filename=None):
     """ Shortcut function to upload a file to the SCC. """
     logger.info("Uploading file %s, using sytem %s" % (filename, system_id))
 
     scc = SCC(settings['basic_credentials'], settings['output_dir'], settings['base_url'])
     scc.login(settings['website_credentials'])
-    measurement_id = scc.upload_file(filename, system_id)
+    measurement_id = scc.upload_file(filename, system_id, rs_filename=rs_filename)
     scc.logout()
     return measurement_id
 
@@ -502,6 +505,9 @@
     parser.add_argument("--rerun-all", help="Measurement ID to rerun.")
     parser.add_argument("--rerun-processing", help="Measurement ID to rerun processing routines.")
 
+    # others files
+    parser.add_argument("--radiosounding", default=None, help="Radiosounding file name or path")
+
     # Verbosity settings from http://stackoverflow.com/a/20663028
     parser.add_argument('-d', '--debug', help="Print debugging information.", action="store_const",
                         dest="loglevel", const=logging.DEBUG, default=logging.INFO,
@@ -532,4 +538,4 @@
         if args.process:
             process_file(args.filename, args.system, settings)
         else:
-            upload_file(args.filename, args.system, settings)
+            upload_file(args.filename, args.system, settings, rs_filename=args.radiosounding)

mercurial