Commit 58ac71c87eda83ea394ab94a26e615c3d9878910
1 parent
48060122
Adapt to new GFilename interface.
Showing
2 changed files
with
36 additions
and
24 deletions
cscripts/csfindobs.py
| @@ -288,11 +288,11 @@ class csfindobs(ctools.cscript): | @@ -288,11 +288,11 @@ class csfindobs(ctools.cscript): | ||
| 288 | 288 | ||
| 289 | # Check for clobber | 289 | # Check for clobber |
| 290 | if outfile.exists() and not self.clobber(): | 290 | if outfile.exists() and not self.clobber(): |
| 291 | - self.log("File "+outfile.url()+" already exists. Set clobber=yes to overwrite file") | 291 | + self.log("File "+outfile+" already exists. Set clobber=yes to overwrite file") |
| 292 | self.log("\n") | 292 | self.log("\n") |
| 293 | else: | 293 | else: |
| 294 | # Write runs to file | 294 | # Write runs to file |
| 295 | - f = open(outfile.url(),"w") | 295 | + f = open(repr(outfile),"w") |
| 296 | for run in self.runs: | 296 | for run in self.runs: |
| 297 | f.write(str(run)+" \n") | 297 | f.write(str(run)+" \n") |
| 298 | f.close() | 298 | f.close() |
cscripts/csiactcopy.py
| @@ -82,7 +82,7 @@ class csiactcopy(ctools.cscript): | @@ -82,7 +82,7 @@ class csiactcopy(ctools.cscript): | ||
| 82 | pars = gammalib.GApplicationPars(parfile) | 82 | pars = gammalib.GApplicationPars(parfile) |
| 83 | except: | 83 | except: |
| 84 | # Signal if parfile was not found | 84 | # Signal if parfile was not found |
| 85 | - sys.stdout.write("Parfile "+parfile+" not found. Create default parfile.\n") | 85 | + print("Parfile "+parfile+" not found. Create default parfile.") |
| 86 | 86 | ||
| 87 | # Create default parfile | 87 | # Create default parfile |
| 88 | pars = gammalib.GApplicationPars() | 88 | pars = gammalib.GApplicationPars() |
| @@ -105,7 +105,10 @@ class csiactcopy(ctools.cscript): | @@ -105,7 +105,10 @@ class csiactcopy(ctools.cscript): | ||
| 105 | # Get Parameters | 105 | # Get Parameters |
| 106 | self.m_remote_master = self["remote_master"].filename() | 106 | self.m_remote_master = self["remote_master"].filename() |
| 107 | if not self.m_remote_master.exists(): | 107 | if not self.m_remote_master.exists(): |
| 108 | - raise RuntimeError("*** ERROR: FITS data not available. No master index file found in \""+self.m_remote_master.url()+"\". Make sure remote file system is properly mounted") | 108 | + raise RuntimeError("*** ERROR: FITS data not available. No " |
| 109 | + "master index file found in \""+ | ||
| 110 | + self.m_remote_master+"\". Make sure remote " | ||
| 111 | + "file system is properly mounted.") | ||
| 109 | 112 | ||
| 110 | # Get parameters | 113 | # Get parameters |
| 111 | self.m_prodname = self["prodname"].string() | 114 | self.m_prodname = self["prodname"].string() |
| @@ -178,23 +181,28 @@ class csiactcopy(ctools.cscript): | @@ -178,23 +181,28 @@ class csiactcopy(ctools.cscript): | ||
| 178 | 181 | ||
| 179 | # Raise exception if file not valid | 182 | # Raise exception if file not valid |
| 180 | else: | 183 | else: |
| 181 | - raise RuntimeError("*** ERROR: Runlist file \""+self.m_runlist+"\" not available") | 184 | + raise RuntimeError("*** ERROR: Runlist file \""+ |
| 185 | + self.m_runlist+"\" not available.") | ||
| 182 | 186 | ||
| 183 | # Check for availability of remote master file | 187 | # Check for availability of remote master file |
| 184 | if not self.m_remote_master.exists(): | 188 | if not self.m_remote_master.exists(): |
| 185 | - raise RuntimeError("*** ERROR: Remote master file \""+self.m_remote_master.url()+"\" does not exist") | 189 | + raise RuntimeError("*** ERROR: Remote master file \""+ |
| 190 | + self.m_remote_master+"\" does not exist.") | ||
| 186 | 191 | ||
| 187 | # Retrieve json data from remote master | 192 | # Retrieve json data from remote master |
| 188 | json_data = open(self.m_remote_master.url()).read() | 193 | json_data = open(self.m_remote_master.url()).read() |
| 189 | data = json.loads(json_data) | 194 | data = json.loads(json_data) |
| 190 | if not "datasets" in data: | 195 | if not "datasets" in data: |
| 191 | - raise RuntimeError("*** ERROR: Key \"datasets\" not available in remote master index file \""+self.m_remote_master.url()+"\".") | 196 | + raise RuntimeError("*** ERROR: Key \"datasets\" not available " |
| 197 | + "in remote master index file \""+ | ||
| 198 | + self.m_remote_master+"\".") | ||
| 192 | 199 | ||
| 193 | # Get array of configurations | 200 | # Get array of configurations |
| 194 | - configs = data["datasets"] | 201 | + configs = data["datasets"] |
| 195 | 202 | ||
| 196 | # Get remote paths | 203 | # Get remote paths |
| 197 | - self.remote_base = os.path.dirname(self.m_remote_master.url()) | 204 | + #self.remote_base = os.path.dirname(self.m_remote_master.url()) |
| 205 | + self.remote_base = self.m_remote_master.path() | ||
| 198 | 206 | ||
| 199 | # Initialise flag if prod has been found | 207 | # Initialise flag if prod has been found |
| 200 | has_prod = False | 208 | has_prod = False |
| @@ -254,16 +262,16 @@ class csiactcopy(ctools.cscript): | @@ -254,16 +262,16 @@ class csiactcopy(ctools.cscript): | ||
| 254 | for run in self.runlist: | 262 | for run in self.runlist: |
| 255 | if not run in remote_ids: | 263 | if not run in remote_ids: |
| 256 | if self.logNormal(): | 264 | if self.logNormal(): |
| 257 | - self.log("Skip observation "+str(run)+": ID not available remotely") | 265 | + self.log("Skip observation "+str(run)+": ") |
| 266 | + self.log("ID not available remotely") | ||
| 258 | self.log("\n") | 267 | self.log("\n") |
| 259 | - | ||
| 260 | 268 | ||
| 261 | # Loop over remote HDU index file | 269 | # Loop over remote HDU index file |
| 262 | for row in range(table.nrows()): | 270 | for row in range(table.nrows()): |
| 263 | 271 | ||
| 264 | # Get observation ID | 272 | # Get observation ID |
| 265 | - obs_id = table["OBS_ID"][row] | ||
| 266 | - file_dir = table["FILE_DIR"][row] | 273 | + obs_id = table["OBS_ID"][row] |
| 274 | + file_dir = table["FILE_DIR"][row] | ||
| 267 | file_name = table["FILE_NAME"][row] | 275 | file_name = table["FILE_NAME"][row] |
| 268 | 276 | ||
| 269 | # Skip if filename is empty | 277 | # Skip if filename is empty |
| @@ -331,10 +339,10 @@ class csiactcopy(ctools.cscript): | @@ -331,10 +339,10 @@ class csiactcopy(ctools.cscript): | ||
| 331 | 339 | ||
| 332 | # Raise Exception if prodname was not found | 340 | # Raise Exception if prodname was not found |
| 333 | if not has_prod: | 341 | if not has_prod: |
| 334 | - msg = "*** ERROR: FITS production \""+self.m_prodname+"\" not available. " | ||
| 335 | - msg += "Available productions are: \n" | 342 | + msg = "*** ERROR: FITS production \""+self.m_prodname+\ |
| 343 | + "\" not available. Available productions are:\n" | ||
| 336 | for config in configs: | 344 | for config in configs: |
| 337 | - msg += " - "+config["name"] + "\n" | 345 | + msg += " - "+config["name"]+"\n" |
| 338 | raise RuntimeError(msg) | 346 | raise RuntimeError(msg) |
| 339 | 347 | ||
| 340 | # Logging | 348 | # Logging |
| @@ -346,7 +354,7 @@ class csiactcopy(ctools.cscript): | @@ -346,7 +354,7 @@ class csiactcopy(ctools.cscript): | ||
| 346 | k = 0 | 354 | k = 0 |
| 347 | 355 | ||
| 348 | # initialise values for logging | 356 | # initialise values for logging |
| 349 | - last_fraction = 0.0 | 357 | + last_fraction = 0.0 |
| 350 | fraction_increment = 20.0 | 358 | fraction_increment = 20.0 |
| 351 | if self.logNormal(): | 359 | if self.logNormal(): |
| 352 | fraction_increment = 10.0 | 360 | fraction_increment = 10.0 |
| @@ -356,7 +364,7 @@ class csiactcopy(ctools.cscript): | @@ -356,7 +364,7 @@ class csiactcopy(ctools.cscript): | ||
| 356 | fraction_increment = 2.0 | 364 | fraction_increment = 2.0 |
| 357 | 365 | ||
| 358 | # initialise logging properties | 366 | # initialise logging properties |
| 359 | - n_copied = 0 | 367 | + n_copied = 0 |
| 360 | total_size = 0.0 | 368 | total_size = 0.0 |
| 361 | 369 | ||
| 362 | # Loop over files and copy | 370 | # Loop over files and copy |
| @@ -433,7 +441,8 @@ class csiactcopy(ctools.cscript): | @@ -433,7 +441,8 @@ class csiactcopy(ctools.cscript): | ||
| 433 | data = json.loads(json_data) | 441 | data = json.loads(json_data) |
| 434 | configs = data["datasets"] | 442 | configs = data["datasets"] |
| 435 | 443 | ||
| 436 | - # Initialise flag indicating if we already have prodname in master file | 444 | + # Initialise flag indicating if we already have prodname in master |
| 445 | + # file | ||
| 437 | has_config = False | 446 | has_config = False |
| 438 | 447 | ||
| 439 | # Initialise new configs array | 448 | # Initialise new configs array |
| @@ -450,7 +459,8 @@ class csiactcopy(ctools.cscript): | @@ -450,7 +459,8 @@ class csiactcopy(ctools.cscript): | ||
| 450 | if not (gammalib.GFilename(str(hdu)).is_fits() and | 459 | if not (gammalib.GFilename(str(hdu)).is_fits() and |
| 451 | gammalib.GFilename(str(obs)).is_fits()): | 460 | gammalib.GFilename(str(obs)).is_fits()): |
| 452 | if self.logTerse(): | 461 | if self.logTerse(): |
| 453 | - self.log("Removing \""+str(config["name"])+"\" (not available)") | 462 | + self.log("Removing \""+str(config["name"])+"\" ") |
| 463 | + self.log("(not available)") | ||
| 454 | self.log("\n") | 464 | self.log("\n") |
| 455 | else: | 465 | else: |
| 456 | # Append config if valid | 466 | # Append config if valid |
| @@ -465,8 +475,8 @@ class csiactcopy(ctools.cscript): | @@ -465,8 +475,8 @@ class csiactcopy(ctools.cscript): | ||
| 465 | 475 | ||
| 466 | # Create new entry if config was not available | 476 | # Create new entry if config was not available |
| 467 | if not has_config: | 477 | if not has_config: |
| 468 | - newdict = dict.fromkeys(["name","hduindx","obsindx"]) | ||
| 469 | - newdict["name"] = self.m_prodname | 478 | + newdict = dict.fromkeys(["name","hduindx","obsindx"]) |
| 479 | + newdict["name"] = self.m_prodname | ||
| 470 | newdict["hduindx"] = os.path.relpath(local_hdu, self.m_outpath) | 480 | newdict["hduindx"] = os.path.relpath(local_hdu, self.m_outpath) |
| 471 | newdict["obsindx"] = os.path.relpath(local_obs, self.m_outpath) | 481 | newdict["obsindx"] = os.path.relpath(local_obs, self.m_outpath) |
| 472 | newconfigs.append(newdict) | 482 | newconfigs.append(newdict) |
| @@ -643,7 +653,8 @@ class csiactcopy(ctools.cscript): | @@ -643,7 +653,8 @@ class csiactcopy(ctools.cscript): | ||
| 643 | # initialise counter for logging | 653 | # initialise counter for logging |
| 644 | removed_rows = 0 | 654 | removed_rows = 0 |
| 645 | 655 | ||
| 646 | - # If clobber=yes, we use the remote content to overwrite corresponding local content | 656 | + # If clobber=yes, we use the remote content to overwrite |
| 657 | + # corresponding local content | ||
| 647 | if clobber: | 658 | if clobber: |
| 648 | 659 | ||
| 649 | # Loop over remote obs_ids | 660 | # Loop over remote obs_ids |
| @@ -666,7 +677,8 @@ class csiactcopy(ctools.cscript): | @@ -666,7 +677,8 @@ class csiactcopy(ctools.cscript): | ||
| 666 | table_has_obsid = True | 677 | table_has_obsid = True |
| 667 | break | 678 | break |
| 668 | 679 | ||
| 669 | - # If clobber=false, we keep the local content unchanged and just expand by remote content | 680 | + # If clobber=false, we keep the local content unchanged and just |
| 681 | + # expand by remote content | ||
| 670 | else: | 682 | else: |
| 671 | # Loop over remote obs_ids | 683 | # Loop over remote obs_ids |
| 672 | for local_obs_id in local_obs: | 684 | for local_obs_id in local_obs: |