コード例 #1
0
	def ImportExes(self, event=None):
		event_id = event.GetId()
		if event_id == btnid.IMPORT:
			# First clear the Auto-Link display and the executable list
			self.Executables.Reset()

			# Get executables from "files" tab
			file_list = GetField(pgid.FILES, inputid.LIST)

			for INDEX in range(file_list.GetItemCount()):
				# Get the filename from the source
				file_name = file_list.GetFilename(INDEX, basename=True)
				file_path = file_list.GetPath(INDEX)
				# Where the file linked to will be installed
				file_target = file_list.GetItem(INDEX, 1)

				# Walk directory to find executables
				if file_list.IsDirectory(INDEX):
					for EXE in GetFiles(file_path, os.X_OK):
						self.Executables.Append(FileItem(EXE, file_target))

				# Search for executables (distinguished by red text)
				elif file_list.IsExecutable(INDEX):
					try:
						# If destination doesn't start with "/" do not include executable
						if file_target.GetText()[0] == u'/':
							if file_target.GetText()[-1] == u'/' or file_target.GetText()[-1] == u' ':
								# In case the full path of the destination is "/" keep going
								if len(file_target.GetText()) == 1:
									dest_path = u''

								else:
									search = True
									# Set the number of spaces to remove from dest path in case of multiple "/"
									slashes = 1
									while search:
										# Find the number of slashes/spaces at the end of the filename
										endline = slashes - 1
										if file_target.GetText()[-slashes] == u'/' or file_target.GetText()[-slashes] == u' ':
											slashes += 1

										else:
											dest_path = file_target.GetText()[:-endline]
											search = False

							else:
								dest_path = file_target.GetText()

							self.Executables.Append(file_name, dest_path)

						else:
							Logger.Warn(__name__, u'{}: The executables destination is not valid'.format(__name__))

					except IndexError:
						Logger.Warn(__name__, u'{}: The executables destination is not available'.format(__name__))

		elif event_id in (btnid.REMOVE, wx.WXK_DELETE):
			self.Executables.RemoveSelected()
コード例 #2
0
ファイル: scripts.py プロジェクト: RogueScholar/debreate
    def ImportExes(self, event=None):
        event_id = event.GetId()
        if event_id == btnid.IMPORT:
            # First clear the Auto-Link display and the executable list
            self.Executables.Reset()

            file_list = GetField(pgid.FILES, inputid.LIST)
            exe_list = file_list.GetExecutables(False)

            for EXE in exe_list:
                INDEX = file_list.GetIndex(EXE)

                # Get the filename from the source
                file_name = file_list.GetFilename(INDEX)
                #file_name = EXE.GetBasename()
                # Where the file linked to will be installed
                # FIXME: FileItem.GetTarget() is not accurate
                file_target = file_list.GetTarget(EXE)

                self.Executables.Add(
                    FileItem(file_name,
                             ConcatPaths(file_target, file_name),
                             ignore_timestamp=True))

            # retrieve nested executables
            # FIXME: symlinks may cause problems here
            for FITEM in file_list.GetFileItems():
                if FITEM.IsDirectory():
                    # recurse into subdirectories
                    toplevel = FITEM.GetPath()
                    for ROOT, DIRS, FILES in os.walk(toplevel):
                        for FILE in FILES:
                            fullpath = ConcatPaths(ROOT, FILE)
                            DIR = os.path.dirname(
                                fullpath[len(toplevel):]).strip(u'/')
                            relpath = ConcatPaths(FITEM.GetBasename(), DIR,
                                                  FILE).strip(u'/')

                            if os.path.isfile(fullpath) and os.access(
                                    fullpath, os.X_OK):
                                fulltarget = ConcatPaths(
                                    FITEM.GetTarget(), relpath)

                                # check if item is already added to list
                                duplicate = False
                                for EXE in exe_list:
                                    existingtarget = ConcatPaths(
                                        EXE.GetTarget(),
                                        file_list.GetFilename(EXE))
                                    if fulltarget == existingtarget:
                                        duplicate = True
                                        break

                                if duplicate:
                                    Logger.Warn(
                                        __name__,
                                        u'Not adding executable with duplicate target: {}'
                                        .format(fulltarget))
                                    continue

                                Logger.Debug(
                                    __name__,
                                    u'Adding nested executable: {}'.format(
                                        relpath))
                                self.Executables.Add(
                                    FileItem(relpath,
                                             ConcatPaths(
                                                 FITEM.GetTarget(), relpath),
                                             ignore_timestamp=True))

        elif event_id in (btnid.REMOVE, wx.WXK_DELETE):
            self.Executables.RemoveSelected()