def try_import_rx(filename, parentdict, *items, tp='ro'): from __main__ import dbg importdict = type(parentdict)() foundlist = [] if not len(items): return "itemlist must not be empty" try: readobj = open(filename).read() if tp == 'rx': exec(readobj, importdict) except Exception as e: del importdict return (e) for it in items: if tp == 'ro': parentdict[it] = readobj else: if it in importdict: ### Check and print if overwriting if it in parentdict: dbg.dprint(256, type(parentdict), '[', it, ']', parentdict[it]) ### foundlist.append(it) if isinstance(importdict[it], dict): parentdict[it] = type(parentdict)(importdict.get(it)) else: parentdict[it] = importdict.get(it) del importdict return foundlist
def __init__(self, master=None, **kw): self.myname = type(self).__name__ super().__init__(master, **kw) self.l1 = ttk.Label(self, text=" F2-L1\ncentered", relief='ridge', anchor='center') self.l2 = ttk.Label(self, text="F2-L2", relief='ridge', anchor='center') self.l3 = ttk.Label(self, text="F2-L3", relief='ridge', anchor='center') self.l1.grid(row=0, column=0, sticky='nsew') self.l2.grid(row=0, column=1, sticky='nsew') self.l3.grid(row=0, column=2, sticky='nsew') self.grid_columnconfigure(0, weight=1) self.grid_columnconfigure(1, weight=1) self.grid_columnconfigure(2, weight=1) self.grid_rowconfigure(0, weight=1) if pydevprog: dbg.entersub() dbg.dprint(1, '->', self.myname) cfg.widgets['class'][self.myname] = self dbg.dprint(1, '<-', self.myname) dbg.leavesub()
def __init__(self, master=None, **kw): self.myname = type(self).__name__ if master is not None: super().__init__(master, **kw) # dbg.dprint(4,"tkcols",cfg.tkcols,'guidefs',cfg.guidefs) #style = ttk.Style(master) if pydevprog: dbg.entersub() dbg.dprint(1, '->', self.myname) # cdict = {'bg':'grey26','fg':'white','activebackground':'grey39','activeforeground':'white'} self.mainmenu = tk.Menu(master, relief='flat') self.master.config(menu=self.mainmenu) self.filemenu = tk.Menu(self.mainmenu) self.filemenu.add_command(label='Open', command=self.showc) self.filemenu.add_command(label='Save', command=self.showc) self.filemenu.add_separator() self.filemenu.add_command(label='Exit', command=self.Exit) self.mainmenu.add_cascade(menu=self.filemenu, label='File') #self.mainmenu.entryconfigure(0,tk.Menu(self.mainmenu, tearoff=0,**cdict),label) self.helpmenu = tk.Menu(self.mainmenu) self.helpmenu.add_command(label='About', command=self.showc) self.mainmenu.add_cascade(label='Help', menu=self.helpmenu) if pydevprog: cfg.widgets['class'][self.myname] = self cfg.widgets['menubar']['main'] = self.mainmenu cfg.widgets['menubar']['File'] = self.filemenu cfg.widgets['menubar']['Help'] = self.helpmenu dbg.dprint(1, '<-', self.myname) dbg.leavesub()
def TEST_API(*args): """ calls the spacewalk api and prints the answer examples: api.getApiNamespaces api.getApiNamespaceCallList system errata.getDetails CESA-2019:2029 """ from __main__ import dbg, prgargs, data # import sumaconnect dbg.entersub() dbg.dprint(2, "ARGS", args) if len(args) > 0: if "help" in args: print(f"Usage: {dbg.myself().__name__} some.api.call [args]") print(f"{dbg.myself().__doc__}") dbg.leavesub() return else: dbg.setlvl(3) ### Create new arglist call = args[0] rest = args[1:] dbg.dprint(0, F"Call {call} with {rest}") sumaconnect.docall(args[0], *rest) dbg.setlvl() else: print("no valid input") dbg.leavesub() return
def prnout(typ, *args): """ print output to stdout and depending on type: hostline: 'h',user,host,cmd error : 'e',other args # first one red warning : 'w',all args # all yellow info : 'i',all args # all normal """ from __main__ import dbg, cfg rst = cfg.data.colors.rst fgy = cfg.data.colors.fgy fgg = cfg.data.colors.fgg fgr = cfg.data.colors.fgr hlen = cfg.data.hlen line = f"error in args to print: {' '.join(args)}" if typ.startswith('h'): line = f"{fgg}--------------- {args[0]}@{args[1]:{hlen}} {' '.join(args[2:])}{rst}" loguru.logger.info(line) elif typ.startswith('e'): line = f"{fgr}{args[0]}{rst} | " + " ".join(args[1:]) loguru.logger.error(line) elif typ.startswith('i'): line = f"{' '.join(args)}" loguru.logger.info(line) elif typ.startswith('w'): line = f"{fgy}{args[0]}{rst} | " + " ".join(args[1:]) loguru.logger.warning(line) else: dbg.dprint(0, line, args) return print(line)
def handle_fdict(namelist, filedict, type=None): """ compare a list of names to a dictionary with teh available names as keys. a type for the comparison must be given: 1by1, single or items. Returns a list of matching items. """ from __main__ import dbg dbg.entersub() result = [] dbg.dprint(2, "type", type, namelist) for n in namelist: new = n.split(',') for name in new: if not name: continue dbg.dprint(2, name) if name in filedict: if type == '1by1': with open(filedict[name], 'r') as f: for line in f: if line.startswith('#'): continue else: result.append(line.strip()) elif type == 'single': result = filedict[name] elif type == 'items': result.append(filedict[name]) else: print("not yet done") else: result.append(name) dbg.leavesub() return result
def Actions_Delete(*args): """ deletes archived actions older than num days. """ from __main__ import dbg, prgargs, data # import datetime,time,sumaconnect dbg.entersub() dbg.dprint(2, "ARGS", args) days = 30 ses = data['conn']['ses'] key = data['conn']['key'] if len(args) > 0: if "help" in args: print(f"Usage: {dbg.myself().__name__} [num of days]") print(f"{dbg.myself().__doc__}") print("Default:", days, "days\n") dbg.leavesub() return elif myinput.is_number(args[0]): days = float(args[0]) else: print("no valid input") dbg.leavesub() return tframe = float(days) * 24 * 3600 currts = time.time() startts = currts - tframe readable = time.ctime(startts) archlist = [] totala = 0 ret = 0 print("----- Startdate:", readable) actions = ses.schedule.listArchivedActions(key) totala = len(actions) for a in actions: exects = datetime.datetime.timestamp(a['earliest']) if exects >= startts: continue print("added Action", a['id'], a['earliest']) archlist.append(a['id']) # try : # for aid in archlist: # dbg.dprint(0,"Aid",aid, "Type", type(aid)) # sumaconnect.docall('schedule.deleteActions',str(aid)) # ret += ses.schedule.deleteActions(key,tuple(aid)) ret = ses.schedule.deleteActions(key, archlist) # except Error as e: # print ("no success,e") if myinput.is_number(ret) and ret == 1: print("deleted", len(archlist), "of", totala, "Actions") else: print(ret) dbg.leavesub() return
def Actions_Archive(*args): """ archives actions older than num days. """ from __main__ import dbg, prgargs, data # import datetime,time,sumaconnect dbg.entersub() dbg.dprint(2, "ARGS", args) days = 7 ses = data['conn']['ses'] key = data['conn']['key'] if len(args) > 0: if "help" in args: print(f"Usage: {dbg.myself().__name__} [num of days]") print(f"{dbg.myself().__doc__}") print("Default:", days, "days\n") dbg.leavesub() return elif myinput.is_number(args[0]): days = float(args[0]) else: print("no valid input") dbg.leavesub() return tframe = float(days) * 24 * 3600 currts = time.time() startts = currts - tframe readable = time.ctime(startts) archlist = [] totalact = 0 print("----- Startdate:", readable) calllist = { 'completed': ses.schedule.listCompletedActions, 'failed': ses.schedule.listFailedActions } for k in calllist: actions = calllist[k](key) numact = len(actions) totalact += numact for a in actions: exects = datetime.datetime.timestamp(a['earliest']) if exects >= startts: continue print("added Action", a['id'], a['earliest'], 'from', k) archlist.append(a['id']) ret = ses.schedule.archiveActions(key, archlist) if myinput.is_number(ret) and ret == 1: print("archived", len(archlist), "of", totalact, "Actions") else: print(ret) dbg.leavesub() return
def write_savefile(savefile): """ write data['sumastate'] to savefile """ from __main__ import prgname, dbg, data #import time,os,pickle dbg.entersub() with open(savefile, 'wb') as f: dbg.dprint(2, "Creating fresh Systemstate in", savefile) pickle.dump(data['sumastate'], f) dbg.leavesub() return ()
def read_savefile(savefile): """ Read the statefile, overwrite data['sumastate'] """ from __main__ import prgname, dbg, data #import time,os,pickle dbg.entersub() with open(savefile, 'rb') as f: data['sumastate'] = pickle.load(f) dbg.dprint(4, "Start data.sumastate", data['sumastate'], "End data.sumastate") dbg.leavesub() return ()
def Systems_Status(*args): """ Prints out the state of Systems Argstring can be a blank separated list of Systems and/or groups Default: Without args prints all systems of the default dumpfile """ from __main__ import dbg, prgargs, data dbg.entersub() dbg.dprint(2, "ARGS", args) #---- Settings ses = data['conn']['ses'] key = data['conn']['key'] grplist = data['sumastate']['groups'] syslist = data['sumastate']['systems'] patlist = data['sumastate']['patches'] sysorgroup = {} if len(args): if "help" in args: print( f"Usage: {dbg.myself().__name__} [sysorgroup [sysorgroup] ...]" ) print(f"{dbg.myself().__doc__}") dbg.leavesub() return else: for sog in args: if sog in grplist: for s in grplist[sog]['systems']: sysorgroup[s] = sysorgroup.get(s, 1) elif sog in syslist: sysorgroup[sog] = sysorgroup.get(sog, 1) else: dbg.dprint(0, sog, "is not a known group or system") else: sysorgroup = syslist #---- # old = uyuni_patches.check_savefile(data['savefile']) # if old : # dbg.dprint(0, "Updating Statefile, please wait") # UpdateStateFile() print(data['formats']['systemstateheader']) for system in sorted(sysorgroup): print(data['formats']['systemstateline'].format( syslist[system]['group'], system, syslist[system]['last_boot'].strftime("%Y-%m-%d"), syslist[system]['reboot'], syslist[system]['sec'], syslist[system]['bgf'], syslist[system]['enh'], syslist[system]['updates'], syslist[system]['last_checkin'].strftime("%Y-%m-%d"))) dbg.leavesub() return
def docall(name,*args): """ execute a known function by name. Convert string args into python objects before. return the answer of the call. """ from __main__ import dbg,data dbg.entersub() ses = data['conn']['ses'] key = data['conn']['key'] dbg.dprint(2,"name:", name) dbg.dprint(2,"args:", args, ", type of args: ",type(args)) call = getattr(ses, name) if len(args) == 0: answer = call(key) else: newargs = [] count = 1 ### create objects and append them to new array for a in args: dbg.dprint(4," {:02d}a - {} - {}".format(count,a,type(a))) obj = myinput.string_to_pyobj(a) newargs.append(obj) count += 1 ### Call the xmlrpc function on server answer = call(key,*newargs[0:]) ### print answer and return dbg.dprint(2,'Start answer for '+name,answer,"End answer for"+name ) dbg.leavesub() return(answer)
async def run_mcmds(hosts,cmd,tmout,**kwargs): from __main__ import dbg,cfg,prgargs from rxe2_mod_general import prnout dbg.entersub() dbg.dprint(2,'cmd:',cmd,', tmout:',tmout,', kwargs:',kwargs) availhosts = [] #tasks = (run_cmd(host,cmd,**kwargs) for host in hosts) tasks = (asyncio.wait_for(run_cmd(host,cmd,**kwargs),timeout=tmout) for host in hosts) results = await asyncio.gather(*tasks, return_exceptions=True) if cmd.startswith('rm /tmp/') : for i, result in enumerate(results, 0): if isinstance(result, Exception): prnout('w',"Exception in rm cmd:", hosts[i],"remove failed") elif cmd == cfg.data.chkcmd: for i, result in enumerate(results, 0): if isinstance(result, asyncio.TimeoutError): prnout('h',kwargs['username'],hosts[i],'Conncheck') prnout('e',"Timeout Exception:",str(result)) elif isinstance(result, Exception): prnout('h',kwargs['username'],hosts[i],'Conncheck') prnout('e',"Exception in conntest:", str(result)) else: if not len(prgargs.cmd): prnout('h',kwargs['username'],hosts[i],'Conncheck') prnout('i',"{}".format(result.stdout.rstrip(),end='')) availhosts.append(hosts[i]) dbg.leavesub() return availhosts else: for i, result in enumerate(results, 0): prnout('h',kwargs['username'],hosts[i],cmd) if isinstance(result, asyncio.TimeoutError): prnout('e',"Timeout Exception:",str(result)) continue if isinstance(result, Exception): prnout('e',"Execution Exception:", str(result)) continue ### always do if result.exit_status: prnout('i','exit_code:',result.exit_status) if result.stdout: prnout('i',"{}".format(result.stdout.rstrip(),end='')) if result.stderr: prnout('i',"stderr: {}".format(result.stderr.rstrip(),end='')) dbg.leavesub()
async def run_mcopy(hosts,src,dst,**kwargs): from __main__ import dbg from rxe2_mod_general import prnout dbg.entersub() dbg.dprint(2,'src:',src,', dst:',dst,', kwargs:',kwargs) availhosts = [] tasks = (copy_file(host,src,dst,**kwargs) for host in hosts) results = await asyncio.gather(*tasks, return_exceptions=True) for i, result in enumerate(results, 0): if isinstance(result, Exception): rxe2_mod_general.prnout('h',kwargs['username'],hosts[i],'Conncheck') prnout('e',"Exception in conntest:", str(result)) else: availhosts.append(hosts[i]) dbg.leavesub() return availhosts
def __init__(self, master=None, **kw): self.myname = type(self).__name__ super().__init__(master, **kw) if master is not None: self.style = ttk.Style(master) self.master = master else: self.style = ttk.Style() self.master = None self.theme_autochange = tk.IntVar(self, 1) if pydevprog: dbg.entersub() dbg.dprint(1, '->', self.myname) self._setup_widgets() if pydevprog: cfg.widgets['class'][self.myname] = self dbg.dprint(1, '<-', self.myname) dbg.leavesub()
def check_savefile(savefile): """ checks for the age of statefile. If file is younger than data['maxage'] returns 0, else returns the differnce (older than data['maxage']) in seconds. """ from __main__ import prgname, dbg, data #import time,os,datetime dbg.entersub() overdue = 0 if not os.path.exists(savefile): create_savefile(savefile) dbg.dprint(0, "Created new Systemstate") f_age = time.time() - os.path.getmtime(savefile) max_s = (data['maxage'] * 60) if (f_age > max_s): overdue = f_age #f_age = str(datetime.timedelta(seconds=f_age)) #dbg.dprint(0, "SystemState is",f_age,"old, Information may be outdated") dbg.leavesub() return (overdue)
def Patches_DeleteManual(*args): """ Delete Patches from a Cloned Channel if they have a CM- advisory """ from __main__ import dbg, prgargs, cfg # import sumaconnect dbg.entersub() dbg.dprint(2, "ARGS", args) if len(args): if "help" in args: print(f"Usage: {dbg.myself().__name__} Channel") print(f"{dbg.myself().__doc__}") dbg.leavesub() return else: chan = args[0] ### Create new arglist else: print("no valid channel") print(f"Usage: {dbg.myself().__name__} Channel") print(f"{dbg.myself().__doc__}") dbg.leavesub() return ses = data['conn']['ses'] key = data['conn']['key'] clist = ses.channel.listSoftwareChannels(key) source_exists = next( (True for channel in clist if channel['label'] == chan), False) if source_exists: srcerrata = ses.channel.software.listErrata(key, chan) # dbg.dprint(256,"List of Errata", srcerrata) for ref in srcerrata: print(ref['advisory_name']) if ref['advisory_name'].startswith('CM'): print("Delete: ", ref['advisory_name']) ses.errata.delete(key, ref['advisory_name']) else: print("no valid channel: ", channel) dbg.leavesub() return
def Channel_List(*args): """ lists channels matching search without args show all known channels """ from __main__ import dbg, prgargs, data # import uyuni_channels dbg.entersub() dbg.dprint(2, "ARGS", args) ses = data['conn']['ses'] key = data['conn']['key'] search = '' chnlist = {} arglist = list(args) if len(arglist) > 0: if "help" in args: print(f"Usage: {dbg.myself().__name__} [search]") print(f"{dbg.myself().__doc__}") dbg.leavesub() return else: search = arglist[0] (chnlist) = uyuni_channels.Get_Channel_List(ses, key) chbylabel = chnlist['byLabel'] chbyparent = chnlist['byParent'] print(data['formats']['channelheader'], end="") for pa in sorted(chbyparent): if search in pa or [key for key in chbyparent[pa] if search in key]: print(data['formats']['channelparent'] % (pa, chbylabel[pa]['id'], chbylabel[pa]['pkg'], chbylabel[pa]['errata'], chbylabel[pa]['sys'])) for cl in sorted(chbyparent[pa]): if search in cl: print(data['formats']['channelchild'] % (cl, chbylabel[cl]['id'], chbylabel[cl]['pkg'], chbylabel[cl]['errata'], chbylabel[cl]['sys'])) print() dbg.leavesub() return (chbylabel)
def __init__(self, master=None, **kw): self.myname = type(self).__name__ if pydevprog: dbg.entersub() dbg.dprint(1, '->', self.myname) dbg.dprint(4, self.myname, "is pydevprog") cfg.widgets['class'][self.myname] = self super().__init__(master, **kw) self.pane = ttk.Panedwindow(master, orient='horizontal') self.L = ttk.Frame(self.pane) self.L.grid(column=0, row=0, sticky='nsew') self.L.rowconfigure(0, weight=1, minsize=50) self.L.columnconfigure(0, weight=1, minsize=50) self.R = ttk.Frame(self.pane) self.R.grid(column=0, row=0, sticky='nsew') self.L.rowconfigure(0, weight=1, minsize=100) self.L.columnconfigure(0, weight=1, minsize=50) self.pane.add(self.L, weight=1) self.pane.add(self.R, weight=3) self.pane.grid(column=0, row=0, sticky='nsew') if pydevprog: cfg.widgets['L'] = self.L cfg.widgets['R'] = self.R dbg.dprint(1, '<-', self.myname) dbg.leavesub()
def Get_Channel_List(ses,key,*args): """ Creates a dictionary of all manageable channels found on the uyuni server and returns it. The dictionary has two keys 'byLabel' and 'byParent', containing the channels and their most important detail information. """ from __main__ import dbg,prgargs,data dbg.entersub() dbg.dprint(2,args) chnlist = {} chbyparent = {} chbylabel = {} for elem in ses.channel.listSoftwareChannels(key): label = elem['label'] chbylabel[label] = chbylabel.get(label,{}) chbylabel[label]['arch'] = elem['arch'] chbylabel[label]['parent'] = elem['parent_label'] chbylabel[label]['errata'] = len(ses.channel.software.listErrata(key,label)) for elem in ses.channel.listAllChannels(key): label = elem['label'] chbylabel[label]['id'] = elem['id'] chbylabel[label]['pkg'] = elem['packages'] chbylabel[label]['sys'] = elem['systems'] for label in chbylabel: parent = chbylabel[label]['parent'] if not parent: chbyparent[label] = chbyparent.get(label,{}) else: chbyparent[parent] = chbyparent.get(parent,{}) chbyparent[parent][label] = 1 chnlist['byLabel'] = chbylabel chnlist['byParent'] = chbyparent dbg.leavesub() return(chnlist)
def __init__(self, master=None, **kw): self.myname = type(self).__name__ if pydevprog: dbg.entersub() dbg.dprint(1, '->', self.myname) super().__init__(master, **kw) self.stat_msg = tk.StringVar() self.stat_inp = tk.IntVar(0) self.stat_msg.set('nix') self.status = ttk.Label(self) self.status.configure(textvariable=self.stat_inp, width=1) self.message = ttk.Label(self, textvariable=self.stat_msg, relief='sunken', width=25) ### setup expand self.status.grid(row=0, column=0, sticky='w', padx=2) self.message.grid(row=0, column=1, sticky='ew', padx=0, pady=2) self.grid_columnconfigure(1, weight=1) if pydevprog: dbg.dprint(1, '<-', self.myname) dbg.leavesub() cfg.widgets['class'][self.myname] = self
def Channel_ShowPatchDiff(*args): """ Show the errata difference between source and target channel. To avoid problems the channel containing more errata should be the first param <source>. To be able to compare original and cloned channels the leading CL- is cut off in both channels. -v adds verbosity. """ from __main__ import dbg, prgargs, data, prgname dbg.entersub() dbg.dprint(2, "ARGS", args) ses = data['conn']['ses'] key = data['conn']['key'] rest = [] for i in range(0, len(args)): if args[i] == "help": print( f"Usage: {dbg.myself().__name__} <SourceChannel> <TargetChannel> [-v[v]]" ) print(f"{dbg.myself().__doc__}") dbg.leavesub() return else: if re.match('\w+', args[i]): if (len(rest) <= 2): rest.append(args[i]) if len(rest) == 2: source, target = rest print(f"Source: {source}") print(f"Target: {target}") uyuni_patches.get_patch_difference(source, target) else: dbg.dprint(0, "not enough Arguments") dbg.leavesub() return
def Channel_03_MergeArchive(*args): """ merge the latest archive channel into the test channel. See server config data['chmap']['03_arcmerge'] if test is given only shows what will be done. """ from __main__ import dbg, prgargs, data, modlog dbg.entersub() dbg.dprint(2, "ARGS", args) ses = data['conn']['ses'] key = data['conn']['key'] clone = False testonly = False if len(args) > 0: if "help" in args: print(f"Usage: {dbg.myself().__name__} [test] [-v]") print(f"{dbg.myself().__doc__}") dbg.leavesub() return if "test" in args: testonly = True chmap = data['chmap']['03_arcmerge'] modlog.info(f"----> {dbg.myself().__name__}") for (source, target, parent) in chmap: modlog.info(f"{source} -> {target}") ok = uyuni_channels.Merge_Channel(source, target, parent, test=testonly, clone=clone) if not ok: line = F"Merging {source} to {target} did not succeed" dbg.dprint(256, line) modlog.error(line) modlog.info(f"<---- {dbg.myself().__name__}") dbg.leavesub() return
def UpdateStateFile(*args): """ Gathers needed information for all managed systems, their patches and states and saves it first in the global dictionary data['sumastate'], then dumps this dictionary to dumpfile for later use. """ from __main__ import dbg, prgargs, data # import sys,pickle,uyuni_groups,uyuni_channels,uyuni_patches dbg.entersub() dbg.dprint(2, "ARGS", args) dumpfile = data['savefile'] if "help" in args: print(f"Usage: {dbg.myself().__name__} [dumpfile]") print(f"{dbg.myself().__doc__}") print("Default:", dumpfile) print("") dbg.leavesub() return if len(args): dumpfile = args[0] dbg.dprint(4, dumpfile) dbg.dprint(4, data) ses = data['conn']['ses'] key = data['conn']['key'] ### get new values in fresh dictionaries grplist = {} syslist = {} patlist = {} chnlist = {} (grplist, syslist) = uyuni_groups.Get_Group_List(ses, key, grplist, syslist) (syslist, patlist) = uyuni_patches.get_Patches_for_all_Systems( ses, key, syslist, patlist) (chnlist) = uyuni_channels.Get_Channel_List(ses, key) ### write the updated values from memory to disk data['sumastate']['groups'] = grplist data['sumastate']['systems'] = syslist data['sumastate']['patches'] = patlist data['sumastate']['channels'] = chnlist uyuni_patches.write_savefile(dumpfile) dbg.leavesub() return
def Channel_02_UpdateArchive(*args): """ create or update archive channels according to the settings in the server config to the appointed channel. if test is given only shows what will be done. Errata are always cloned for Archives. """ from __main__ import dbg, prgargs, data, modlog dbg.entersub() dbg.dprint(2, "ARGS", args) ses = data['conn']['ses'] key = data['conn']['key'] chmap = data['chmap']['02_datefreeze'] chlist = data['sumastate']['channels'] testonly = False printout = False clone = True ###### Check args and do it ################################################ if len(args) > 0: if "help" in args: print(f"Usage: {dbg.myself().__name__} [test] [-v]") print(f"{dbg.myself().__doc__}") dbg.dprint(64, "current config from data.chmap.02_datefreeze", chmap, "End data['chmap']['02_datefreeze']") print("") dbg.leavesub() return elif "test" in args: testonly = 1 else: pass modlog.info(f"----> {dbg.myself().__name__}") for (source, target, parent) in chmap: modlog.info(f"{source} -> {target}") ok = uyuni_channels.Merge_Channel(source, target, parent, test=testonly, clone=clone) if not ok: dbg.dprint(256, F"ArchiveUpdate to {target} did not succeed") modlog.error(F"ArchiveUpdate to {target} did not succeed") modlog.info(f"<---- {dbg.myself().__name__}") dbg.leavesub() return
def get_patch_difference(source, target): """ check errata of source and target channel for differences and print the errata names. To prevent problems with clone names, target should be the cloned channel. """ from __main__ import dbg, prgargs, data dbg.entersub() #print("LEVEL",dbg.setlvl()) ses = data['conn']['ses'] key = data['conn']['key'] typenames = data['patchtypenames'] ##### Check if channels exist clist = ses.channel.listSoftwareChannels(key) source_exists = next( (True for channel in clist if channel['label'] == source), False) target_exists = next( (True for channel in clist if channel['label'] == target), False) if source_exists and target_exists: srcerrata = ses.channel.software.listErrata(key, source) tgterrata = ses.channel.software.listErrata(key, target) srcnames = set(d['advisory_name'].replace('CL-', '', 1) for d in srcerrata) tgtnames = set(d['advisory_name'].replace('CL-', '', 1) for d in tgterrata) srconly = sorted(list(srcnames.difference(tgtnames))) #dbg.dprint(256,'srconly',sorted(srconly)) #srconly = sorted(srconly) #dbg.dprint(256,type(srconly)) #return #dbg.dprint(0,"Start Missing Errata in target",srconly, "End Missing Errata in target") chunknum = 0 chunk = [] for errnum in range(0, len(srconly)): #if errnum // 10 == chunknum: #chunk.append(srconly[errnum]) #else : #dbg.dprint(0, "chunk", chunk) #chunk = [] #chunknum += 1 #chunk.append(srconly[errnum]) err = srconly[errnum] errdetail = ses.errata.getDetails(key, err) errpkgs = ses.errata.listPackages(key, err) #print( "----- {} --- id: {:7d} {}".format( #err,errdetail['id'],errdetail['last_modified_date'])) dbg.dprint(0, f"{err:33s} id:{errdetail['id']:7d}") dbg.dprint(64, f" Type: {errdetail['type']}") dbg.dprint(64, f" Synopsis: {errdetail['synopsis']}") dbg.dprint( 64, f" Date: {errdetail['last_modified_date']}" ) #print( " Topic: {}".format(errdetail['topic'])) dbg.dprint(128, f" -- Packages affected") for pkgnum in range(0, len(errpkgs)): pkg = errpkgs[pkgnum] pkgstring = "".join([ f" Id:{pkg['id']:6d}, ", f"N: {pkg['name']:30}, ", #f"V: {pkg['version']:7}, ", f"R: {pkg['release']:7}, ", f"File:{pkg['file']}" ]) f"V: {pkg['version']:7}, ", f"R: {pkg['release']:7}" ]) dbg.dprint(128, pkgstring) #dbg.dprint(0, "Start Packages affected",errpkgs, "End Packages affected") #dbg.dprint(0, "chunk", chunk) dbg.leavesub() return ()
def load_all_themes(root): if pydevprog: dbg.entersub() if dbg.key_exists(cfg, '.guidefs.available_themes'): dbg.leavesub() return cfg.guidefs.available_themes style = ttk.Style(root) tkversion = tk.TkVersion themelist = list(style.theme_names()) if tkversion >= 8.5: blacktheme = os.path.join(themepaths['black'], 'black.tcl') try: if 'black' not in themelist: root.tk.call('source', blacktheme) themelist.append('black') except Exception as e: if pydevprog: dbg.dprint(0, "Could not load theme black:", e) if tkversion == 8.6: try: #print(themepaths['tksvg']) root.tk.call('lappend', 'auto_path', themepaths['tksvg']) root.tk.call('package', 'require', 'tksvg') except Exception as e: if pydevprog: dbg.dprint(0, "Could not load tksvg:", e) if tkversion >= 8.6: try: #print( themepaths['aw']) root.tk.call('lappend', 'auto_path', themepaths['aw']) root.tk.call('package', 'require', 'awthemes') root.tk.call('package', 'require', 'colorutils') themes = [f for f in os.listdir(themepaths['aw']) \ if os.path.isfile(os.path.join(themepaths['aw'], f)) \ and f.startswith('aw') and f.endswith('.tcl')] for f in themes: if f == 'awthemes.tcl' or f == 'awtemplate.tcl': continue t = f.split('.')[0] if t not in themelist: themelist.append(t) except Exception as e: if pydevprog: dbg.dprint(0, "Could not load awthemes:", e) try: # #print( themepaths['scid']) scidthemes = os.path.join(themepaths['scid'], 'scidthemes.tcl') if 'scidgrey' not in themelist: root.tk.call('source', scidthemes) themes = [f for f in os.listdir(themepaths['scid']) \ if os.path.isdir(os.path.join(themepaths['scid'], f))] for f in themes: if f == 'scid': continue if f not in themelist: themelist.append(f) except Exception as e: if pydevprog: dbg.dprint(0, "Could not load scidthemes:", e) if pydevprog: cfg.guidefs.loaded = True cfg.guidefs.available_themes = themelist dbg.dprint(4, dbg.myname(), "Loaded Themes:", themelist) dbg.leavesub() return themelist
def use_theme(root, wanted, **kwargs): """ This function expects: 1. the top widget 2. a single theme name or a list of wanted themes (first match is selected) 3. optionally the keyword reconfigure=True|False Selects the wanted theme or default if wanted is not available Sets the colors of known (pydevprog) menus """ style = ttk.Style(root) if pydevprog: dbg.entersub() cfg.tkcols.clear() themes = load_all_themes(root) if isinstance(wanted, list) or isinstance(wanted, tuple): for theme in wanted: if theme in themes: break elif isinstance(wanted, str): theme = wanted if theme not in themes: theme = 'default' #print("Selected",theme) if theme.startswith('aw'): if pydevprog and theme not in style.theme_names(): root.tk.call('package', 'require', 'awthemes') root.tk.call('package', 'require', 'colorutils') if 'BgCol' in cfg.guidefs: #dbg.dprint(0, "Wanted BG:",cfg.guidefs.BgCol) root.tk.call('::themeutils::setBackgroundColor', theme, cfg.guidefs.BgCol) if 'HiCol' in cfg.guidefs: #dbg.dprint(0, "Wanted Hi:",cfg.guidefs.HiCol) root.tk.call('::themeutils::setHighlightColor', theme, cfg.guidefs.HiCol) if 'Scroll' in cfg.guidefs: root.tk.call('::themeutils::setThemeColors', theme, 'style.progressbar rounded-linetk.TkVersion', 'style.scale circle-rev', 'style.scrollbar-grip none', 'scrollbar.has.arrows false') root.tk.call('package', 'require', theme) style.theme_use(theme) ### get colors for menubar tkcols = {} tkcols['activebackground'] = root.tk.call('::ttk::style', 'lookup', 'TEntry', '-selectbackground', 'focus') tkcols['bg'] = root.tk.call('::ttk::style', 'lookup', 'TButton', '-background') tkcols['fg'] = root.tk.call('::ttk::style', 'lookup', 'TButton', '-foreground') tkcols['activeforeground'] = root.tk.call('::ttk::style', 'lookup', 'TButton', '-foreground') ### reconfigure menubar if pydevprog: cfg.tkcols = tkcols dbg.dprint(2, "Selected Theme:", theme, ", Colors:", cfg.tkcols) if 'menubar' in cfg.widgets: newdict = cfg.widgets.menubar for menu in newdict: dbg.dprint(8, "ColorConfig:", menu, newdict[menu]) newdict[menu].configure(**tkcols) if 'contentmenu' in cfg.widgets: newdict = cfg.widgets.contentmenu for menu in newdict: dbg.dprint(8, "ColorConfig:", menu, newdict[menu]) newdict[menu].configure(**tkcols) dbg.leavesub() return style.theme_use()
def Merge_Channel(source,target,parent,test=False,clone=False): """ Merge content and errata from source channel to target channel. All channel parameters are label strings. parent is the label of target's parent. In addition the kwargs test and clone are accepted with boolean values. Returns 0 on failure, in case of test or success returns 1 """ from __main__ import dbg,prgargs,data,modlog dbg.entersub() dbg.dprint(2,"verbose :",dbg.setlvl(),", test :", test,",clone :",clone) #dbg.dprint(256,dbg.myname()) ses = data['conn']['ses'] key = data['conn']['key'] ##### Falls test angegeben wurde nur die Aktionen ausgeben if test: dbg.setlvl(64) #dbg.dprint\(64,"Would merge",source, "to", target) ##### Check if channels exist clist = ses.channel.listSoftwareChannels(key) source_exists = next((True for channel in clist if channel['label'] == source),False) target_exists = next((True for channel in clist if channel['label'] == target),False) clone_stat = 0 ##### stop if no source if not source_exists: dbg.dprint(0,"Cannot merge non existing",source) modlog.error(f"Cannot merge non existing {source}") dbg.setlvl() dbg.leavesub() return clone_stat ##### If clone is set, clone channel completely if channel does not yet exist, ##### otherwise merge packages, but clone errata if clone : dbg.dprint(64,"Clone:",clone, " ",source, "->", target) ##### Clone is set, but channel already exists if target_exists: dbg.dprint(64,"Channel exists, clone pkgs + errata") if test : dbg.dprint(64," - OK - Would merge packages and clone errata...") clone_stat = 1 else: ### get the missing errata srcerrata = ses.channel.software.listErrata(key,source) tgterrata = ses.channel.software.listErrata(key,target) srcnames = set(d['advisory_name'] for d in srcerrata) tgtnames = set(d['advisory_name'].replace('CL-','',1) for d in tgterrata) srconly = sorted(list(srcnames.difference(tgtnames))) dbg.dprint(64,"Missing Errata:",srconly) failure = 0 try: resultMP = ses.channel.software.mergePackages(key,source,target) dbg.dprint(64, "Packages merged :", len(resultMP)) modlog.info(f"Packages merged : {len(resultMP)}") except: dbg.dprint(256,"Merging Packages did not succeed") modlog.error("Merging Packages did not succeed") failure += 1 ### break patchlist into chunks chunknum = 0 chunk = [] for errnum in range(0,len(srconly)): if errnum // 10 == chunknum: chunk.append(srconly[errnum]) else : try: resultCE = ses.errata.clone(key,target,chunk) dbg.dprint(64, "Errata chunk ",chunknum, "cloned :", len(resultCE)) #modlog.info(f"Errata chunk {chunknum} cloned : {len(resultCE)}") except: dbg.dprint(256, "Errata chunk ",chunknum, "could not be cloned") modlog.error(f"Errata chunk {chunknum} could not be cloned") dbg.dprint(0, "chunk", chunknum, chunk) failure += 1 chunk = [] chunknum += 1 chunk.append(srconly[errnum]) ### proces last chunk if len(chunk): try: resultCE = ses.errata.clone(key,target,chunk) dbg.dprint(64, "Errata chunk ",chunknum, "cloned :", len(resultCE)) modlog.info(f"Errata chunk {chunknum} cloned : {len(resultCE)}") except: dbg.dprint(256, "Errata chunk ",chunknum, "could not be cloned") modlog.error(f"Errata chunk {chunknum} could not be cloned") dbg.dprint(0, "chunk", chunknum, chunk) failure += 1 if failure: dbg.dprint(256,"Merging packages or cloning errata did not succeed") modlog.error(f"Merging packages or cloning errata did not succeed") clone_stat = 0 else: result = f"Errata cloned : {len(srconly)}" dbg.dprint(64,result) modlog.info(f"{result}") clone_stat = 1 ##### clone is set, target does not exist else: srcdetails = ses.channel.software.getDetails(key,source) dbg.dprint(0,"Arch_label of source", srcdetails['arch_label']) ### only if parent is not "" and not existing create an empty parent if parent: parent_exists = next((True for channel in clist if channel['label'] == parent),False) if not parent_exists: dbg.dprint(0,"Targets parent does not exist") psumm = 'custom parent channel' parch = srcdetails['arch_label'] try: result = ses.channel.software.create(key,parent,parent,psumm,parch,"") dbg.dprint(64,"Parent Channel", parent, "created",result) modlog.info(f"Parent Channel {parent} created") except: err = "error exit: \"{0}\" in {1}".format(sys.exc_info()[1],sys.exc_info()[2:]) dbg.dprint(256,err) modlog.error(f"{err}") dbg.setlvl() dbg.leavesub() return clone_stat ### non empty parent was created details = { 'label' : target, 'name' : target, 'summary' : "Clone of "+source, 'description' : "Created at "+datetime.date.today().strftime("%Y-%m-%d"), 'parent_label' : parent, 'checksum' : srcdetails['checksum_label'], } try: result = ses.channel.software.clone(key,source,details,False) dbg.dprint(64,"Channel geclont mit der ID ",result) modlog.info(f"Channel geclont mit der ID {result}") clone_stat = 1 except: err = "error exit: \"{0}\" in {1}".format(sys.exc_info()[1],sys.exc_info()[2:]) dbg.dprint(256,err) modlog.error(f"{err}") dbg.dprint(256,"Could not clone",source,"to",target,"with Error") ##### Clone ist nicht gesetzt => nur mergen else: dbg.dprint(64,"Merge:",source,"->", target) if target_exists: dbg.dprint(64,"Channels ok, merge pkgs + errata:" ) if test: dbg.dprint(64," - OK - Would merge packages and errata...") clone_stat = 1 else: try: resultMP = ses.channel.software.mergePackages(key,source,target) dbg.dprint(64, "Packages merged :", len(resultMP)) modlog.info(f"Packages merged : {len(resultMP)}") resultME = ses.channel.software.mergeErrata(key,source,target) dbg.dprint(64, "Errata merged :", len(resultME)) modlog.info(f"Errata merged : {len(resultME)}") clone_stat = 1 except: err = "error exit: \"{0}\" in {1}".format(sys.exc_info()[1],sys.exc_info()[2:]) dbg.dprint(256,err) modlog.error(f"{err}") dbg.dprint(256,"Could not merge",target,"with Error") ##### Target does not exist else: dbg.dprint(0,"Cannot merge",source,"to non existing",target) modlog.error(f"Cannot merge {source} to non existing {target}") if test: dbg.dprint(64,"Would try to create new channel",target) clone_stat = 1 else: dbg.dprint(0,"Trying to create new channel:",target) try: archLabel = 'channel-' + target.split('-')[-1] summary = "Created from "+source clone_stat = ses.channel.software.create(key,target,target,summary,archLabel,parent) if clone_stat: dbg.dprint(0,"Channel Creation succeeded. Run again to merge channels!") modlog.warning("Channel Creation succeeded. Run again to merge channels!") except: dbg.dprint(256,"Could not create Channel",target) modlog.error(f"Could not create Channel {target}") ##### Cleanup and return status dbg.dprint(64,"----------- Status: ",clone_stat, " --------------------") #modlog.info(f"--- Status: {clone_stat}") dbg.setlvl() dbg.leavesub() return clone_stat
def get_pkg_difference(source,target): """ Get package difference between two software channels. """ from __main__ import dbg,prgargs,data dbg.entersub() ses = data['conn']['ses'] key = data['conn']['key'] #### Check if channels exist clist = ses.channel.listSoftwareChannels(key) source_exists = next((True for channel in clist if channel['label'] == source),False) target_exists = next((True for channel in clist if channel['label'] == target),False) if source_exists and target_exists: srclist = ses.channel.software.listAllPackages(key,source) tgtlist = ses.channel.software.listAllPackages(key,target) srcids = set(d['id'] for d in srclist) tgtids = set(d['id'] for d in tgtlist) srconly = list(srcids.difference(tgtids)) tgtonly = list(tgtids.difference(srcids)) for pkgnum in range(0,len(srconly)): pkgid = srconly[pkgnum] pkgdict = ses.packages.getDetails(key,pkgid) dbg.dprint(0, f"{pkgdict['name']:55} {pkgid:7d}") dbg.dprint(64, f" V: {pkgdict['version']:15}, R: {pkgdict['release']:10}, E: {pkgdict['epoch']}") dbg.dprint(128, f" Description: {pkgdict['description']}") dbg.leavesub() return ######### Maybe no longer needed after this line ? ############################################################################## ############################################################################## #def Clone_Channel(source,target,parent,**kwargs): # """ Create a new Channel with all content and errata from source channel to target # channel. All parameters are label strings. parent is the label of target's parent. # Only recognized keyword is checksum. # Returns 0 on failure else 1 # """ # from __main__ import dbg,prgargs,data # import sys # dbg.entersub() # dbg.dprint(2,"Start kwargs",kwargs,"End optional kwargs") # ses = data['conn']['ses'] # key = data['conn']['key'] # checksum = 'sha256' # if 'checksum' in kwargs: # checksum = kwargs['checksum'] # details = { # 'name' : target, # 'label' : target, # 'summary' : "Clone of "+source, # 'parent_label' : parent, # 'checksum' : checksum, # } # try: # ok = ses.channel.software.clone(key,source,details,False) # except: # dbg.dprint(0,"Could not clone channel", source, "to",target) # dbg.dprint(0,"error exit: \"{0}\" in {1}".format(sys.exc_info()[1],sys.exc_info()[2:] )) # dbg.dprint(0,"Could not clone Channel",target,"with Error:",xmlrpc.exc_info()[0]) # dbg.leavesub() # return(0) # else: # dbg.leavesub() # return(1) # ############################################################################## ############################################################################## #def Create_Channel(source,target,parent,*args): # """ Create a new empty Channel. Only useful for custom channels without errata. All # parameters are label strings. # Returns 0 on failure else 1 # """ # from __main__ import dbg,prgargs,data # import sys # dbg.entersub() # dbg.dprint(2,args) # ses = data['conn']['ses'] # key = data['conn']['key'] # archLabel = 'channel-' + target.split('-')[-1] # if source == '' and parent == '': # description = "custom parent channel" # else: # description = "Created from "+source # try: # ses.channel.software.create(key,target,target,description,archLabel,parent) # except: # if "already in use" in sys.exc_info()[2:]: # dbg.leavesub() # return(1) # else: # dbg.dprint(0,"Could not create channel", target) # dbg.dprint(0,"error exit: \"{0}\" in {1}".format(sys.exc_info()[1],sys.exc_info()[2:] )) # dbg.dprint(0,"Could not create Channel",target,"with Error:",sys.exc_info()[0]) # dbg.leavesub() # return(0) # else: # dbg.dprint(0,"Created channel", target) # # dbg.leavesub() # return(1) #