Beispiel #1
0
def ConcatPaths(pathList, *tail):
    # Convert string arg to list
    if IsString(pathList):
        pathList = [
            pathList,
        ]

    # Make sure we are working with a list instance
    pathList = list(pathList)

    # Append tail arguments
    if tail:
        pathList += tail

    # Clean up tail arguments
    for INDEX in range(len(pathList)):
        pathList[INDEX] = pathList[INDEX].strip(u'/')

    path = u'/'.join(pathList)

    while u'//' in path:
        path = path.replace(u'//', u'/')

    # FIXME: How to add 'absolute' argument with ambiguous arg count for 'tail'
    absolute = True
    if absolute and not path.startswith(u'/'):
        path = u'/' + path

    return path
Beispiel #2
0
    def __init__(self,
                 button,
                 label,
                 parent=None,
                 btnId=wx.ID_ANY,
                 size=32,
                 tooltip=None,
                 name=None,
                 showLabel=True):

        BoxSizer.__init__(self, wx.VERTICAL)

        if IsString(button):
            self.Button = CreateButton(parent, btnId, label, button, size,
                                       tooltip, name)

        else:
            self.Button = button

        self.Add(self.Button, 1, wx.ALIGN_CENTER)

        if isinstance(self.Button, CustomButton):
            if not label:
                label = self.Button.Name

            self.Label = wx.StaticText(self.Button.GetParent(), label=label)

            self.Add(self.Label, 0, wx.ALIGN_CENTER)

            self.Show(self.Label, showLabel)
Beispiel #3
0
	def Check(self):
		if self.Commands:
			enabled = True

			if IsString(self.Commands):
				# FIXME: CommandExists should return boolean
				#self.Enable(not not CommandExists(self.Commands))
				enabled = not not CommandExists(self.Commands)

			else:
				if self.RequireAll:
					for CMD in self.Commands:
						if not CommandExists(CMD):
							enabled = False

							break

				else:
					cmd_found = False
					for CMD in self.Commands:
						if CommandExists(CMD):
							cmd_found = True

							break

					enabled = cmd_found

			self.Enable(enabled)
Beispiel #4
0
    def LogMessage(self,
                   level,
                   module,
                   message,
                   details=[],
                   newline=False,
                   pout=sys.stdout):
        level = self.CheckLogLevel(level)

        # Use the object to retrieve module string
        if not IsString(module):
            module = GetModuleString(module)

        if (level in self.LogLevelList) and (level <= self.LogLevel):
            l_string = self.LogLevelList[level].upper()
            message = u'{}: [{}] {}'.format(l_string, module, message)

            if details:
                if IsString(details):
                    message += u'\n  • {}'.format(details)

                else:
                    for ITEM in details:
                        message += u'\n  • {}'.format(ITEM)

            if newline:
                message = u'\n{}'.format(message)

            # Message is shown in terminal
            if pout not in (
                    sys.stdout,
                    sys.stderr,
            ):
                print(message)

            else:
                # Need to manually add newline when using sys.stdout/sys.stderr
                pout.write(u'{}\n'.format(message))

            # Open log for writing
            AppendFile(self.LogFile, u'{}\n'.format(message), self.NoStrip)

            # Allow stripping leading & trailing newlines from opened log file
            if self.NoStrip:
                self.NoStrip = None
Beispiel #5
0
	def __init__(self, commands=None, requireAll=False):
		self.Commands = commands
		self.RequireAll = requireAll

		if commands:
			if IsString(self.Commands) and u' ' in self.Commands:
				self.Commands = self.Commands.split(u' ')
				self.Commands = RemoveEmptyLines(self.Commands)

		# Check for the commands when the object is constructed
		self.Check()
Beispiel #6
0
    def GetFileItem(self, item, target=None):
        if IsString(item):
            for FILE in self.FileItems:
                if FILE.GetPath() == item:
                    item = FILE

                    break

        elif isinstance(item, int):
            item = self.FileItems[item]

        if isinstance(item, FileItem):
            return item
Beispiel #7
0
	def GetFileItem(self, item):
		if IsString(item):
			for FILE in self.FileItems:
				if FILE.GetPath() == item:
					item = FILE

					break

		elif isinstance(item, int):
			item = self.FileItems[item]

		if not isinstance(item, FileItem):
			Logger.Warn(__name__, u'Could not convert to FileItem: {}'.format(item))
			return None

		return item
Beispiel #8
0
def GetIntTuple(value):
    if isinstance(value, (
            tuple,
            list,
    )):
        if len(value) > 1:
            # Convert to list in case we need to make changes
            value = list(value)

            for I in value:
                t_index = value.index(I)

                if isinstance(I, (tuple, list)):
                    I = GetIntTuple(I)

                else:
                    I = GetInteger(I)

                if I == None:
                    return None

                value[t_index] = I

            return tuple(value)

    elif IsString(value):
        # Remove whitespace & braces
        value = value.strip(u' ()')
        value = u''.join(value.split(u' '))

        value = value.split(u',')

        if len(value) > 1:
            for S in value:
                v_index = value.index(S)

                S = GetInteger(S)

                if S == None:
                    return None

                value[v_index] = S

            # Convert return value from list to tuple
            return tuple(value)

    return None
Beispiel #9
0
	def Reset(self):
		if isinstance(self, wx.Choice):
			if self.GetCount():
				if IsString(self.Default):
					self.SetStringSelection(self.Default)

					return self.StringSelection == self.Default

				else:
					self.SetSelection(self.Default)

					return self.Selection == self.Default

		elif isinstance(self, wx.ListCtrl):
			#  FIXME: What to do if default value is not 'None'
			if self.Default == None:
				return self.DeleteAllItems()

		else:
			self.SetValue(self.Default)
Beispiel #10
0
def GetInteger(value):
    if isinstance(value, (
            int,
            float,
    )):
        return int(value)

    # Will always use there very first value, even for nested items
    elif isinstance(value, (
            tuple,
            list,
    )):
        # Recursive check lists & tuples
        return GetInteger(value[0])

    elif value and IsString(value):
        # Convert because of unsupported methods in str class
        value = GS(value)

        if HasAlpha(value):
            return None

        # Check for negative
        if value[0] == u'-':
            if value.count(u'-') <= 1:
                value = GetInteger(value[1:])

                if value != None:
                    return -value

        # Check for tuple
        elif u'.' in value:
            value = value.split(u'.')[0]
            return GetInteger(value)

        elif StringIsNumeric(value):
            return int(value)

    return None
Beispiel #11
0
 def HasTarget(self):
     return IsString(self.Target) and not TextIsEmpty(self.Target)
Beispiel #12
0
	def HasOutputLabel(self):
		return IsString(self.OutputLabel) and self.OutputLabel != wx.EmptyString