Esempio n. 1
0
    def CreateDetailedView(self, details):
        # Controls have not been constructed yet
        if TextIsEmpty(self.details):
            self.btn_details = wx.ToggleButton(self, label=GT(u'Details'))
            #btn_copy = wx.Button(self, label=GT(u'Copy details'))

            self.dsp_details = TextAreaPanel(self,
                                             value=details,
                                             style=wx.TE_READONLY)

            # *** Event handlers *** #

            self.btn_details.Bind(wx.EVT_TOGGLEBUTTON, self.ToggleDetails)
            #btn_copy.Bind(wx.EVT_BUTTON, self.OnCopyDetails)

            layout = self.GetSizer()
            layout.Add(self.btn_details, (2, 1))
            #layout.Add(btn_copy, (2, 2), flag=wx.ALIGN_LEFT|wx.RIGHT, border=5)
            layout.Add(self.dsp_details, (3, 1), (1, 2), wx.EXPAND | wx.RIGHT,
                       5)

            self.ToggleDetails()

        if not TextIsEmpty(details):
            for C in self.GetChildren():
                if isinstance(C, TextAreaPanel):
                    self.details = details
                    C.SetValue(self.details)

                    return True

        return False
Esempio n. 2
0
    def GetLauncherInfo(self):
        desktop_list = [u'[Desktop Entry]']

        name = GetField(self, inputid.NAME).GetValue()
        if not TextIsEmpty(name):
            desktop_list.append(u'Name={}'.format(name))

        desktop_list.append(u'Version=1.0')

        executable = GetField(self, inputid.EXEC).GetValue()
        if not TextIsEmpty(executable):
            desktop_list.append(u'Exec={}'.format(executable))

        comment = GetField(self, inputid.DESCR).GetValue()
        if not TextIsEmpty(comment):
            desktop_list.append(u'Comment={}'.format(comment))

        icon = GetField(self, inputid.ICON).GetValue()
        if not TextIsEmpty(icon):
            desktop_list.append(u'Icon={}'.format(icon))

        launcher_type = GetField(self, inputid.TYPE).GetValue()
        if not TextIsEmpty(launcher_type):
            desktop_list.append(u'Type={}'.format(launcher_type))

        desktop_list.append(u'Terminal={}'.format(
            GS(GetField(self, chkid.TERM).GetValue()).lower()))

        desktop_list.append(u'StartupNotify={}'.format(
            GS(GetField(self, chkid.NOTIFY).GetValue()).lower()))

        encoding = GetField(self, inputid.ENC).GetValue()
        if not TextIsEmpty(encoding):
            desktop_list.append(u'Encoding={}'.format(encoding))

        lst_categories = GetField(self, listid.CAT)
        categories = []
        cat_total = lst_categories.GetItemCount()
        count = 0
        while count < cat_total:
            C = lst_categories.GetItemText(count)
            if not TextIsEmpty(C):
                categories.append(lst_categories.GetItemText(count))

            count += 1

        # Add a final semi-colon if categories is not empty
        if categories:
            categories = u';'.join(categories)
            if categories[-1] != u';':
                categories = u'{};'.format(categories)

            desktop_list.append(u'Categories={}'.format(categories))

        other = GetField(self, inputid.OTHER).GetValue()
        if not TextIsEmpty(other):
            desktop_list.append(other)

        return u'\n'.join(desktop_list)
Esempio n. 3
0
 def ExportDeprecated(self, outDir, outName=wx.EmptyString):
     if not os.path.isdir(outDir):
         Logger.Debug(__name__, u'Directory does not exist: {}'.format(outDir))
         return ERR_DIR_NOT_AVAILABLE
     
     if outName == wx.EmptyString:
         outName = page_ids[self.GetId()].upper()
     
     page_info = self.Get()
     
     if not page_info:
         return 0
     
     if not outName:
         outName = self.Name
     
     if TextIsEmpty(page_info):
         return 0
     
     absolute_filename = u'{}/{}'.format(outDir, outName)
     
     Logger.Debug(outName, u'Exporting: {}'.format(absolute_filename))
     
     WriteFile(absolute_filename, page_info)
     
     return 0
Esempio n. 4
0
	def GetDestValue(self, event=None):
		if not TextIsEmpty(self.ti_target.GetValue()):
			if self.ti_target.GetValue()[0] == u'/':
				self.prev_dest_value = self.ti_target.GetValue()

		if event:
			event.Skip()
Esempio n. 5
0
 def OnAddCustom(self, event=None):
     custom_label = GS(
         self.input_add_custom.GetValue()).strip(u' ').replace(u' ', u'_')
     if not TextIsEmpty(custom_label) and not self.check_list.LabelExists(
             custom_label):
         self.check_list.AddItem(custom_label, True)
         self.check_list.ScrollToEnd()
Esempio n. 6
0
def FormatChangelog(text,
                    name=APP_name,
                    version=VERSION_string,
                    dist=OS_codename,
                    urgency=u'low',
                    packager=AUTHOR_name,
                    email=AUTHOR_email,
                    preserve_indent=False):
    if TextIsEmpty(text):
        return None

    # Remove leading & trailing whitespace & empty lines & split into
    # list of lines.
    lines = text.strip(u' \t\n\r').split(u'\n')

    if not lines:
        return None

    lines = RemoveEmptyLines(lines)
    lines = _format_lines(lines, preserve_indent)

    text = u'\n'.join(lines)
    header = u'{} ({}) {}; urgency={}\n'.format(name, version, dist, urgency)
    footer = u'\n -- {} <{}>  {}'.format(packager, email, _get_cl_timestamp())

    return u'\n'.join((header, text, footer))
Esempio n. 7
0
        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
Esempio n. 8
0
    def _title_is_ok(self, title):
        if TextIsEmpty(title):
            return False

        return not Contains(title, (
            u' ',
            u'\t',
        ))
Esempio n. 9
0
	def Get(self):
		scripts = {}

		for DS, RB in self.script_objects:
			if not TextIsEmpty(DS.GetValue()):
				scripts[DS.GetFilename()] = DS.GetValue()

		return scripts
Esempio n. 10
0
    def __init__(self,
                 parent,
                 title=GT(u'Message'),
                 icon=ICON_INFORMATION,
                 text=wx.EmptyString,
                 details=wx.EmptyString,
                 style=wx.DEFAULT_DIALOG_STYLE,
                 buttons=(wx.ID_OK, ),
                 linewrap=0):

        BaseDialog.__init__(self, parent, wx.ID_ANY, title, style=style)

        # Allow using strings for 'icon' argument
        if isinstance(icon, (unicode, str)):
            icon = wx.Bitmap(icon)

        icon = wx.StaticBitmap(self, wx.ID_ANY, icon)

        txt_message = wx.StaticText(self, label=text)
        if linewrap:
            txt_message.Wrap(linewrap)

        # self.details needs to be empty for constructor
        self.details = wx.EmptyString
        details = details

        # *** Layout *** #

        self.lyt_urls = BoxSizer(wx.VERTICAL)

        # Only set if buttons are added to dialog
        self.lyt_buttons = None

        lyt_main = wx.GridBagSizer(5, 5)
        lyt_main.SetCols(3)
        lyt_main.AddGrowableRow(3)
        lyt_main.AddGrowableCol(2)
        lyt_main.Add(icon, (0, 0), (5, 1),
                     wx.ALIGN_TOP | lyt.PAD_LR | wx.BOTTOM, 20)
        lyt_main.Add(txt_message, (0, 1), (1, 2), lyt.PAD_RT, 20)
        lyt_main.Add(self.lyt_urls, (1, 1), (1, 2), wx.RIGHT, 5)

        self.SetAutoLayout(True)
        self.SetSizer(lyt_main)

        self.AddButtons(buttons)

        if not TextIsEmpty(details):
            # self.details will be set here
            self.CreateDetailedView(details)

        else:
            self.Layout()

            self.Fit()
            self.SetMinSize(self.GetSize())

        self.CenterOnParent()
Esempio n. 11
0
 def DestroyLicenseText(self):
     if not TextIsEmpty(self.dsp_copyright.GetValue()):
         warn_msg = GT(u'This will destroy all license text.')
         warn_msg = u'{}\n\n{}'.format(warn_msg, GT(u'Continue?'))
         
         if ConfirmationDialog(GetMainWindow(), text=warn_msg).ShowModal() not in (wx.ID_OK, wx.OK):
             return False
     
     return True
Esempio n. 12
0
    def GetOutputFilename(self):
        if not GetField(self, chkid.FNAME).GetValue():
            filename = GetField(self,
                                inputid.FNAME).GetValue().strip(u' ').replace(
                                    u' ', u'_')
            if not TextIsEmpty(filename):
                return filename

        return GetField(self, inputid.NAME).GetValue().strip(u' ').replace(
            u' ', u'_')
Esempio n. 13
0
 def Get(self, getModule=False):
     page = self.dsp_copyright.GetValue()
     
     if TextIsEmpty(page):
         page = None
     
     if getModule:
         page = (__name__, page,)
     
     return page
Esempio n. 14
0
	def CheckDest(self, event=None):
		if TextIsEmpty(self.ti_target.GetValue()):
			self.ti_target.SetValue(self.prev_dest_value)
			self.ti_target.SetInsertionPoint(-1)

		elif self.ti_target.GetValue()[0] != u'/':
			self.ti_target.SetValue(self.prev_dest_value)
			self.ti_target.SetInsertionPoint(-1)

		if event:
			event.Skip()
Esempio n. 15
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

		files_data = ReadFile(filename, split=True)

		# Lines beginning with these characters will be ignored
		ignore_characters = (
			u'',
			u' ',
			u'#',
		)

		target = None
		targets_list = []

		for L in files_data:
			if not TextIsEmpty(L) and L[0] not in ignore_characters:
				if u'[' in L and u']' in L:
					target = L.split(u'[')[-1].split(u']')[0]
					continue

				if target:
					executable = (len(L) > 1 and L[-2:] == u' *')
					if executable:
						L = L[:-2]

					targets_list.append((target, L, executable))

		missing_files = []

		for T in targets_list:
			# FIXME: Create method in FileList class to retrieve all missing files
			if not os.path.exists(T[1]):
				missing_files.append(T[1])

			source_file = os.path.basename(T[1])
			source_dir = os.path.dirname(T[1])

			self.lst_files.AddFile(source_file, source_dir, T[0], executable=T[2])

		if len(missing_files):
			main_window = GetMainWindow()

			err_line1 = GT(u'The following files/folders are missing from the filesystem.')
			err_line2 = GT(u'They will be highlighted on the Files page.')
			DetailedMessageDialog(main_window, title=GT(u'Warning'), icon=ICON_ERROR,
					text=u'\n'.join((err_line1, err_line2)),
					details=u'\n'.join(missing_files)).ShowModal()

		return 0
Esempio n. 16
0
    def AddInfo(self, event=None):
        new_changes = self.ti_changes.GetValue()

        if TextIsEmpty(new_changes):
            DetailedMessageDialog(
                GetMainWindow(), GT(u'Warning'), ICON_WARNING,
                GT(u'"Changes" section is empty')).ShowModal()

            self.ti_changes.SetInsertionPointEnd()
            self.ti_changes.SetFocus()

            return

        package = self.ti_package.GetValue()
        version = self.ti_version.GetValue()
        dist = self.ti_dist.GetValue()
        urgency = self.sel_urgency.GetStringSelection()
        maintainer = self.ti_maintainer.GetValue()
        email = self.ti_email.GetValue()

        new_changes = FormatChangelog(new_changes, package, version, dist,
                                      urgency, maintainer, email,
                                      self.chk_indentation.GetValue())

        # Clean up leading & trailing whitespace in old changes
        old_changes = self.dsp_changes.GetValue().strip(u' \t\n\r')

        # Only append newlines if log isn't already empty
        if not TextIsEmpty(old_changes):
            new_changes = u'{}\n\n\n{}'.format(new_changes, old_changes)

        # Add empty line to end of log
        if not new_changes.endswith(u'\n'):
            new_changes = u'{}\n'.format(new_changes)

        self.dsp_changes.SetValue(new_changes)

        # Clear "Changes" text
        self.ti_changes.Clear()
        self.ti_changes.SetFocus()
Esempio n. 17
0
    def SetTabName(self, index=-1, rename=False, checkBox=None, checked=False):
        getname = TextEntryDialog(GetMainWindow(), GT(u'Name for new page'))
        new_name = None

        if not rename and checkBox:
            check_box = CheckBox(getname, label=checkBox)
            check_box.SetValue(checked)

            sizer = getname.GetSizer()
            insert_point = len(sizer.GetChildren()) - 1

            sizer.InsertSpacer(insert_point, 5)
            sizer.Insert(insert_point + 1, check_box, 0, wx.LEFT, 16)

            getname.SetSize(sizer.GetMinSize())
            getname.Fit()
            getname.CenterOnParent()

        valid_name = False

        while not valid_name:
            if new_name and TextIsEmpty(new_name):
                getname.Clear()

            # User cancelled
            if not ShowDialog(getname):
                return False

            else:
                new_name = getname.GetValue()

            valid_name = self._title_is_ok(new_name)

            if valid_name:
                break

            ShowErrorDialog(GT(u'Page name cannot contain whitespace'),
                            warn=True)

        if rename:
            if index < 0:
                return False

            return self.Tabs.SetPageText(index, new_name)

        if checkBox:
            return self.AddPage(new_name, checkBox=check_box)

        return self.AddPage(new_name)
Esempio n. 18
0
    def Set(self, items):
        # Text control is cleared when options are changed
        cached_value = self.GetValue()

        if not isinstance(items, (tuple, list, dict)):
            items = (items, )

        if wx.MAJOR_VERSION > 2:
            OwnerDrawnComboBox.Set(self, items)

        else:
            self.Clear()

            for I in items:
                self.Append(I)

        if not TextIsEmpty(cached_value):
            self.SetValue(cached_value)
Esempio n. 19
0
    def OnKeyUp(self, event=None):
        insertion_point = self.GetInsertionPoint()
        text = self.GetValue()
        original_text = text

        # Remove whitespace
        for C in (u' ', u'\t'):
            if C in text:
                text = text.replace(C, u'-')

        if not TextIsEmpty(text):
            for C in invalid_chars:
                if C in text:
                    text = text.replace(C, u'-')

            if text != original_text:
                self.SetValue(text)
                self.SetInsertionPoint(insertion_point)
Esempio n. 20
0
    def Get(self, getModule=False):
        target = self.pnl_target.GetPath()

        if target == self.pnl_target.GetDefaultPath():
            target = u'DEFAULT'

        body = self.dsp_changes.GetValue()

        if TextIsEmpty(body):
            page = None

        else:
            page = u'[TARGET={}]\n\n[BODY]\n{}'.format(target, body)

        if getModule:
            page = (
                __name__,
                page,
            )

        return page
Esempio n. 21
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)
Esempio n. 22
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
Esempio n. 23
0
    def OnImportFromControl(self, event=None):
        fields = (
            (self.ti_package, inputid.PACKAGE),
            (self.ti_version, inputid.VERSION),
            (self.ti_maintainer, inputid.MAINTAINER),
            (self.ti_email, inputid.EMAIL),
        )

        for F, FID in fields:
            field_value = GetFieldValue(pgid.CONTROL, FID)

            if isinstance(field_value, ErrorTuple):
                err_msg1 = GT(
                    u'Got error when attempting to retrieve field value')
                err_msg2 = u'\tError code: {}\n\tError message: {}'.format(
                    field_value.GetCode(), field_value.GetString())
                Logger.Error(__name__, u'{}:\n{}'.format(err_msg1, err_msg2))

                continue

            if not TextIsEmpty(field_value):
                F.SetValue(field_value)
Esempio n. 24
0
def WriteConfig(k_name, k_value, conf=default_config, sectLabel=None):
    conf_dir = os.path.dirname(conf)

    if not os.path.isdir(conf_dir):
        if os.path.exists(conf_dir):
            print(u'{}: {}: {}'.format(
                GT(u'Error'),
                GT(u'Cannot create config directory, file exists'), conf_dir))
            return ConfCode.ERR_WRITE

        os.makedirs(conf_dir)

    # Only write pre-defined keys
    if k_name not in default_config_values:
        print(u'{}: {}: {}'.format(GT(u'Error'),
                                   GT(u'Configuration key not found'), k_name))
        return ConfCode.KEY_NOT_DEFINED

    # Make sure we are writing the correct type
    k_value = default_config_values[k_name][0](k_value)

    if k_value == None:
        print(u'{}: {}: {}'.format(
            GT(u'Error'), GT(u'Wrong value type for configuration key'),
            k_name))
        return ConfCode.WRONG_TYPE

    # tuple is the only type we need to format
    if isinstance(k_value, tuple):
        k_value = u'{},{}'.format(GS(k_value[0]), GS(k_value[1]))

    else:
        k_value = GS(k_value)

    conf_text = wx.EmptyString

    # Save current config to buffer
    if os.path.exists(conf):
        if not os.path.isfile(conf):
            print(u'{}: {}: {}'.format(
                GT(u'Error'),
                GT(u'Cannot open config for writing, directory exists'), conf))
            return ConfCode.ERR_WRITE

        conf_text = ReadFile(conf)

        # FIXME: ReadFile returns None type if config file exists but is empty
        if conf_text == None:
            conf_text = u''

    else:
        conf_text = u'[CONFIG-{}.{}]'.format(GS(config_version[0]),
                                             GS(config_version[1]))

    conf_lines = conf_text.split(u'\n')

    key_exists = False
    for L in conf_lines:
        l_index = conf_lines.index(L)
        if u'=' in L:
            key = L.split(u'=')[0]

            if k_name == key:
                key_exists = True

                conf_lines[l_index] = u'{}={}'.format(k_name, k_value)

    if not key_exists:
        conf_lines.append(u'{}={}'.format(k_name, k_value))

    conf_text = u'\n'.join(conf_lines)

    if TextIsEmpty(conf_text):
        print(u'{}: {}'.format(GT(u'Warning'),
                               GT(u'Not writing empty text to configuration')))
        return ConfCode.ERR_WRITE

    # Actual writing to configuration
    WriteFile(conf, conf_text)

    if os.path.isfile(conf):
        return ConfCode.SUCCESS

    return ConfCode.ERR_WRITE
Esempio n. 25
0
 def IsOkay(self):
     return not TextIsEmpty(self.dsp_changes.GetValue())
Esempio n. 26
0
    def ImportFromFile(self, filename):
        if not os.path.isfile(filename):
            return dbrerrno.ENOENT

        clog_data = ReadFile(filename, split=True)

        sections = {}

        def parse_section(key, lines):
            value = u'\n'.join(lines).split(u'\n[')[0]

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

            sections[key] = value

        # NOTE: This would need to be changed were more sections added to project file
        for L in clog_data:
            line_index = clog_data.index(L)

            if not TextIsEmpty(L) and u'[' in L and u']' in L:
                L = L.split(u'[')[-1].split(u']')[0]
                parse_section(L, clog_data[line_index + 1:])

        for S in sections:
            Logger.Debug(
                __name__,
                GT(u'Changelog section: "{}", Value:\n{}').format(
                    S, sections[S]))

            if isinstance(sections[S], (tuple, list)):
                value_index = 0
                for I in sections[S]:
                    Logger.Debug(__name__,
                                 GT(u'Value {}: {}').format(value_index, I))
                    value_index += 1

            if S == u'TARGET':
                Logger.Debug(__name__, u'SECTION TARGET FOUND')

                if sections[S][0] == u'DEFAULT':
                    Logger.Debug(__name__, u'Using default target')

                    if not self.pnl_target.UsingDefault():
                        self.pnl_target.Reset()

                else:
                    Logger.Debug(
                        __name__,
                        GT(u'Using custom target: {}').format(sections[S][0]))

                    self.pnl_target.SetPath(sections[S][0])

                continue

            if S == u'BODY':
                Logger.Debug(__name__, u'SECTION BODY FOUND')

                self.dsp_changes.SetValue(sections[S])

                continue

        return 0
Esempio n. 27
0
 def IsOkay(self):
     return not TextIsEmpty(self.dsp_copyright.GetValue())
Esempio n. 28
0
	def IsOkay(self):
		return not TextIsEmpty(self.ScriptBody.GetValue())
Esempio n. 29
0
	def OnGenerate(self, event=None):
		main_window = GetMainWindow()

		# Get the amount of links to be created
		total = self.Executables.GetCount()

		if total > 0:
			non_empty_scripts = []

			for DS in self.script_objects[1][0], self.script_objects[2][0]:
				if not TextIsEmpty(DS.GetValue()):
					non_empty_scripts.append(DS.GetName())

			# Warn about overwriting previous post-install & pre-remove scripts
			if non_empty_scripts:
				warn_msg = GT(u'The following scripts will be overwritten if you continue: {}')
				warn_msg = u'{}\n\n{}'.format(warn_msg.format(u', '.join(non_empty_scripts)), GT(u'Continue?'))

				overwrite = ConfirmationDialog(main_window, text=warn_msg)

				if not overwrite.Confirmed():
					return

				overwrite.Destroy()
				del warn_msg, overwrite

			# Get destination for link from Auto-Link input textctrl
			link_path = self.ti_autolink.GetValue()

			# Warn about linking in a directory that does not exist on the current filesystem
			if not os.path.isdir(link_path):
				warn_msg = GT(u'Path "{}" does not exist.')
				warn_msg = u'{}\n\n{}'.format(warn_msg, GT(u'Continue?'))

				overwrite = ConfirmationDialog(main_window, text=warn_msg.format(link_path))

				if not overwrite.Confirmed():
					return

				overwrite.Destroy()
				del warn_msg, overwrite

			# Create a list of commands to put into the script
			postinst_list = []
			prerm_list = []

			for INDEX in range(total):
				source_path = self.Executables.GetPath(INDEX)
				filename = self.Executables.GetBasename(INDEX)

				if u'.' in filename:
					linkname = u'.'.join(filename.split(u'.')[:-1])
					link = u'{}/{}'.format(link_path, linkname)

				else:
					link = u'{}/{}'.format(link_path, filename)

				postinst_list.append(u'ln -fs "{}" "{}"'.format(source_path, link))
				prerm_list.append(u'rm -f "{}"'.format(link))

			postinst = u'\n\n'.join(postinst_list)
			prerm = u'\n\n'.join(prerm_list)

			self.script_objects[1][0].SetValue(postinst)
			self.script_objects[2][0].SetValue(prerm)

			DetailedMessageDialog(main_window, GT(u'Success'),
					text=GT(u'Post-Install and Pre-Remove scripts generated')).ShowModal()
Esempio n. 30
0
    def OnBuild(self, event=None):
        if event:
            event.Skip()

        # Show control file preview for editing
        if UsingTest(u'alpha') and self.chk_editctrl.GetValue():
            self.EditControl()

        wizard = GetWizard()

        pg_control = wizard.GetPage(pgid.CONTROL)
        pg_files = wizard.GetPage(pgid.FILES)
        pg_launcher = wizard.GetPage(pgid.LAUNCHERS)

        required_fields = {
            GT(u'Control'): pg_control.GetRequiredFields(),
        }

        # Check if launchers are enabled for build
        if pg_launcher.GetLaunchersCount():
            required_fields[GT(
                u'Menu Launcher')] = pg_launcher.GetRequiredFields()

            # FIXME: Old code won't work with multiple launchers
            for RF in required_fields[GT(u'Menu Launcher')]:
                Logger.Debug(
                    __name__,
                    GT(u'Required field (Menu Launcher): {}').format(
                        RF.GetName()))

        for p_name in required_fields:
            Logger.Debug(__name__, GT(u'Page name: {}').format(p_name))
            for F in required_fields[p_name]:
                if not isinstance(F, wx.StaticText) and TextIsEmpty(
                        F.GetValue()):
                    f_name = F.GetName()

                    msg_l1 = GT(u'One of the required fields is empty:')
                    msg_full = u'{}: {} ➜ {}'.format(msg_l1, p_name, f_name)

                    Logger.Warn(__name__, msg_full)

                    DetailedMessageDialog(GetMainWindow(),
                                          GT(u'Cannot Continue'),
                                          ICON_EXCLAMATION,
                                          text=msg_full).ShowModal()

                    for P in wizard.GetAllPages():
                        if P.GetTitle() == p_name:
                            Logger.Debug(
                                __name__,
                                GT(u'Showing page with required field: {}').
                                format(p_name))
                            wizard.ShowPage(P.GetId())

                    return

        if GetField(pg_files, inputid.LIST).MissingFiles():
            ShowErrorDialog(GT(u'Files are missing in file list'),
                            warn=True,
                            title=GT(u'Warning'))

            wizard.ShowPage(pgid.FILES)

            return

        ttype = GT(u'Debian Packages')
        save_dialog = GetFileSaveDialog(GetMainWindow(), GT(u'Build Package'),
                                        u'{} (*.deb)|*.deb'.format(ttype),
                                        u'deb')

        package = GetFieldValue(pg_control, inputid.PACKAGE)
        version = GetFieldValue(pg_control, inputid.VERSION)
        arch = GetFieldValue(pg_control, inputid.ARCH)
        save_dialog.SetFilename(u'{}_{}_{}.deb'.format(package, version, arch))

        if ShowDialog(save_dialog):
            self.Build(save_dialog.GetPath())