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 | 288 | |
| 289 | 289 | # Check for clobber |
| 290 | 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 | 292 | self.log("\n") |
| 293 | 293 | else: |
| 294 | 294 | # Write runs to file |
| 295 | - f = open(outfile.url(),"w") | |
| 295 | + f = open(repr(outfile),"w") | |
| 296 | 296 | for run in self.runs: |
| 297 | 297 | f.write(str(run)+" \n") |
| 298 | 298 | f.close() | ... | ... |
cscripts/csiactcopy.py
| ... | ... | @@ -82,7 +82,7 @@ class csiactcopy(ctools.cscript): |
| 82 | 82 | pars = gammalib.GApplicationPars(parfile) |
| 83 | 83 | except: |
| 84 | 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 | 87 | # Create default parfile |
| 88 | 88 | pars = gammalib.GApplicationPars() |
| ... | ... | @@ -105,7 +105,10 @@ class csiactcopy(ctools.cscript): |
| 105 | 105 | # Get Parameters |
| 106 | 106 | self.m_remote_master = self["remote_master"].filename() |
| 107 | 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 | 113 | # Get parameters |
| 111 | 114 | self.m_prodname = self["prodname"].string() |
| ... | ... | @@ -178,23 +181,28 @@ class csiactcopy(ctools.cscript): |
| 178 | 181 | |
| 179 | 182 | # Raise exception if file not valid |
| 180 | 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 | 187 | # Check for availability of remote master file |
| 184 | 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 | 192 | # Retrieve json data from remote master |
| 188 | 193 | json_data = open(self.m_remote_master.url()).read() |
| 189 | 194 | data = json.loads(json_data) |
| 190 | 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 | 200 | # Get array of configurations |
| 194 | - configs = data["datasets"] | |
| 201 | + configs = data["datasets"] | |
| 195 | 202 | |
| 196 | 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 | 207 | # Initialise flag if prod has been found |
| 200 | 208 | has_prod = False |
| ... | ... | @@ -254,16 +262,16 @@ class csiactcopy(ctools.cscript): |
| 254 | 262 | for run in self.runlist: |
| 255 | 263 | if not run in remote_ids: |
| 256 | 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 | 267 | self.log("\n") |
| 259 | - | |
| 260 | 268 | |
| 261 | 269 | # Loop over remote HDU index file |
| 262 | 270 | for row in range(table.nrows()): |
| 263 | 271 | |
| 264 | 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 | 275 | file_name = table["FILE_NAME"][row] |
| 268 | 276 | |
| 269 | 277 | # Skip if filename is empty |
| ... | ... | @@ -331,10 +339,10 @@ class csiactcopy(ctools.cscript): |
| 331 | 339 | |
| 332 | 340 | # Raise Exception if prodname was not found |
| 333 | 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 | 344 | for config in configs: |
| 337 | - msg += " - "+config["name"] + "\n" | |
| 345 | + msg += " - "+config["name"]+"\n" | |
| 338 | 346 | raise RuntimeError(msg) |
| 339 | 347 | |
| 340 | 348 | # Logging |
| ... | ... | @@ -346,7 +354,7 @@ class csiactcopy(ctools.cscript): |
| 346 | 354 | k = 0 |
| 347 | 355 | |
| 348 | 356 | # initialise values for logging |
| 349 | - last_fraction = 0.0 | |
| 357 | + last_fraction = 0.0 | |
| 350 | 358 | fraction_increment = 20.0 |
| 351 | 359 | if self.logNormal(): |
| 352 | 360 | fraction_increment = 10.0 |
| ... | ... | @@ -356,7 +364,7 @@ class csiactcopy(ctools.cscript): |
| 356 | 364 | fraction_increment = 2.0 |
| 357 | 365 | |
| 358 | 366 | # initialise logging properties |
| 359 | - n_copied = 0 | |
| 367 | + n_copied = 0 | |
| 360 | 368 | total_size = 0.0 |
| 361 | 369 | |
| 362 | 370 | # Loop over files and copy |
| ... | ... | @@ -433,7 +441,8 @@ class csiactcopy(ctools.cscript): |
| 433 | 441 | data = json.loads(json_data) |
| 434 | 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 | 446 | has_config = False |
| 438 | 447 | |
| 439 | 448 | # Initialise new configs array |
| ... | ... | @@ -450,7 +459,8 @@ class csiactcopy(ctools.cscript): |
| 450 | 459 | if not (gammalib.GFilename(str(hdu)).is_fits() and |
| 451 | 460 | gammalib.GFilename(str(obs)).is_fits()): |
| 452 | 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 | 464 | self.log("\n") |
| 455 | 465 | else: |
| 456 | 466 | # Append config if valid |
| ... | ... | @@ -465,8 +475,8 @@ class csiactcopy(ctools.cscript): |
| 465 | 475 | |
| 466 | 476 | # Create new entry if config was not available |
| 467 | 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 | 480 | newdict["hduindx"] = os.path.relpath(local_hdu, self.m_outpath) |
| 471 | 481 | newdict["obsindx"] = os.path.relpath(local_obs, self.m_outpath) |
| 472 | 482 | newconfigs.append(newdict) |
| ... | ... | @@ -643,7 +653,8 @@ class csiactcopy(ctools.cscript): |
| 643 | 653 | # initialise counter for logging |
| 644 | 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 | 658 | if clobber: |
| 648 | 659 | |
| 649 | 660 | # Loop over remote obs_ids |
| ... | ... | @@ -666,7 +677,8 @@ class csiactcopy(ctools.cscript): |
| 666 | 677 | table_has_obsid = True |
| 667 | 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 | 682 | else: |
| 671 | 683 | # Loop over remote obs_ids |
| 672 | 684 | for local_obs_id in local_obs: | ... | ... |