source: src-qt4/EasyPBI/ModuleUtils.cpp @ 0c42827

releng/10.0.1releng/10.0.2
Last change on this file since 0c42827 was 0c42827, checked in by Ken Moore <ken@…>, 5 months ago

Update EasyPBI to 2.3:
Changes Include:
Add ability to build from ports directly again.
Add legacy port-build options to the GUI.
Add item to show current package compile-time options.
Add ability to create a new module from either ports/packages.
Fix a bug in the default wrapper script for 10.x PBI's (container path is /usr/local/ now when running)

  • Property mode set to 100644
File size: 8.3 KB
Line 
1#include "ModuleUtils.h"
2
3// =====================
4//    VALID/RECOMMENDATIONS
5// =====================
6QStringList ModuleUtils::validXdgCategories(){
7  QStringList out;
8  out << "AudioVideo"<<"Development"<<"Education"<<"Game"<<"Graphics"<<"Network"<<"Office"<<"Science"<<"Settings"<<"System"<<"Utility";
9  return out;
10}
11
12QString ModuleUtils::recommendedXdgCategory(QString portCategory){
13  QString pc = portCategory.toLower();
14  QStringList avcat, devcat, edcat, gamecat, gracat,netcat,offcat,setcat,syscat,scicat;
15  avcat << "audio"<<"multimedia";
16  devcat << "devel" << "lang" << "java";
17  edcat << "astro" << "cad" <<"math";
18  scicat <<"biology"<<"science";
19  gamecat << "games";
20  gracat << "graphics";
21  netcat << "ftp"<<"irc"<<"mail"<<"net"<<"net-im"<<"net-p2p"<<"net-mgmt"<<"www";
22  offcat << "editors" << "finance" << "news" << "textproc";
23  setcat << "accessibility"<<"print";
24  syscat << "sysutils" << "benchmarks" << "emulators" << "ports-mgmt";
25 
26  //Assign the menu category
27  QString mc;
28  if( avcat.contains(pc) ){ mc="AudioVideo"; }
29  else if( devcat.contains(pc) ){ mc="Development"; }
30  else if( edcat.contains(pc) ){ mc="Education"; }
31  else if( scicat.contains(pc) ){ mc ="Science"; }
32  else if( gamecat.contains(pc) ){ mc="Game"; }
33  else if( gracat.contains(pc) ){ mc="Graphics"; }
34  else if( netcat.contains(pc) ){ mc="Network"; }
35  else if( offcat.contains(pc) ){ mc="Office"; }
36  else if( setcat.contains(pc) ){ mc="Settings"; }
37  else if( syscat.contains(pc) ){ mc="System"; }
38  else{ mc = "Utility"; }
39 
40  return mc;   
41}
42
43QStringList ModuleUtils::validExternalLinkTypes(){
44  QStringList out;
45  out << "binary" << "linux" << "keep" << "replace" << "nocrash";
46  return out;
47}
48
49QString ModuleUtils::addExternalLinkType(QString current, QString newtype){
50  QStringList types = current.remove(" ").split(",");
51  bool ok = false;
52  for(int i=0; i<types.length(); i++){
53    //Check for special cases
54    if( (types[i] == "keep") && (newtype=="replace") ){
55      types[i] = newtype;
56      ok = true;
57      break;
58    }else if( (types[i] == "replace") && (newtype=="keep") ){
59      types[i] = newtype;
60      ok = true;
61      break;
62    }else if( (types[i]=="binary") && (newtype=="linux") ){
63      types[i] = newtype;
64      ok = true;
65      break;
66    }else if( (types[i]=="linux") && (newtype=="binary") ){
67      types[i] = newtype;
68      ok = true;
69      break;
70    }else if( types[i] == newtype ){
71      ok=true;
72      break;
73    }
74  }
75  if(!ok){ types << newtype; } //append the type to the list
76  return types.join(",");
77}
78
79QStringList ModuleUtils::validRepoCategories(){
80  QStringList out;
81  out << "Accessibility" << "Archivers" << "Astronomy" << "Audio" << "Benchmarks" << "Biology" \
82        << "CAD" << "Communications" << "Converters" << "Databases" << "Desktop Utilities" \
83        << "Development" << "Editors" << "Emulators" << "File Transfer" << "Finance" \
84        << "Games" << "Graphics" << "IRC" << "Japanese" << "Java" << "Languages" \
85        << "Mail" << "Math" << "Miscellaneous" << "Multimedia" << "Network" << "Network - IM"  \
86        << "Network - Management" << "Network - P2P" << "News" << "Non-Port" << "Polish"  \
87        << "Print" << "Science" << "Security" << "Shells" << "System Utilities" << "Text Processing" \
88        << "Ports - Management" << "Web" << "X11" << "X11 - Clocks" << "X11 - File Managers"  \
89        << "X11 - Fonts" << "X11 - Toolkits" << "X11 - Window Managers";
90  return out;
91}
92
93QString ModuleUtils::recommendedRepoCategory(QString portCategory){
94  QStringList cat = ModuleUtils::validRepoCategories();
95  QStringList pcat;  //WARNING: Make sure these correspond exactly to the "valid" categories above
96  pcat << "accessibility" << "archivers" << "astro" << "audio" << "benchmarks" << "biology" \
97        << "cad" << "comms" << "converters" << "databases" << "deskutils" \
98        << "devel" << "editors" << "emulators" << "ftp" << "finance" \
99        << "games" << "graphics" << "irc" << "japanese" << "java" << "lang" \
100        << "mail" << "math" << "misc" << "multimedia" << "net" << "net-im" \
101        << "net-mgmt" << "net-p2p" << "news" << "nonport" << "polish" \
102        << "print" << "science" << "security" << "shells" << "sysutils" << "textproc" \
103        << "ports-mgmt" << "www" << "x11" << "x11-clocks" << "x11-fm" \
104        << "x11-fonts" << "x11-toolkits" << "x11-wm";
105  int index = pcat.indexOf(portCategory.toLower());
106  if( index < 0 || index >= cat.length() ) { index = pcat.indexOf("nonport"); } 
107  return cat[index];
108}
109
110QStringList ModuleUtils::validRepoTypes(){
111  QStringList out;
112  out << "Graphical" << "Text" << "Server";
113  return out;
114}
115
116
117// =======================
118//     XDG SIMPLIFICATIONS
119// =======================
120bool ModuleUtils::xdgExecUsesRoot(QString exec){
121  QString first = exec.section(" ",0,0,QString::SectionSkipEmpty);
122  return ( (first == "pc-su") || first.contains("sudo") );
123}
124
125QString ModuleUtils::pruneXdgLine(QString exec){
126  if(exec.contains("%%PBI_EXEDIR%%") || exec.contains("%%PBI_APPDIR%%") ){
127    QString sline = exec.section("%%",2,50);
128    if(sline.startsWith("/")){ sline = sline.remove(0,1); }
129    return sline;
130  }else{
131    return exec;         
132  }
133}
134
135QString ModuleUtils::generateXdgExec(QString shortExec, bool useRoot){
136  QString exec = "%%PBI_EXEDIR%%/"+shortExec;
137  if(useRoot){ exec.prepend("pc-su "); }
138  return exec;
139}
140
141QString ModuleUtils::generateXdgPath(QString shortline){
142  QString line = "%%PBI_APPDIR%%";
143  if(!shortline.isEmpty()){
144    line.append("/"+shortline);   
145  }
146  return line;
147}
148       
149void ModuleUtils::compressModule(QString modulePath){
150  //Compress the module directory
151  QString localDir = modulePath.section("/",-1);
152  QString cmd = "cd "+modulePath+"/..; tar czf "+localDir+".tar.gz "+localDir;
153  qDebug() << "Compressing module:" << modulePath+".tar.gz";
154  system( cmd.toUtf8() );
155  return;
156}
157
158PBIModule ModuleUtils::newModule(QString moduleDir, QString port, QString iconFile){
159  PBIModule MOD;
160  if(port.isEmpty()){ 
161    qDebug() << "Error: No port given for the new module";
162    return MOD;
163  }
164  //Check/create the base module directory
165  QDir dir(moduleDir);
166  bool ok = false;     
167  if(!dir.exists()){
168    ok = dir.mkpath(moduleDir);
169    if(!ok){
170      qDebug() << "Error: Could not create base module directory:" << moduleDir;
171      return MOD;
172    }
173  }
174  //Now check/create the specific module directory
175  QString modName = port.section("/",-1);
176  QString pbiname = modName; //save this for later
177  if(dir.exists(modName)){
178    //change the module dir name (append a number)
179    int add = 2;
180    while( dir.exists(modName+"--"+QString::number(add)) ){
181      add++;
182    }
183    modName = modName+"--"+QString::number(add);
184  }
185  ok = dir.mkpath(modName);
186  if(!ok){
187    qDebug() << "Error: Could not create the module directory:" << modName;
188    return MOD;
189  }
190  dir.cd(modName);
191  //Load the (non-existant) pbi.conf to prep the structure
192  MOD.loadModule(dir.canonicalPath()+"/pbi.conf");
193  //Now try to copy over the icon file into the resources dir
194  if(iconFile.isEmpty() || !QFile::exists(iconFile)){ iconFile = QDir::homePath()+"/EasyPBI/defaulticon.png"; }
195  ok = MOD.addResource(iconFile);
196  if(!ok){
197    qDebug() << "Warning: Could not copy icon into the new module:" << iconFile;
198  }else{
199    MOD.setText("PBI_PROGICON", iconFile.section("/",-1) ); //Use this icon for the program
200  }
201  //Now add the port info and create the pbi.conf file
202  MOD.setText("PBI_MAKEPORT", port);
203  MOD.setText("PBI_PROGNAME", pbiname);
204  MOD.saveConfig(); //create the new pbi.conf
205  return MOD;
206}
207
208QString ModuleUtils::generatePbiBuildCmd(QString confDir, QString outDir, QString sigFile, bool packageBuild){
209  QString cmd = "pbi_makeport"; 
210  if(confDir.isEmpty()){ qDebug() << "Warning: a module must be supplied to build a PBII"; return ""; }
211  if(!confDir.isEmpty()){ cmd.append(" -c "+confDir); }
212  if(!outDir.isEmpty()){ cmd.append(" -o "+outDir); }
213  if(!sigFile.isEmpty()){ cmd.append(" --sign "+sigFile); }
214  if(packageBuild){ cmd.append(" --pkgbuild"); }
215  return cmd;
216}
217
218QStringList ModuleUtils::generateWrapperScriptTemplate(){
219  QStringList out;
220        out <<"#!/bin/sh";
221        out << "#This is a sample wrapper script form generated by EasyPBI";
222        out << "# REMINDER: Add this file to the external-links for the PBI as well!";
223        out << "";
224        out << "#Setup some internal script variables";
225        out << "PROGDIR=`/usr/local`   #Base PBI directory inside container";
226        out << "APPBINARY=bin/SAMPLE   #application binary";
227        out << "";
228        out << "#--- DO SOMETHING HERE ---";
229        out << "";
230        out << "#Now start the main application";
231        out << "${PROGDIR}/${APPBINARY} $@";
232       
233  return out;
234}
Note: See TracBrowser for help on using the repository browser.