> I thought we wanted to change that with the new approach.
That is quite easy. Patch attached. The logic is that generate a
default copy if --without-latex-config is specified, or if there is no
previous version of this file.
- # First, remove the files that we want to re-create
- removeFiles(['textclass.lst', 'packages.lst', 'chkconfig.sed'])
- #
- if not check_config:
+ # if --without-latex-config is forced, or if there is no previous
+ # version of textclass.lst, re-generate a default file.
+ if not os.path.isfile('textclass.lst') or not check_config:
+ # remove the files only if we want to regenerate
+ removeFiles(['textclass.lst', 'packages.lst', 'chkconfig.sed'])
+ #
+ # Then, generate a default textclass.lst. In case configure.py
+ # fails, we still have something to start lyx.
Do you want me to polish configure.py, or both configure.py and lyx
parts for 1.5.2?
Bo
Index: src/LyX.cpp
===================================================================
--- src/LyX.cpp (revision 20494)
+++ src/LyX.cpp (working copy)
@@ -611,6 +611,13 @@
// aknowledged.
restoreGuiSession();
+ // if reconfiguration is needed.
+ if (textclasslist.empty()) {
+ Alert::error(_("No textclass is found"),
+ _("Click OK to reconfigure lyx."));
+ pimpl_->lyxfunc_.dispatch(FuncRequest(LFUN_RECONFIGURE));
+ }
+
// Execute batch commands if available
if (batch_command.empty())
return;
@@ -626,6 +633,10 @@
{
LyXView * view = newLyXView();
+ // if there is no valid class list, do not load any file.
+ if (textclasslist.empty())
+ return;
+
// if some files were specified at command-line we assume that the
// user wants to edit *these* files and not to restore the session.
if (!pimpl_->files_to_load_.empty()) {
Index: src/TextClassList.cpp
===================================================================
--- src/TextClassList.cpp (revision 20494)
+++ src/TextClassList.cpp (working copy)
@@ -164,13 +164,15 @@
}
LYXERR(Debug::TCLASS) << "End of parsing of textclass.lst" << endl;
- if (classlist_.empty()) {
+ // lyx will start with an empty classlist_, but only reconfigure is allowed
+ // in this case. This gives users a second chance to configure lyx if
+ // initial configuration fails. (c.f. bug 2829)
+ if (classlist_.empty())
lyxerr << "TextClassList::Read: no textclasses found!"
<< endl;
- return false;
- }
- // Ok everything loaded ok, now sort the list.
- sort(classlist_.begin(), classlist_.end(), less_textclass_avail_desc());
+ else
+ // Ok everything loaded ok, now sort the list.
+ sort(classlist_.begin(), classlist_.end(), less_textclass_avail_desc());
return true;
}
Index: src/TextClassList.h
===================================================================
--- src/TextClassList.h (revision 20494)
+++ src/TextClassList.h (working copy)
@@ -40,6 +40,8 @@
const_iterator begin() const { return classlist_.begin(); }
///
const_iterator end() const { return classlist_.end(); }
+ ///
+ bool empty() const { return classlist_.empty(); }
/// Gets textclass number from name, -1 if textclass name does not exist
std::pair<bool, textclass_type> const
Index: src/LyXFunc.cpp
===================================================================
--- src/LyXFunc.cpp (revision 20494)
+++ src/LyXFunc.cpp (working copy)
@@ -390,6 +390,16 @@
//lyxerr << "LyXFunc::getStatus: cmd: " << cmd << endl;
FuncStatus flag;
+ // if textclasslist is empty, the only allowed operation is reconfigure (c.f. bug 2829)
+ // FIXME: this can be removed after lyx can restart itself automatically
+ // after reconfiguration. Note that reconfiguration is triggered at
+ // LyX::execBatchCommands() in LyX.cpp.
+ if (textclasslist.empty() && cmd.action != LFUN_RECONFIGURE
+ && cmd.action != LFUN_LYX_QUIT) {
+ flag.enabled(false);
+ return flag;
+ }
+
Cursor & cur = view()->cursor();
/* In LyX/Mac, when a dialog is open, the menus of the
Index: lib/chkconfig.ltx
===================================================================
--- lib/chkconfig.ltx (revision 20494)
+++ lib/chkconfig.ltx (working copy)
@@ -129,10 +129,10 @@
% Initializes the files
\typeout{\prefix Inspecting your LaTeX configuration.}
-\newwrite{\layouts} \immediate\openout \layouts = textclass.lst
+\newwrite{\layouts} \immediate\openout \layouts = textclass.lst.tmp
\newwrite{\sed} \immediate\openout \sed = chkconfig.sed
\newwrite{\vars} \immediate\openout \vars = chkconfig.vars
-\newwrite{\packages} \immediate\openout \packages = packages.lst
+\newwrite{\packages} \immediate\openout \packages = packages.lst.tmp
\immediate\write\layouts{%
# This file declares layouts and their associated definition files.^^J%
Index: lib/configure.py
===================================================================
--- lib/configure.py (revision 20494)
+++ lib/configure.py (working copy)
@@ -591,10 +591,14 @@
def checkLatexConfig(check_config, bool_docbook, bool_linuxdoc):
''' Explore the LaTeX configuration '''
print 'checking LaTeX configuration... ',
- # First, remove the files that we want to re-create
- removeFiles(['textclass.lst', 'packages.lst', 'chkconfig.sed'])
- #
- if not check_config:
+ # if --without-latex-config is forced, or if there is no previous
+ # version of textclass.lst, re-generate a default file.
+ if not os.path.isfile('textclass.lst') or not check_config:
+ # remove the files only if we want to regenerate
+ removeFiles(['textclass.lst', 'packages.lst', 'chkconfig.sed'])
+ #
+ # Then, generate a default textclass.lst. In case configure.py
+ # fails, we still have something to start lyx.
print ' default values'
print '+checking list of textclasses... '
tx = open('textclass.lst', 'w')
@@ -604,7 +608,7 @@
# It contains only default values, since chkconfig.ltx could not be run
# for some reason. Run ./configure.py if you need to update it after a
# configuration change.
-''')
+ ''')
# build the list of available layout files and convert it to commands
# for chkconfig.ltx
foundClasses = []
@@ -624,7 +628,8 @@
tx.write(processLayoutFile(file, bool_docbook, bool_linuxdoc))
tx.close()
print '\tdone'
- else:
+ # the following will generate textclass.lst.tmp, and packages.lst.tmp
+ if check_config:
print '\tauto'
removeFiles(['wrap_chkconfig.ltx', 'chkconfig.vars', \
'chkconfig.classes', 'chklayouts.tex'])
@@ -682,6 +687,12 @@
pass
if rmcopy: # remove the copied file
removeFiles( [ 'chkconfig.ltx' ] )
+ # if configure successed, move textclass.lst.tmp to textclass.lst
+ # and packages.lst.tmp to packages.lst
+ if os.path.isfile('textclass.lst.tmp') and len(open('textclass.lst.tmp').read()) > 0 \
+ and os.path.isfile('packages.lst.tmp') and len(open('packages.lst.tmp').read()) > 0:
+ shutil.move('textclass.lst.tmp', 'textclass.lst')
+ shutil.move('packages.lst.tmp', 'packages.lst')
def createLaTeXConfig():