comparison hgrunner.cpp @ 180:3d6d826b04ad

* Similarly, tidier lookup for Hg binary and extension
author Chris Cannam
date Fri, 17 Dec 2010 08:53:54 +0000
parents bb89bcd8986b
children bf366e0b9050
comparison
equal deleted inserted replaced
179:a51980a00dac 180:3d6d826b04ad
47 47
48 setTextVisible(false); 48 setTextVisible(false);
49 setVisible(false); 49 setVisible(false);
50 m_isRunning = false; 50 m_isRunning = false;
51 51
52 findExtension(); 52 (void)findExtension();
53 (void)getHgBinaryName(); 53 (void)findHgBinaryName();
54 } 54 }
55 55
56 HgRunner::~HgRunner() 56 HgRunner::~HgRunner()
57 { 57 {
58 closeTerminal(); 58 closeTerminal();
60 m_proc->kill(); 60 m_proc->kill();
61 m_proc->deleteLater(); 61 m_proc->deleteLater();
62 } 62 }
63 } 63 }
64 64
65 void HgRunner::findExtension() 65 QString HgRunner::findExtension()
66 { 66 {
67 QSettings settings; 67 QSettings settings;
68 settings.beginGroup("Locations"); 68 settings.beginGroup("Locations");
69 m_extensionPath = settings.value("extensionpath", "").toString(); 69 QString extpath = settings.value("extensionpath", "").toString();
70 if (m_extensionPath != "") return; 70 if (extpath != "") return extpath;
71 m_extensionPath = findInPath("easyhg.py", m_myDirPath, false); 71 extpath = findInPath("easyhg.py", m_myDirPath, false);
72 if (m_extensionPath == "easyhg.py") { 72 if (extpath == "easyhg.py") {
73 if (!unbundleExtension()) { 73 extpath = unbundleExtension();
74 // might have failed because the file already existed 74 }
75 if (!QFile(m_extensionPath).exists()) { 75 settings.setValue("extensionpath", extpath);
76 m_extensionPath = ""; 76 return extpath;
77 }
78 }
79 }
80 settings.setValue("extensionpath", m_extensionPath);
81 } 77 }
82 78
83 bool HgRunner::unbundleExtension() 79 QString HgRunner::unbundleExtension()
84 { 80 {
85 QString bundled = ":easyhg.py"; 81 QString bundled = ":easyhg.py";
86 QString home = QDir::homePath(); 82 QString home = QDir::homePath();
87 QString target = QString("%1/.easyhg").arg(home); 83 QString target = QString("%1/.easyhg").arg(home);
88 if (!QDir().mkpath(target)) { 84 if (!QDir().mkpath(target)) {
89 DEBUG << "Failed to make unbundle path " << target << endl; 85 DEBUG << "Failed to make unbundle path " << target << endl;
90 std::cerr << "Failed to make unbundle path " << target.toStdString() << std::endl; 86 std::cerr << "Failed to make unbundle path " << target.toStdString() << std::endl;
91 return false; 87 return "";
92 } 88 }
93 QFile bf(bundled); 89 QFile bf(bundled);
94 m_extensionPath = QString("%1/easyhg.py").arg(target); 90 if (!bf.exists()) {
95 if (!bf.copy(m_extensionPath)) { 91 DEBUG << "Bundled extension is missing!" << endl;
92 return "";
93 }
94 QString extpath = QString("%1/easyhg.py").arg(target);
95 if (QFile(extpath).exists()) {
96 QFile(extpath).remove();
97 }
98 if (!bf.copy(extpath)) {
96 DEBUG << "Failed to unbundle extension to " << target << endl; 99 DEBUG << "Failed to unbundle extension to " << target << endl;
97 std::cerr << "Failed to unbundle extension to " << m_extensionPath.toStdString() << std::endl; 100 std::cerr << "Failed to unbundle extension to " << extpath.toStdString() << std::endl;
98 return false; 101 return "";
99 } 102 }
100 DEBUG << "Unbundled extension to " << m_extensionPath << endl; 103 DEBUG << "Unbundled extension to " << extpath << endl;
101 return true; 104 return extpath;
102 } 105 }
103 106
104 void HgRunner::requestAction(HgAction action) 107 void HgRunner::requestAction(HgAction action)
105 { 108 {
106 DEBUG << "requestAction " << action.action << endl; 109 DEBUG << "requestAction " << action.action << endl;
122 } 125 }
123 if (pushIt) m_queue.push_back(action); 126 if (pushIt) m_queue.push_back(action);
124 checkQueue(); 127 checkQueue();
125 } 128 }
126 129
127 QString HgRunner::getHgBinaryName() 130 QString HgRunner::findHgBinaryName()
128 { 131 {
129 QSettings settings; 132 QSettings settings;
130 settings.beginGroup("Locations"); 133 settings.beginGroup("Locations");
131 QString hg = settings.value("hgbinary", "").toString(); 134 QString hg = settings.value("hgbinary", "").toString();
132 if (hg == "") { 135 if (hg == "") {
339 bool interactive = false; 342 bool interactive = false;
340 QStringList params = action.params; 343 QStringList params = action.params;
341 344
342 if (executable == "") { 345 if (executable == "") {
343 // This is a Hg command 346 // This is a Hg command
344 executable = getHgBinaryName(); 347 executable = findHgBinaryName();
345 348
346 if (action.mayBeInteractive()) { 349 if (action.mayBeInteractive()) {
347 params.push_front("ui.interactive=true"); 350 params.push_front("ui.interactive=true");
348 params.push_front("--config"); 351 params.push_front("--config");
349 352
350 QSettings settings; 353 QSettings settings;
351 settings.beginGroup("General"); 354 settings.beginGroup("General");
352 if (settings.value("useextension", true).toBool()) { 355 if (settings.value("useextension", true).toBool()) {
353 params.push_front(QString("extensions.easyhg=%1").arg(m_extensionPath)); 356 QString extpath = findExtension();
357 params.push_front(QString("extensions.easyhg=%1").arg(extpath));
354 params.push_front("--config"); 358 params.push_front("--config");
355 } 359 }
356 interactive = true; 360 interactive = true;
357 } 361 }
358 362