DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
rename_duplicate_dals.RenameDalCli Class Reference

Public Member Functions

 __init__ (self, DalCollector collector)
 
 run (self)
 

Public Attributes

 collector = collector
 
list history = []
 

Protected Member Functions

 _render (self, DalGroup group)
 
 _handle_rename (self, str action, DalGroup group)
 

Protected Attributes

int _idx = 0
 

Detailed Description

Definition at line 253 of file rename_duplicate_dals.py.

Constructor & Destructor Documentation

◆ __init__()

rename_duplicate_dals.RenameDalCli.__init__ ( self,
DalCollector collector )

Definition at line 254 of file rename_duplicate_dals.py.

254 def __init__(self, collector: DalCollector):
255 self.collector = collector
256 self.history: list = []
257 self._idx = 0
258

Member Function Documentation

◆ _handle_rename()

rename_duplicate_dals.RenameDalCli._handle_rename ( self,
str action,
DalGroup group )
protected

Definition at line 352 of file rename_duplicate_dals.py.

352 def _handle_rename(self, action: str, group: DalGroup):
353 if group.has_same_parents:
354 console.print("[bold red]Renaming disabled — these DALs share the same parents.[/]")
355 Prompt.ask("[dim]Press Enter to continue[/]", default="")
356 return
357
358 idx = int(action) - 1
359 if not (0 <= idx < len(group)):
360 console.print("[red]Invalid number.[/]")
361 Prompt.ask("[dim]Press Enter to continue[/]", default="")
362 return
363
364 ext = group[idx]
365 console.print(f"Renaming [cyan]{ext.id}[/] ({ext.dal.className()})")
366 new_name = Prompt.ask("Enter new name (or empty to cancel)").strip()
367 if not new_name:
368 console.print("[yellow]Rename cancelled.[/]")
369 return
370
371 old_name = ext.id
372 ext.rename(new_name)
373 self.history.append((ext, old_name))
374 console.print(f"[green]Renamed {old_name} → {new_name}[/]")
375
376
377@click.command()
378@click.option("--input-folder", "-i", required=True, type=click.Path())

◆ _render()

rename_duplicate_dals.RenameDalCli._render ( self,
DalGroup group )
protected

Definition at line 319 of file rename_duplicate_dals.py.

319 def _render(self, group: DalGroup):
320 console.clear()
321
322 if group.has_same_parents:
323 console.print(
324 Panel(
325 "[bold red]Renaming Disabled[/]\n\n"
326 "These duplicate DALs share the same parents.\n"
327 "Renaming would cause commit inconsistencies.",
328 title="⚠ WARNING",
329 border_style="red",
330 expand=False,
331 )
332 )
333 console.print()
334
335 table = Table(title="Duplicated DAL Objects")
336 for col, style in [("#", ""), ("DAL ID", "cyan"), ("Class", "magenta"),
337 ("Configuration", "purple"), ("Parents", "blue"),
338 ("Attributes", "green"), ("Relations", "yellow")]:
339 table.add_column(col, style=style, justify="right" if col == "#" else "left")
340
341 for i, ext in enumerate(group, 1):
342 attr_str = ", ".join(f"{k}={v}" for k, v in ext.attributes.items())
343 rel_str = ", ".join(f"{k}=[{', '.join(v)}]" for k, v in ext.relations.items())
344 table.add_row(
345 str(i), ext.id, ext.dal.className(),
346 str(ext.config), str(ext.get_parents()),
347 attr_str, rel_str,
348 )
349
350 console.print(table)
351

◆ run()

rename_duplicate_dals.RenameDalCli.run ( self)

Definition at line 259 of file rename_duplicate_dals.py.

259 def run(self):
260 groups = self.collector.groups
261 if not groups:
262 console.print("[green]No duplicate DALs found.[/]")
263 return
264
265 last = "n"
266 # Rich treats [...] as markup tags, so use \[ to render literal square brackets
267 prompt = r"\[n] next, \[p] prev, \[c] commit, \[s] save & quit, \[q] quit, or a number to rename"
268
269 while self._idx <= len(groups):
270 # End-of-list: offer save/back/quit instead of silently exiting
271 if self._idx == len(groups):
272 console.print("\n[bold]Reached the end of all duplicate groups.[/]")
273 action = Prompt.ask(
274 r"\[s] save & quit, \[p] go back, \[q] quit without saving",
275 default="s",
276 ).lower().strip()
277 if action == "p":
278 self._idx -= 1
279 elif action == "s":
280 self.collector.commit()
281 console.print("[bold green]Saved and exiting.[/]")
282 return
283 else:
284 console.print("[bold red]Exiting without saving.[/]")
285 return
286 continue
287
288 group = groups[self._idx]
289 self._render(group)
290 console.print(f"[dim]({self._idx + 1}/{len(groups)})[/]")
291
292 action = Prompt.ask(prompt, default=last).lower().strip()
293
294 if action == "n":
295 self._idx += 1
296 last = action
297 elif action == "p":
298 if self._idx > 0:
299 self._idx -= 1
300 else:
301 console.print("[yellow]Already at the first item.[/]")
302 last = action
303 elif action == "c":
304 self.collector.commit()
305 console.print("[bold green]Changes committed.[/]")
306 elif action == "s":
307 self.collector.commit()
308 console.print("[bold green]Saved and exiting.[/]")
309 return
310 elif action == "q":
311 console.print("[bold red]Exiting without saving.[/]")
312 return
313 elif action.isdigit():
314 self._handle_rename(action, group)
315 last = action
316 else:
317 console.print("[red]Unknown command.[/]")
318
static volatile sig_atomic_t run

Member Data Documentation

◆ _idx

rename_duplicate_dals.RenameDalCli._idx = 0
protected

Definition at line 257 of file rename_duplicate_dals.py.

◆ collector

rename_duplicate_dals.RenameDalCli.collector = collector

Definition at line 255 of file rename_duplicate_dals.py.

◆ history

list rename_duplicate_dals.RenameDalCli.history = []

Definition at line 256 of file rename_duplicate_dals.py.


The documentation for this class was generated from the following file: