Exemplo n.º 1
0
	def ImportFromFile(self, filename):
		Logger.Debug(__name__, GT(u'Importing script: {}').format(filename))

		script_name = filename.split(u'-')[-1]
		script_object = None

		for DS, RB in self.script_objects:
			if script_name == DS.GetFilename():
				script_object = DS

				break

		# Loading the actual text
		# FIXME: Should be done in class method
		if script_object != None:
			script_data = ReadFile(filename, split=True, convert=list)

			# FIXME: this should be global variable
			shebang = u'/bin/bash'

			remove_indexes = 0

			if u'#!' == script_data[0][:2]:
				shebang = script_data[0][2:]
				script_data.remove(script_data[0])

			# Remove empty lines from beginning of script
			for L in script_data:
				if not TextIsEmpty(L):
					break

				remove_indexes += 1

			for I in reversed(range(remove_indexes)):
				script_data.remove(script_data[I])

			script_data = u'\n'.join(script_data)

			script_object.SetShell(shebang, True)
			script_object.SetValue(script_data)
Exemplo n.º 2
0
 def ImportFromFile(self, filename):
     if not os.path.isfile(filename):
         return dbrerrno.ENOENT
     
     copyright_data = ReadFile(filename, split=True)
     
     # Remove preceding empty lines
     remove_index = 0
     for I in copyright_data:
         if not TextIsEmpty(I):
             break
         
         remove_index += 1
     
     for I in reversed(range(remove_index)):
         copyright_data.remove(copyright_data[I])
     
     copyright_data = u'\n'.join(copyright_data)
     
     self.dsp_copyright.SetValue(copyright_data)
     
     return 0
Exemplo n.º 3
0
	def ImportFromFile(self, filename):
		if not os.path.isfile(filename):
			return dbrerrno.ENOENT

		copyright_data = ReadFile(filename, split=True)

		# Remove preceding empty lines
		remove_index = 0
		for I in copyright_data:
			if not TextIsEmpty(I):
				break

			remove_index += 1

		for I in reversed(range(remove_index)):
			copyright_data.remove(copyright_data[I])

		copyright_data = u'\n'.join(copyright_data)

		self.dsp_copyright.SetValue(copyright_data)

		return 0
Exemplo n.º 4
0
	def ImportFromFile(self, filename):
		Logger.Debug(__name__, GT(u'Importing page info from {}').format(filename))

		if not os.path.isfile(filename):
			return dbrerrno.ENOENT

		menu_data = ReadFile(filename, split=True, convert=list)

		if u'[Desktop Entry]' in menu_data[0]:
			menu_data.remove(menu_data[0])

		menu_definitions = {}
		unused_raw_lines = []

		for L in menu_data:
			if u'=' in L:
				key = L.split(u'=')
				value = key[-1]
				key = key[0]

				menu_definitions[key] = value

				continue

			# Any unrecognizable lines will be added to "Other" section
			unused_raw_lines.append(L)


		def set_value(option):
			key = option.GetName()
			value = None

			if key in menu_definitions:
				value = menu_definitions[key]

				if not TextIsEmpty(value):
					if option in self.opts_input:
						option.SetValue(value)
						return True

					elif option in self.opts_choice:
						if option.SetStringSelection(value):
							return True

					elif option in self.opts_list:
						lst_categories = GetField(self, listid.CAT)

						if key == lst_categories.GetName():
							value = value.split(u';')

							if value:
								for X, val in enumerate(value):
									lst_categories.InsertStringItem(X, val)
								return True

			return False

		categories_used = []

		for group in self.opts_input, self.opts_choice, self.opts_list:
			for O in group:
				if set_value(O):
					categories_used.append(O.GetName())


		# List of keys that can be ignored if unused
		bypass_unused = (
			u'Version',
		)

		categories_unused = []
		for key in menu_definitions:
			if key not in categories_used and key not in bypass_unused:
				categories_unused.append(u'{}={}'.format(key, menu_definitions[key]))

		categories_unused += unused_raw_lines
		if len(categories_unused):
			categories_unused = u'\n'.join(categories_unused)

			#self.ti_other.SetValue(categories_unused)

		return 0
Exemplo n.º 5
0
    def ImportFromFile(self, filename):
        Logger.Debug(__name__,
                     GT(u'Importing page info from {}').format(filename))

        if not os.path.isfile(filename):
            return dbrerrno.ENOENT

        menu_data = ReadFile(filename, split=True, convert=list)

        if u'[Desktop Entry]' in menu_data[0]:
            menu_data.remove(menu_data[0])

        menu_definitions = {}
        unused_raw_lines = []

        for L in menu_data:
            if u'=' in L:
                key = L.split(u'=')
                value = key[-1]
                key = key[0]

                menu_definitions[key] = value

                continue

            # Any unrecognizable lines will be added to "Other" section
            unused_raw_lines.append(L)

        def set_value(option):
            key = option.GetName()
            value = None

            if key in menu_definitions:
                value = menu_definitions[key]

                if not TextIsEmpty(value):
                    if option in self.opts_input:
                        option.SetValue(value)
                        return True

                    elif option in self.opts_choice:
                        if option.SetStringSelection(value):
                            return True

                    elif option in self.opts_list:
                        lst_categories = GetField(self, listid.CAT)

                        if key == lst_categories.GetName():
                            value = value.split(u';')

                            if value:
                                for X, val in enumerate(value):
                                    lst_categories.InsertStringItem(X, val)
                                return True

            return False

        categories_used = []

        for group in self.opts_input, self.opts_choice, self.opts_list:
            for O in group:
                if set_value(O):
                    categories_used.append(O.GetName())

        # List of keys that can be ignored if unused
        bypass_unused = (u'Version', )

        categories_unused = []
        for key in menu_definitions:
            if key not in categories_used and key not in bypass_unused:
                categories_unused.append(u'{}={}'.format(
                    key, menu_definitions[key]))

        categories_unused += unused_raw_lines
        if len(categories_unused):
            categories_unused = u'\n'.join(categories_unused)

            #self.ti_other.SetValue(categories_unused)

        return 0