Exemplo n.º 1
0
    def __init__(self, item, path, label=None):
        if path == None:
            # So that calls to os.path.exists(PathItem.Path) do not raise exception
            path = wx.EmptyString

        self.Item = item
        self.Path = path
        self.Label = label
        self.Children = []
        self.Type = None

        if self.Path:
            self.Type = GetFileMimeType(self.Path)

            executables_binary = (u'x-executable', )

            executables_text = (
                u'x-python',
                u'x-shellscript',
            )

            # Don't use MIME type 'inode' for directories (symlinks are inodes)
            if os.path.isdir(self.Path):
                self.Type = u'folder'

            elif self.Type.startswith(u'image'):
                self.Type = u'image'

            elif self.Type.startswith(u'audio'):
                self.Type = u'audio'

            elif self.Type.startswith(u'video'):
                self.Type = u'video'

            else:
                # Exctract second part of MIME type
                self.Type = self.Type.split(u'/')[-1]

                if self.Type in executables_binary:
                    self.Type = u'executable-binary'

                elif self.Type in executables_text:
                    self.Type = u'executable-script'

            self.ImageIndex = ImageList.GetImageIndex(self.Type)

            # Use generic 'file' image as default
            if self.ImageIndex == ImageList.GetImageIndex(u'failsafe'):
                self.ImageIndex = ImageList.GetImageIndex(u'file')

            Logger.Debug(
                __name__,
                u'PathItem type: {} ({})'.format(self.Type, self.Path))
Exemplo n.º 2
0
    def AddFile(self, filename, sourceDir, targetDir=None, executable=False):
        list_index = self.GetItemCount()

        # Method can be called with two argements: absolute filename & target directory
        if targetDir == None:
            targetDir = sourceDir
            sourceDir = os.path.dirname(filename)
            filename = os.path.basename(filename)

        source_path = ConcatPaths((sourceDir, filename))

        Logger.Debug(__name__, GT(u'Adding file: {}').format(source_path))

        self.InsertStringItem(list_index, filename)
        self.SetStringItem(list_index, columns.SOURCE, sourceDir)
        self.SetStringItem(list_index, columns.TARGET, targetDir)
        self.SetStringItem(list_index, columns.TYPE,
                           GetFileMimeType(source_path))

        if os.path.isdir(source_path):
            self.SetItemTextColour(list_index, self.FOLDER_TEXT_COLOR)

        else:
            # TODO: Use 'GetFileMimeType' module to determine file type
            if os.access(source_path, os.X_OK) or executable:
                self.SetFileExecutable(list_index)

            if not os.path.isfile(source_path):
                self.SetItemBackgroundColour(list_index, COLOR_warn)

                # File was added but does not exist on filesystem
                return False

        return True
Exemplo n.º 3
0
	def __init__(self, item, path, label=None):
		if path == None:
			# So that calls to os.path.exists(PathItem.Path) do not raise exception
			path = wx.EmptyString

		self.Item = item
		self.Path = path
		self.Label = label
		self.Children = []
		self.Type = None

		if self.Path:
			self.Type = GetFileMimeType(self.Path)

			executables_binary = (
				u'x-executable',
				)

			executables_text = (
				u'x-python',
				u'x-shellscript',
				)

			# Don't use MIME type 'inode' for directories (symlinks are inodes)
			if os.path.isdir(self.Path):
				self.Type = u'folder'

			elif self.Type.startswith(u'image'):
				self.Type = u'image'

			elif self.Type.startswith(u'audio'):
				self.Type = u'audio'

			elif self.Type.startswith(u'video'):
				self.Type = u'video'

			else:
				# Exctract second part of MIME type
				self.Type = self.Type.split(u'/')[-1]

				if self.Type in executables_binary:
					self.Type = u'executable-binary'

				elif self.Type in executables_text:
					self.Type = u'executable-script'

			self.ImageIndex = ImageList.GetImageIndex(self.Type)

			# Use generic 'file' image as default
			if self.ImageIndex == ImageList.GetImageIndex(u'failsafe'):
				self.ImageIndex = ImageList.GetImageIndex(u'file')

			Logger.Debug(__name__, u'PathItem type: {} ({})'.format(self.Type, self.Path))
Exemplo n.º 4
0
    def SetChangelog(self):
        ## Defines where the changelog is located
        #
        #  By default it is located in the folder 'doc'
        #   under the applications root directory. The
        #   install script or Makefile should change this
        #   to reflect installed path.
        CHANGELOG = u'{}/docs/changelog'.format(PATH_app)

        if os.path.isfile(CHANGELOG):
            changelog_mimetype = GetFileMimeType(CHANGELOG)

            Logger.Debug(
                __name__,
                GT(u'Changelog mimetype: {}').format(changelog_mimetype))

            # Set log text in case of read error
            log_text = GT(u'Error reading changelog: {}\n\t').format(CHANGELOG)
            log_text = u'{}{}'.format(
                log_text,
                GT(u'Cannot decode, unrecognized mimetype: {}').format(
                    changelog_mimetype))

            if changelog_mimetype == u'text/plain':
                log_text = ReadFile(CHANGELOG)

            else:
                ShowErrorDialog(log_text, parent=self)

        else:
            log_text = GT(
                u'ERROR: Could not locate changelog file:\n\t\'{}\' not found'.
                format(CHANGELOG))

        self.changelog.SetValue(log_text)
        self.changelog.SetInsertionPoint(0)
Exemplo n.º 5
0
class PathItem:
    def __init__(self, item, path, label=None):
        if path == None:
            # So that calls to os.path.exists(PathItem.Path) do not raise exception
            path = wx.EmptyString

        self.Item = item
        self.Path = path
        self.Label = label
        self.Children = []
        self.Type = None

        if self.Path:
            self.Type = GetFileMimeType(self.Path)

            executables_binary = (u'x-executable', )

            executables_text = (
                u'x-python',
                u'x-shellscript',
            )

            # Don't use MIME type 'inode' for directories (symlinks are inodes)
            if os.path.isdir(self.Path):
                self.Type = u'folder'

            elif self.Type.startswith(u'image'):
                self.Type = u'image'

            elif self.Type.startswith(u'audio'):
                self.Type = u'audio'

            elif self.Type.startswith(u'video'):
                self.Type = u'video'

            else:
                # Exctract second part of MIME type
                self.Type = self.Type.split(u'/')[-1]

                if self.Type in executables_binary:
                    self.Type = u'executable-binary'

                elif self.Type in executables_text:
                    self.Type = u'executable-script'

            self.ImageIndex = ImageList.GetImageIndex(self.Type)

            # Use generic 'file' image as default
            if self.ImageIndex == ImageList.GetImageIndex(u'failsafe'):
                self.ImageIndex = ImageList.GetImageIndex(u'file')

            Logger.Debug(
                __name__,
                u'PathItem type: {} ({})'.format(self.Type, self.Path))

    ## TODO: Doxygen
    def AddChild(self, item):
        self.Children.append(item)

    ## TODO: Doxygen
    def ContainsInstance(self, item):
        return self.Item == item

    ## TODO: Doxygen
    def GetBaseItem(self):
        return self.Item

    ## TODO: Doxygen
    def GetChildren(self):
        return self.Children

    ## TODO: Doxygen
    def GetLabel(self):
        return self.Label

    ## TODO: Doxygen
    def GetPath(self):
        return self.Path

    ## TODO: Doxygen
    #
    #  FIXME: Should return boolean
    def HasChildren(self):
        return self.Children

    ## Checks if this is a child of another PathItem instance
    #
    #  \param item
    #	\b \e PathItem instance to check against
    #  \return
    #	True if self instance found in item children
    def IsChildOf(self, item):
        for CHILD in item.Children:
            if CHILD == self:
                return True

        return False

    ## TODO: Doxygen
    def IsDir(self):
        return os.path.isdir(self.Path)

    ## TODO: Doxygen
    def IsFile(self):
        return os.path.isfile(self.Path)

    ## TODO: Doxygen
    def RemoveChildren(self):
        self.Children = []

        return not self.Children

    ## TODO: Doxygen
    def SetChildren(self, items):
        self.Children = items

        return self.Children == items

    ## TODO: Doxygen
    def SetItem(self, item, path):
        self.Item = item
        self.Item.Path = path
Exemplo n.º 6
0
class PathItem:
	def __init__(self, item, path, label=None):
		if path == None:
			# So that calls to os.path.exists(PathItem.Path) do not raise exception
			path = wx.EmptyString

		self.Item = item
		self.Path = path
		self.Label = label
		self.Children = []
		self.Type = None

		if self.Path:
			self.Type = GetFileMimeType(self.Path)

			executables_binary = (
				u'x-executable',
				)

			executables_text = (
				u'x-python',
				u'x-shellscript',
				)

			# Don't use MIME type 'inode' for directories (symlinks are inodes)
			if os.path.isdir(self.Path):
				self.Type = u'folder'

			elif self.Type.startswith(u'image'):
				self.Type = u'image'

			elif self.Type.startswith(u'audio'):
				self.Type = u'audio'

			elif self.Type.startswith(u'video'):
				self.Type = u'video'

			else:
				# Exctract second part of MIME type
				self.Type = self.Type.split(u'/')[-1]

				if self.Type in executables_binary:
					self.Type = u'executable-binary'

				elif self.Type in executables_text:
					self.Type = u'executable-script'

			self.ImageIndex = ImageList.GetImageIndex(self.Type)

			# Use generic 'file' image as default
			if self.ImageIndex == ImageList.GetImageIndex(u'failsafe'):
				self.ImageIndex = ImageList.GetImageIndex(u'file')

			Logger.Debug(__name__, u'PathItem type: {} ({})'.format(self.Type, self.Path))


	## TODO: Doxygen
	def AddChild(self, item):
		self.Children.append(item)


	## TODO: Doxygen
	def ContainsInstance(self, item):
		return self.Item == item

	## TODO: Doxygen
	def GetBaseItem(self):
		return self.Item


	## TODO: Doxygen
	def GetChildren(self):
		return self.Children


	## TODO: Doxygen
	def GetLabel(self):
		return self.Label


	## TODO: Doxygen
	def GetPath(self):
		return self.Path


	## TODO: Doxygen
	#
	#  FIXME: Should return boolean
	def HasChildren(self):
		return self.Children


	## Checks if this is a child of another PathItem instance
	#
	#  \param item
	#	\b \e PathItem instance to check against
	#  \return
	#	True if self instance found in item children
	def IsChildOf(self, item):
		for CHILD in item.Children:
			if CHILD == self:
				return True

		return False


	## TODO: Doxygen
	def IsDir(self):
		return os.path.isdir(self.Path)


	## TODO: Doxygen
	def IsFile(self):
		return os.path.isfile(self.Path)


	## TODO: Doxygen
	def RemoveChildren(self):
		self.Children = []

		return not self.Children


	## TODO: Doxygen
	def SetChildren(self, items):
		self.Children = items

		return self.Children == items


	## TODO: Doxygen
	def SetItem(self, item, path):
		self.Item = item
		self.Item.Path = path
Exemplo n.º 7
0
    def SetChangelog(self):
        ## Defines where the changelog is located
        #
        #  By default it is located in the folder 'doc'
        #   under the applications root directory. The
        #   install script or Makefile should change this
        #   to reflect installed path.
        if INSTALLED:
            # FIXME: Read compressed .gz changelog
            CHANGELOG = u'{}/share/doc/debreate/changelog.gz'.format(PREFIX)

        else:
            CHANGELOG = u'{}/docs/changelog'.format(PREFIX)

        if os.path.isfile(CHANGELOG):
            changelog_mimetype = GetFileMimeType(CHANGELOG)

            Logger.Debug(
                __name__,
                GT(u'Changelog mimetype: {}').format(changelog_mimetype))

            # Set log text in case of read error
            log_text = GT(u'Error reading changelog: {}\n\t').format(CHANGELOG)
            log_text = u'{}{}'.format(
                log_text,
                GT(u'Cannot decode, unrecognized mimetype: {}').format(
                    changelog_mimetype))

            if changelog_mimetype == u'application/gzip':
                temp_dir = CreateStage()

                shutil.copy(CHANGELOG, temp_dir)

                CMD_gzip = GetExecutable(u'gzip')

                if CMD_gzip:
                    prev_dir = os.getcwd()
                    os.chdir(temp_dir)

                    gzip_output = commands.getstatusoutput(u'{} -fd {}'.format(
                        CMD_gzip, os.path.basename(CHANGELOG)))

                    Logger.Debug(
                        __name__,
                        GT(u'gzip decompress; Code: {}, Output: {}').format(
                            gzip_output[0], gzip_output[1]))

                    os.chdir(prev_dir)

                changelog_file = os.path.basename(CHANGELOG).split(u'.')[0]
                changelog_file = u'{}/{}'.format(temp_dir, changelog_file)

                if os.path.isfile(changelog_file):
                    log_text = ReadFile(changelog_file)

                RemoveStage(temp_dir)

            elif changelog_mimetype == u'text/plain':
                log_text = ReadFile(CHANGELOG)

            else:
                ShowErrorDialog(log_text, parent=self)

        else:
            log_text = GT(
                u'ERROR: Could not locate changelog file:\n\t\'{}\' not found'.
                format(CHANGELOG))

        self.changelog.SetValue(log_text)
        self.changelog.SetInsertionPoint(0)
Exemplo n.º 8
0
    def ProjectOpen(self, project_file=None):
        Logger.Debug(__name__, u'Opening project: {}'.format(project_file))

        # Need to show file open dialog because no project file was specified
        if not project_file:
            wc_z = GetDialogWildcards(ID_PROJ_Z)
            wc_l = GetDialogWildcards(ID_PROJ_L)
            wc_a = GetDialogWildcards(ID_PROJ_A)
            wc_t = GetDialogWildcards(ID_PROJ_T)

            wildcards = (
                wc_a[0],
                wc_a[1],
                wc_z[0],
                wc_z[1],
                wc_t[0],
                wc_t[1],
                wc_l[0],
                wc_l[1],
            )

            open_dialog = GetFileOpenDialog(self, GT(u'Open Debreate Project'),
                                            wildcards)
            if not ShowDialog(open_dialog):
                return dbrerrno.ECNCLD

            # Get the path and set the saved project
            project_file = open_dialog.GetPath()

        # Failsafe check that file exists
        if not os.path.isfile(project_file):
            err_l1 = GT(u'Cannot open project:')
            err_details = GT(u'File does not exist')

            ShowErrorDialog(u'{} {}'.format(err_l1, project_file), err_details)

            return dbrerrno.ENOENT

        # Check for unsaved changes & reset project to defaults
        if not self.ProjectClose():
            return dbrerrno.ECNCLD

        mime_type = GetFileMimeType(project_file)

        Logger.Debug(__name__, GT(u'Project mime type: {}').format(mime_type))

        opened = None
        if mime_type == u'text/plain':
            p_text = ReadFile(project_file)

            filename = os.path.split(project_file)[1]

            # Legacy projects should return None since we can't save in that format
            opened = self.ProjectOpenLegacy(p_text, filename)

        else:
            opened = self.ProjectOpenArchive(project_file, mime_type)

        Logger.Debug(
            __name__,
            GT(u'Project loaded before OnProjectOpen: {}').format(
                self.ProjectIsLoaded()))

        if opened == dbrerrno.SUCCESS:
            self.LoadedProject = project_file

            # Set project 'unmodified' for newly opened project
            self.ProjectSetDirty(False)

        Logger.Debug(
            __name__,
            GT(u'Project loaded after OnOpenPreject: {}').format(
                self.ProjectIsLoaded()))

        if DebugEnabled() and self.ProjectIsLoaded():
            Logger.Debug(__name__,
                         GT(u'Loaded project: {}').format(self.LoadedProject))

        return opened