def _display(self, colour): from Ganga.Utility.ColourText import ANSIMarkup, NoMarkup, Foreground, Effects if colour: markup = ANSIMarkup() else: markup = NoMarkup() fg = Foreground() from cStringIO import StringIO sio = StringIO() sio.write("Ganga Configuration" + '\n') sections = sorted(stripProxy(self).keys()) maxcol = 0 for p in sections: if len(p) > maxcol: maxcol = len(p) if maxcol > 50: maxcol = 50 for p in sections: sio.write('%-*s : %s' % (maxcol, p, markup( stripProxy(self)[p].docstring.split( '\n')[0], fg.boldgrey)) + '\n') return sio.getvalue()
def _display(self, interactive=0): from Ganga.Utility.ColourText import ANSIMarkup, NoMarkup if interactive: markup = ANSIMarkup() else: markup = NoMarkup() dirs = self.listdirs() cnt = len(dirs) ds = "\n[Folders]: %d\n" % cnt if cnt > 0: ds += "--------------\n" for d in dirs: ds += "%s\n" % d jobs = self.getjobs() ds += "[Jobs]: %d\n" % len(jobs) if len(jobs) > 0: ds += "--------------\n" ds += jobs._display(interactive) return ds
from GangaAtlas.Lib.ATLASDataset.DQ2Dataset import DQ2Dataset from Ganga.GPIDev.Lib.Tasks.common import * from Ganga.GPIDev.Lib.Tasks import Task from MultiTransform import MultiTransform from Ganga.Utility.ColourText import overview_colours, ANSIMarkup, fgcol, Effects markup = ANSIMarkup() fx = Effects() from Ganga.Core.exceptions import ApplicationConfigurationError from GangaAtlas.Lib.ATLASDataset.DQ2Dataset import dq2_lock, dq2 from GangaAtlas.Lib.Credentials.ProxyHelper import getNickname from dq2.clientapi.DQ2 import DQ2, DQUnknownDatasetException, DQDatasetExistsException, DQFileExistsInDatasetException, DQInvalidRequestException from dq2.container.exceptions import DQContainerAlreadyHasDataset, DQContainerDoesNotHaveDataset from dq2.common.DQException import DQException from Ganga.GPIDev.Schema import * import copy o = [""] def c(s): return markup(s, fgcol("blue")) o.append(markup(" *** Task for Multiple Athena Analyses ***", fgcol("blue"))) #o.append(" Analysis Application : "+c("t.analysis.application")) #o.append(" Set Dataset : "+c("t.setDataset('my.dataset')")) #o.append(" Input Dataset Object : "+c("t.analysis.inputdata"))
def _display(self, interactive=0): """Prints content of the shareref metadata in a well formatted way. """ if len(self.__getName()) > 0: from Ganga.GPIDev.Lib.File import getSharedPath fstring = " %48s | %20s | %15s" disp_string = fstring % ("Shared directory", "Date created", "Reference count\n") # print fstring % (" ", " "," ") disp_string += fstring % ( "------------------------------------------------", "--------------------", "---------------\n") zero_ref = False unsorted = [] all_elements = copy.deepcopy(self.__getName()) for element in all_elements: full_shareddir_path = os.path.join(getSharedPath(), os.path.basename(element)) if os.path.isdir(full_shareddir_path): unsorted.append( shareref_data( os.path.basename(element), int(os.path.getctime(full_shareddir_path)), self.__getName()[element])) else: unsorted.append( shareref_data(os.path.basename(element), "Directory not found", self.__getName()[element])) decorated = sorted( (name.date, i, name) for i, name in enumerate(unsorted)) sorted_refs = [name for date, i, name in decorated] for line in sorted_refs: if isinstance(line.date, int): tmp_string = fstring % ( os.path.basename(line.name), time.strftime("%d %b %Y %H:%M:%S", time.localtime(line.date)), line.counter) else: tmp_string = fstring % (os.path.basename( line.name), line.date, line.counter) if (line.counter == 0) or (isinstance(line.date, str)): from Ganga.Utility.ColourText import ANSIMarkup, NoMarkup, Foreground, Background, Effects fg = Foreground() fg = Background() fx = Effects() if interactive: m = ANSIMarkup() else: m = NoMarkup() disp_string += fg.red + tmp_string + fx.normal + '\n' #disp_string += m(tmp_string,code=fg.red) if (line.counter == 0): zero_ref = True else: disp_string += tmp_string + '\n' disp_string += "\nThe shared directory repository is rooted at " + \ getSharedPath() + "\n" if zero_ref: disp_string += "\nShared directories with a zero reference count will be removed when Ganga exits.\n" else: disp_string = "No objects stored in the shared directory." return disp_string
def _display(self, colour): from Ganga.Utility.ColourText import ANSIMarkup, NoMarkup, getColour, Foreground, Effects if colour: markup = ANSIMarkup() else: markup = NoMarkup() fg = Foreground() display_config = getConfig('Display') name_colour = getColour(display_config['config_name_colour']) docstring_colour = getColour( display_config['config_docstring_colour']) # fg.boldgrey value_colour = getColour( display_config['config_value_colour']) # fx.normal levels = ['**', '* ', ' '] levels = map(lambda x: markup(x, fg.red), levels) from cStringIO import StringIO sio = StringIO() sio.write('%s' % markup(stripProxy(self).name, name_colour) + ' : ' + markup(stripProxy(self).docstring, docstring_colour) + '\n') opts = sorted(stripProxy(self).options.keys()) INDENT = ' ' * 2 p = re.compile('[\.\w]*\.') for o in opts: sio.write( levels[stripProxy(self).getEffectiveLevel(o)] + ' ' + markup(o, name_colour) + ' = ' + markup(p.sub('', repr(stripProxy(self)[o])), value_colour) + '\n') sio.write( textwrap.fill(markup( stripProxy(self).options[o].docstring.strip(), docstring_colour), width=80, initial_indent=INDENT, subsequent_indent=INDENT) + '\n') typelist = stripProxy(self).options[o].typelist if not typelist: typedesc = 'Type: ' + \ p.sub('',str(type(stripProxy(self).options[o].default_value))) else: typedesc = 'Allowed types: ' + \ str([p.sub('',str(t)) for t in typelist]) sio.write(markup(INDENT + typedesc, docstring_colour) + '\n') filter = stripProxy(self).options[o].filter if filter: filter_doc = filter.__doc__ if not filter_doc: filter_doc = "undocumented" sio.write( markup(INDENT + "Filter: " + filter_doc, docstring_colour) + '\n') examples = stripProxy(self).options[o].examples if examples: sio.write( markup(INDENT + "Examples:", docstring_colour) + '\n') for e in examples.splitlines(): sio.write( markup(INDENT + e.strip(), docstring_colour) + '\n') return sio.getvalue()
def _display(self, interactive=0): from Ganga.Utility.ColourText import ANSIMarkup, NoMarkup, Effects if interactive: markup = ANSIMarkup() else: markup = NoMarkup() # default column width default_width = 10 cnt = len(self) ds = "Registry Slice: %s (%d objects)\n" % (self.name, cnt) this_format = "#" flist = [] for d in self._display_columns: width = self._display_columns_width.get(d, default_width) flist.append("%" + str(width) + "s ") #this_format += "%"+str(width)+"s " this_format = "|".join(flist) this_format += "\n" if cnt > 0: ds += "--------------\n" ds += this_format % self._display_columns ds += "-" * len( this_format % tuple([""] * len(self._display_columns))) + "\n" for obj_i in self.objects.keys(): cached_data = None if isType(self.objects, SubJobXMLList): cached_data = self.objects.getCachedData(obj_i) colour = self._getColour(cached_data) else: obj = stripProxy(self.objects[obj_i]) colour = self._getColour(obj) vals = [] for item in self._display_columns: display_str = "display:" + str(item) #logger.info("Looking for : %s" % display_str) width = self._display_columns_width.get(item, default_width) try: if not isType(self.objects, SubJobXMLList): obj = stripProxy(self.objects[obj_i]) if item == "fqid": vals.append( str( stripProxy(obj).getNodeIndexCache() [display_str])) else: vals.append( str( stripProxy(obj).getNodeIndexCache() [display_str])[0:width]) else: if item == 'fqid': vals.append(str(cached_data[display_str])) else: vals.append(str(cached_data[display_str])[0:width]) continue except KeyError as err: logger.debug("_display KeyError: %s" % str(err)) pass if item == "fqid": vals.append(self._get_display_value(obj, item)) else: vals.append(self._get_display_value(obj, item)[0:width]) ds += markup(this_format % tuple(vals), colour) return ds
def list_cached_files(self, loop=True, opts=''): """ Lists the uploaded files. if loop = True, it prints also the uploaded files associated with subjobs. """ fc = 0 ds = '' doColoring = True fg = Foreground() fx = Effects() status_colors = {'inuse': fg.orange, 'free': fg.blue, 'gone': fg.red} status_mapping = { 'new': 'inuse', 'submitted': 'inuse', 'submitting': 'inuse', 'running': 'inuse', 'completed': 'free', 'completing': 'free', 'failed': 'free', 'killed': 'free' } if doColoring: markup = ANSIMarkup() else: markup = NoMarkup() def __markup_by_status__(fileIndex, counter, status): fmtStr = '\n%4d\t%-30s\t%-12s\t%s' % (counter, fileIndex.name, status, fileIndex.id) try: return markup(fmtStr, status_colors[status]) except KeyError: return markup(fmtStr, fx.normal) j = self.getJobObject() for f in self.get_cached_files(opts=opts): my_status = 'unknown' if j: try: my_status = status_mapping[j.status] except KeyError: pass ds += __markup_by_status__(f, fc, my_status) fc += 1 if j and loop: for sj in j.subjobs: for f in sj.backend.sandboxcache.get_cached_files(opts=opts): my_status = 'unknown' try: my_status = status_mapping[sj.status] except KeyError: pass ds += __markup_by_status__(f, fc, my_status) fc += 1 return ds
def _display(self, interactive=0): from Ganga.Utility.ColourText import ANSIMarkup, NoMarkup, Effects if interactive: markup = ANSIMarkup() else: markup = NoMarkup() # default column width default_width = 10 cnt = len(self) ds = "Registry Slice: %s (%d objects)\n" % (self.name, cnt) this_format = "#" flist = [] for d in self._display_columns: width = self._display_columns_width.get(d, default_width) flist.append("%" + str(width) + "s ") #this_format += "%"+str(width)+"s " this_format = "|".join(flist) this_format += "\n" if cnt > 0: ds += "--------------\n" ds += this_format % self._display_columns ds += "-" * len( this_format % tuple([""] * len(self._display_columns))) + "\n" if hasattr(self.objects, '_private_display'): ds += self.objects._private_display(self, this_format, default_width, markup) else: for obj_i in self.ids(): if isinstance(self.objects[obj_i], IncompleteObject): continue cached_data = None reg_object = self.objects[obj_i] obj = stripProxy(reg_object) colour = self._getColour(obj) vals = [] for item in self._display_columns: display_str = "display:" + str(item) #logger.info("Looking for : %s" % display_str) width = self._display_columns_width.get( item, default_width) try: if item == "fqid": vals.append(str(obj._index_cache[display_str])) else: vals.append( str(obj._index_cache[display_str])[0:width]) continue except KeyError as err: logger.debug("_display KeyError: %s" % err) #pass if item == "fqid": vals.append(self._get_display_value(obj, item)) else: vals.append( self._get_display_value(obj, item)[0:width]) ds += markup(this_format % tuple(vals), colour) return ds