Commit edb069860625f1e1d1dfe6320df5c310956bed54

Authored by Alain Klotz
1 parent a6f1918b
Exists in master

Small changes.

src/guitastro/filenames.py
... ... @@ -1221,7 +1221,7 @@ class FileNames(FileNamesException, GuitastroTools):
1221 1221 param['indexes'] = ""
1222 1222 return param
1223 1223  
1224   - def naming_wildcard(self) -> str:
  1224 + def naming_wildcard(self, *args: str, **kwargs: int) -> str:
1225 1225 """Return the wildcard corresponding to the naming rule
1226 1226  
1227 1227 Returns:
... ... @@ -1244,6 +1244,47 @@ class FileNames(FileNamesException, GuitastroTools):
1244 1244 wildcard = "T1M_????????_??????_???_*_Filtre_*_bin?x?.*"
1245 1245 elif self.fcontext_value('naming') == self.NAMING_INDEXED1:
1246 1246 wildcard = "*"
  1247 + # - Param constraints
  1248 + nkwa = len(kwargs)
  1249 + na = len(args)
  1250 + if nkwa > 0:
  1251 + param = self.naming_get(wildcard)
  1252 + # - case indexes
  1253 + if "i" in kwargs.keys():
  1254 + if kwargs['i'] == True and na >= 1:
  1255 + fname = args[0]
  1256 + param_fname = self.naming_get(fname)
  1257 + keys = []
  1258 + if self.fcontext_value('naming') == self.NAMING_INDEXED1:
  1259 + keys = ['indexes']
  1260 + elif self.fcontext_value('naming') == self.NAMING_ROS1:
  1261 + keys = ['date','time','id_scene']
  1262 + elif self.fcontext_value('naming') == self.NAMING_T1M1:
  1263 + keys = ['date','time','millis','index']
  1264 + elif self.fcontext_value('naming') == self.NAMING_PYROS_IMG1:
  1265 + keys = ['date','time','frame']
  1266 + elif self.fcontext_value('naming') == self.NAMING_PYROS_EPH1:
  1267 + keys = ['date']
  1268 + elif self.fcontext_value('naming') == self.NAMING_PYROS_SEQ1:
  1269 + keys = ['id_seq']
  1270 + elif self.fcontext_value('naming') == self.NAMING_PYROS_FIL1:
  1271 + keys = ['date','time']
  1272 + #print(f"{param_fname=}")
  1273 + for key in keys:
  1274 + param_fname[key] = param[key]
  1275 + param = param_fname
  1276 + if self.fcontext_value('naming') == self.NAMING_INDEXED1:
  1277 + if param['indexes'] == "":
  1278 + if param['ndigit'] > 0:
  1279 + param['indexes'] = "?"*param['ndigit']
  1280 + else:
  1281 + param['indexes'] = "*"
  1282 + #print(f"{param=}")
  1283 + # - constraints
  1284 + for key, val in kwargs.items():
  1285 + if key in param.keys():
  1286 + param[key] = val
  1287 + wildcard = self.naming_set(param)
1247 1288 return wildcard
1248 1289  
1249 1290 def naming_set(self, *args, **kwargs) -> str:
... ... @@ -1921,6 +1962,10 @@ class FileNames(FileNamesException, GuitastroTools):
1921 1962 if param['indexes'].isdigit() or param['indexes'] == "*":
1922 1963 valid = True
1923 1964 index_exists = True
  1965 + if len(param['indexes']) > 0:
  1966 + if param['indexes'][0] == "?":
  1967 + valid = True
  1968 + index_exists = True
1924 1969 if valid == False:
1925 1970 texte = f"Indexes {param['indexes']} must be a string or a list of strings" + see_rules
1926 1971 raise FileNamesException(FileNamesException.BAD_PARAM, texte)
... ... @@ -3059,7 +3104,7 @@ class FileNames(FileNamesException, GuitastroTools):
3059 3104 pdict_input = self.dict(fname_input)
3060 3105 # --- Default wilcard of the current fcontext
3061 3106 param_wildcard = fn.naming_get(self.naming_wildcard())
3062   - print(f"(100) {param_wildcard=}")
  3107 + #print(f"(100) {param_wildcard=}")
3063 3108 # --- Get parameters from *kwargs compatible with the fcontext param keys
3064 3109 param_inputs = {}
3065 3110 for key, val in kwargs.items():
... ... @@ -3072,21 +3117,21 @@ class FileNames(FileNamesException, GuitastroTools):
3072 3117 else:
3073 3118 # no file was provided
3074 3119 param = self.naming_get(fname_input)
3075   - print(f"(200) {param=}")
  3120 + #print(f"(200) {param=}")
3076 3121 # --- Set kwargs in the wilcard of the current fcontext
3077 3122 for key, val in param_inputs.items():
3078 3123 param[key] = param_inputs[key]
3079 3124 # --- Modify fcontext attributes if forced
3080 3125 if force:
3081   - print(f"{pdict_input=}")
  3126 + #print(f"{pdict_input=}")
3082 3127 if pdict_input['wildcard_dirname'] == False and pdict_input['dirname'] != ".":
3083 3128 self.rootdir = pdict_input['dirname']
3084 3129 self.extension = pdict_input['extension']
3085 3130 # --- Build the filename
3086 3131 fname_input = self.naming_set(param)
3087   - print(f"(300) {fname_input=}")
  3132 + #print(f"(300) {fname_input=}")
3088 3133 fullname_input = self.joinabs(fname_input)
3089   - print(f"{fullname_input=}")
  3134 + #print(f"{fullname_input=}")
3090 3135 return fullname_input
3091 3136  
3092 3137 def split_dir_name_extension(self, fullfilename:str) -> Tuple[str, str, str]:
... ... @@ -3750,8 +3795,8 @@ class FileNames(FileNamesException, GuitastroTools):
3750 3795  
3751 3796 if __name__ == "__main__":
3752 3797  
3753   - default = 20
3754   - example = input(f"Select the example (0 to 20) ({default}) ")
  3798 + default = 21
  3799 + example = input(f"Select the example (0 to 21) ({default}) ")
3755 3800 try:
3756 3801 example = int(example)
3757 3802 except:
... ... @@ -4186,7 +4231,7 @@ if __name__ == "__main__":
4186 4231 fn.fcontext_create("findex", "Files with indexes")
4187 4232 fn.fcontext = "findex"
4188 4233 fn.pathnaming("Indexed.1")
4189   - file_in = os.path.join("c:","srv","develop","pyros_soft","pyros","vendor","guitastro","tests","data","m57.fit")
  4234 + #file_in = os.path.join("c:","srv","develop","pyros_soft","pyros","vendor","guitastro","tests","data","m57.fit")
4190 4235 file_in = "M-57"
4191 4236 param = fn._naming_get_indexed1(file_in)
4192 4237 print(f"{param=}")
... ... @@ -4194,3 +4239,27 @@ if __name__ == "__main__":
4194 4239 gn = FileNames()
4195 4240 # --- Create a file context
4196 4241 gn.fcontext_create("gindex", "Files with indexes")
  4242 +
  4243 + if example == 21:
  4244 + """
  4245 + Test the method naming_wildcard of various fcontexts
  4246 + """
  4247 + fn = FileNames()
  4248 + # --- Create a file context
  4249 + fn.fcontext_create("pf", "Files with indexes")
  4250 + fn.fcontext = "pf"
  4251 + fn.pathnaming("PyROS.img.1")
  4252 + # ---
  4253 + wildcard = fn.naming_wildcard(ftype="L0A", unit="TNC", channel="CH1")
  4254 + print(f"{wildcard=}")
  4255 + # ---
  4256 + in_fullname = r"/srv/work/L1B_20211026_194522999983_1_TNC_CH1_0123456789_001_001.fits.gz"
  4257 + wildcard = fn.naming_wildcard(in_fullname, i=True)
  4258 + print(f"{wildcard=}")
  4259 + # ---
  4260 + fn.pathnaming("Indexed.1")
  4261 + in_fullname = r"/srv/work/i.fits.gz"
  4262 + wildcard = fn.naming_wildcard(in_fullname, i=True)
  4263 + print(f"{wildcard=}")
  4264 +
  4265 +
... ...
src/guitastro/guitastrotools.py
... ... @@ -648,7 +648,7 @@ if __name__ == "__main__":
648 648 Create initial source code of a new device.
649 649 """
650 650 gta1 = GuitastroDev()
651   - res = gta1.create_device_module("Esatto", "Flipro")
  651 + res = gta1.create_device_module("Flipro", "Quickaudine")
652 652 print(f"res={res}")
653 653  
654 654 if example == 2:
... ...