コード例 #1
0
def _get_module_queue(yresults, result, scanObject, metaLabel):
    '''
    Description: Takes the results from a dispatch yara scan and creates a priority queue from them.
                 The function also adds dispatch flags if they exist in the rule.
    '''
    moduleQueue = Queue.PriorityQueue()
    dispatchFlags = []
    parentDispatchFlags = []

    for yr in yresults:
        if 'scan_modules' in yr.meta:
            # Check to see if the rule has a priority, if not use the default
            if 'priority' in yr.meta:
                priority = int(yr.meta['priority'])
                logging.debug("Rule %s set priority %i" % (yr, priority))
            else:
                priority = int(config.defaultmodulepriority)
            scanObject.addMetadata("DISPATCH", metaLabel,
                                   "%s (%i)" % (str(yr), priority))
            moduleQueue.put(
                (priority, uniqueList(yr.meta['scan_modules'].split())))
        if 'flags' in yr.meta:
            dispatchFlags.extend(yr.meta['flags'].split())
        if 'parent_flags' in yr.meta:
            parentDispatchFlags.extend(yr.meta['parent_flags'].split())
        if 'file_type' in yr.meta:
            scanObject.fileType.append(yr.meta['file_type'])
    dispatchFlags = set(dispatchFlags)
    for df in dispatchFlags:
        scanObject.addFlag("dispatch::%s" % (df))
    if scanObject.parent in result.files:
        for pdf in parentDispatchFlags:
            result.files[scanObject.parent].addFlag("dispatch::%s" % (pdf))

    return moduleQueue
コード例 #2
0
ファイル: getRel.py プロジェクト: ypapax/sublime_util
def getRel(str):
	"""Returns relative path list from str"""
	m = re.findall(r"['\"]([\.]{1,2}/.*)['\"]", str)
	unique = util.uniqueList(m)
	print('unique list: ', unique)

	return unique
コード例 #3
0
 def availableVoices():
     """a list of all voice directories"""
     if not Voice.__availableVoices:
         result = []
         directories = QStandardPaths.locateAll(
             QStandardPaths.AppDataLocation, 'voices',
             QStandardPaths.LocateDirectory)
         directories.insert(0, os.path.join('share', 'kajongg', 'voices'))
         for parentDirectory in directories:
             for (dirpath, _, _) in os.walk(parentDirectory,
                                            followlinks=True):
                 if os.path.exists(os.path.join(dirpath, 's1.ogg')):
                     result.append(Voice(dirpath))
         group = Internal.kajonggrc.group('Locale')
         prefLanguages = uniqueList(':'.join(
             ['local', str(group.readEntry('Language')),
              'en_US']).split(':'))
         prefLanguages = dict(
             (x[1], x[0]) for x in enumerate(prefLanguages))
         result = sorted(
             result, key=lambda x: prefLanguages.get(x.language(), 9999))
         if Debug.sound:
             logDebug('found voices:%s' % [str(x) for x in result])
         Voice.__availableVoices = result
     return Voice.__availableVoices
コード例 #4
0
ファイル: dispatch.py プロジェクト: ckuethe/laikaboss
def _get_module_queue(yresults, result, scanObject, metaLabel):
    """
    Description: Takes the results from a dispatch yara scan and creates a priority queue from them.
                 The function also adds dispatch flags if they exist in the rule.
    """
    moduleQueue = Queue.PriorityQueue()
    dispatchFlags = []
    parentDispatchFlags = []

    for yr in yresults:
        if "scan_modules" in yr.meta:
            # Check to see if the rule has a priority, if not use the default
            if "priority" in yr.meta:
                priority = int(yr.meta["priority"])
                logging.debug("Rule %s set priority %i" % (yr, priority))
            else:
                priority = int(config.defaultmodulepriority)
            scanObject.addMetadata("DISPATCH", metaLabel, "%s (%i)" % (str(yr), priority))
            moduleQueue.put((priority, uniqueList(yr.meta["scan_modules"].split())))
        if "flags" in yr.meta:
            dispatchFlags.extend(yr.meta["flags"].split())
        if "parent_flags" in yr.meta:
            parentDispatchFlags.extend(yr.meta["parent_flags"].split())
        if "file_type" in yr.meta:
            scanObject.fileType.append(yr.meta["file_type"])
    dispatchFlags = set(dispatchFlags)
    for df in dispatchFlags:
        scanObject.addFlag("dispatch::%s" % (df))
    if scanObject.parent in result.files:
        for pdf in parentDispatchFlags:
            result.files[scanObject.parent].addFlag("dispatch::%s" % (pdf))

    return moduleQueue
コード例 #5
0
ファイル: next3.py プロジェクト: ypapax/all_sublime_plugins
def get(fileNameList, fileNameWithLine, move):
    fileNameList = util.uniqueList(fileNameList)
    result = ""
    contains = any(fileNameWithLine in i for i in fileNameList)
    if (contains):
        index = fileNameList.index(fileNameWithLine)
        if (move=="prev"):
            index = index - 1
            if (index < 0):
                index = len(fileNameList)-1
        elif(move=="next"):    
            index = index + 1
            if (index >= len(fileNameList)):
                index = 0
        else:
            index = -1            

        result = fileNameList[index]
    else:
        (fileName, line) = fileNameWithLine.split(':')
   
        contains = any(fileName in i for i in fileNameList)
        if contains:
            result = [i for i in fileNameList if util.startsWith(i, fileName)][0]
        elif(len(fileNameList)):
            result = fileNameList[-1]
    

    return result
コード例 #6
0
ファイル: mi18n.py プロジェクト: zero804/kajongg
 def availableLanguages(cls):
     """see python lib, getdefaultlocale (which only returns the first one)"""
     localenames = [getdefaultlocale()[0]]
     for variable in ('LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG'):
         try:
             localename = os.environ[variable]
         except KeyError:
             continue
         else:
             if variable == 'LANGUAGE':
                 localenames.extend(localename.split(':'))
             else:
                 localenames.append(localename)
     if Debug.i18n:
         Internal.logger.debug('localenames: {}'.format(
             ','.join(localenames)))
     languages = list(
         _parse_localename(x)[0] for x in localenames if len(x))
     if Debug.i18n:
         Internal.logger.debug('languages: {}'.format(','.join(languages)))
     for resourceDir in cls.localeDirectories():
         for sysLanguage in sorted(os.listdir(resourceDir)):
             if cls.__isLanguageInstalledForKajongg(sysLanguage):
                 languages.append(sysLanguage)
     if languages:
         languages = uniqueList(cls.extendRegionLanguages(languages))
         languages = list(x for x in languages
                          if cls.isLanguageInstalled(x))
     if 'en_US' not in languages:
         languages.extend(['en_US', 'en'])
     if Debug.i18n:
         Internal.logger.debug('languages available: {}'.format(
             ':'.join(languages)))
     return ':'.join(languages)
コード例 #7
0
    def genInfo(self):
        output = util.compare_dictionaries(
            self.rawData,
            self.rawCompData)  # must use raw data, otherwise format error
        self.master = util.intOutString(output)
        print(self.master)

        for eachLine in self.master:
            if len(eachLine) is not 1:
                if eachLine[0] == '-':
                    self.oriColorTop.append(eachLine[1])
                elif eachLine[0] == '+':
                    self.compColorTop.append(eachLine[1])
                elif eachLine[0] == '!':
                    self.diffColorTop.append(eachLine[1])
                else:
                    print('error on master output')

        self.oriColorTop = util.uniqueList(self.oriColorTop)
        self.compColorTop = util.uniqueList(self.compColorTop)
        self.diffColorTop = util.uniqueList(self.diffColorTop)
コード例 #8
0
 def __init__(self, rulesets, title, parent=None):
     super(RuleModel, self).__init__(parent)
     self.rulesets = rulesets
     self.loaded = False
     unitNames = list()
     for ruleset in rulesets:
         ruleset.load()
         for rule in ruleset.allRules:
             unitNames.extend(rule.score.unitNames.items())
     unitNames = sorted(unitNames, key=lambda x: x[1])
     unitNames = uniqueList(x[0] for x in unitNames)
     rootData = [title]
     rootData.extend(unitNames)
     self.rootItem = RuleRootItem(rootData)
コード例 #9
0
ファイル: rulesetselector.py プロジェクト: KDE/kajongg
 def __init__(self, rulesets, title, parent=None):
     super(RuleModel, self).__init__(parent)
     self.rulesets = rulesets
     self.loaded = False
     unitNames = list()
     for ruleset in rulesets:
         ruleset.load()
         for rule in ruleset.allRules:
             unitNames.extend(rule.score.unitNames.items())
     unitNames = sorted(unitNames, key=lambda x: x[1])
     unitNames = uniqueList(x[0] for x in unitNames)
     rootData = [title]
     rootData.extend(unitNames)
     self.rootItem = RuleRootItem(rootData)
コード例 #10
0
 def tileAt(self, position):
     """find out which uiTile is clickable at this position. Always
     returns a list. If there are several tiles above each other,
     return all of them, highest first"""
     allTiles = [x for x in self.items(position) if isinstance(x, UITile)]
     items = [x for x in allTiles if self.__matchingTile(position, x)]
     if not items:
         return None
     for item in items[:]:
         for other in allTiles:
             if (other.xoffset, other.yoffset) == (item.xoffset, item.yoffset):
                 if other.level > item.level:
                     items.append(other)
     return uniqueList(sorted(items, key=lambda x: -x.level))
コード例 #11
0
ファイル: board.py プロジェクト: KDE/kajongg
 def tileAt(self, position):
     """find out which uiTile is clickable at this position. Always
     returns a list. If there are several tiles above each other,
     return all of them, highest first"""
     allTiles = [x for x in self.items(position) if isinstance(x, UITile)]
     items = [x for x in allTiles if self.__matchingTile(position, x)]
     if not items:
         return None
     for item in items[:]:
         for other in allTiles:
             if (other.xoffset, other.yoffset) == (item.xoffset, item.yoffset):
                 if other.level > item.level:
                     items.append(other)
     return uniqueList(sorted(items, key=lambda x: -x.level))
コード例 #12
0
def remove(text):
	lines = text.split('\n')
	removeList = []
	for i in lines:
		if (startsWithOk(i)):
			indexesFound = indexes(lines, i)
			if(len(indexesFound)>1):
				exceptFirstIndexes = indexesFound[1:]
				if(len(exceptFirstIndexes)):
					removeList.extend(exceptFirstIndexes)
	removeList = util.uniqueList(removeList)
	for r in removeList:

		del(lines[r])
	return str.join('\n', lines)
コード例 #13
0
ファイル: sound.py プロジェクト: ospalh/kajongg-fork
 def availableVoices():
     """a list of all voice directories"""
     if not Voice.__availableVoices and Internal.haveKDE:
         result = []
         for parentDirectory in KGlobal.dirs().findDirs("appdata", "voices"):
             parentDirectory = unicode(parentDirectory)
             for (dirpath, _, _) in os.walk(parentDirectory, followlinks=True):
                 if os.path.exists(os.path.join(dirpath, 's1.ogg')):
                     result.append(Voice(dirpath))
         config = KGlobal.config()
         group = KConfigGroup(config, 'Locale')
         prefLanguages = uniqueList(':'.join(['local', str(group.readEntry('Language')), 'en_uS']).split(':'))
         prefLanguages = dict((x[1], x[0]) for x in enumerate(prefLanguages))
         result = sorted(result, key=lambda x: prefLanguages.get(x.language(), 9999))
         if Debug.sound:
             logDebug('found voices:%s' % [str(x) for x in result])
         Voice.__availableVoices = result
     return Voice.__availableVoices
コード例 #14
0
 def availableVoices():
     """a list of all voice directories"""
     if not Voice.__availableVoices and Internal.haveKDE:
         result = []
         for parentDirectory in KGlobal.dirs().findDirs(
                 "appdata", "voices"):
             parentDirectory = unicode(parentDirectory)
             for (dirpath, _, _) in os.walk(parentDirectory,
                                            followlinks=True):
                 if os.path.exists(os.path.join(dirpath, 's1.ogg')):
                     result.append(Voice(dirpath))
         config = KGlobal.config()
         group = KConfigGroup(config, 'Locale')
         prefLanguages = uniqueList(':'.join(
             ['local', str(group.readEntry('Language')),
              'en_uS']).split(':'))
         prefLanguages = dict(
             (x[1], x[0]) for x in enumerate(prefLanguages))
         result = sorted(
             result, key=lambda x: prefLanguages.get(x.language(), 9999))
         if Debug.sound:
             logDebug('found voices:%s' % [str(x) for x in result])
         Voice.__availableVoices = result
     return Voice.__availableVoices