From: Konrad Rosenbaum Date: Sun, 11 Aug 2013 13:14:34 +0000 (+0200) Subject: add meta file classes X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=8db2c6440c48b05426855aa64a1ce7673a754e2f;p=web%2Fkonrad%2Ftaurus.git add meta file classes --- diff --git a/.gitignore b/.gitignore index 23e564d..0a07b4b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,9 @@ *.bak *~ lib/ +bin/ .ctmp Makefile* +core +core.* +.kdev* diff --git a/aurora/common/metafile.cpp b/aurora/common/metafile.cpp new file mode 100644 index 0000000..94f09c0 --- /dev/null +++ b/aurora/common/metafile.cpp @@ -0,0 +1,257 @@ +// Copyright (C) 2012 by Konrad Rosenbaum +// protected under the GNU LGPL version 3 or at your option any newer. +// See COPYING.LGPL file that comes with this distribution. +// + +#include "metafile.h" +#include "../gnupg/include/host2net.h" +#include +#include +#include +#include + +#include + +static const QString slocalOS = +#ifdef Q_OS_LINUX + "linux" +#elif defined(Q_OS_WIN) + "windows" +#else +#warning "Unknown OS, please extend me" + "unknown" +#endif +; + +static const QString slocalCPU = +#ifdef Q_PROCESSOR_X86_32 + "x86" +#elif defined(Q_PROCESSOR_X86_64) + "x86-64" +#else +#warning "Unknown CPU, please extend me" + "unknown" +#endif +; + +static inline bool matchLocalOS(const QString &os) +{ + if(os==slocalOS || os=="all")return true; +#ifdef AURORA_INSTGEN_BUILD + if(os=="any")return true; +#endif + return false; +} + +static inline bool matchLocalCPU(const QString &cpu) +{ + if(cpu==slocalCPU || cpu=="all")return true; +#ifdef AURORA_INSTGEN_BUILD + if(cpu=="any")return true; +#endif + return false; +} + +static inline bool matchLocal(const QString &os,const QString &cpu) +{ + return matchLocalOS(os)&&matchLocalCPU(cpu); +} + +#ifdef AURORA_INSTGEN_BUILD +static inline QString createArchiveName(const QString&name,const QString&os, const QString&cpu) +{ + //shortcut + if(!name.contains('*'))return name; + //create the replacement for *: os-cpu; any is replaced with the actual os/cpu + QString ast; + if(os=="any")ast=slocalOS; + else ast=os; + ast+="-"; + if(cpu=="any")ast+=slocalCPU; + else ast+=cpu; + return QString(name).replace('*',ast); +} + +static inline QString resolveDir(QString dir,const QString&base=".") +{ + if(dir.isEmpty())dir="."; + //stage 1: resolve pipe + if(dir.startsWith("|")){ + QProcess prc; + prc.start(dir.mid(1),QIODevice::ReadOnly); + if(!prc.waitForFinished()){ + qDebug()<<"Error: Failed to resolve directory externally."; + qDebug()<<" Command:"<0 && dir!="/")dir+="/"; + dir+=dc; + } + if(dir.size()==0)dir="."; + //done + return dir; +} +#endif + +QString MetaFile::localPlatform() +{ + return slocalOS+"-"+slocalCPU; +} + +Archive::Archive(const QDomElement& ael) +#ifdef AURORA_INSTGEN_BUILD + :misSource(false) +#endif +{ + mName=ael.attribute("name"); + msha1=ael.attribute("sha1sum"); + mos=ael.attribute("os"); + mcpu=ael.attribute("cpu"); +} + +MetaFile::MetaFile(const QString& fname) +{ + QFile fd(fname); + if(!fd.open(QIODevice::ReadOnly)){ + qDebug()<<"Unable to open Meta File"; + return; + } + QDomDocument doc; + if(!doc.setContent(&fd)){ + qDebug()<<"Meta File is not XML"; + return; + } + QDomElement root=doc.documentElement(); + mValid=root.tagName()=="AuroraInfo"; + QDomElement el=doc.elementsByTagName("CurrentVersion").at(0).toElement(); + mBuilt=QDateTime::fromString(el.attribute("buildDate"),Qt::ISODate); + mInstalled=QDateTime::fromString(el.attribute("installDate"),Qt::ISODate); + mVersionH=el.attribute("version"); + mVersionM=el.attribute("mrv"); + el=doc.elementsByTagName("Settings").at(0).toElement(); + mBaseUrl=el.attribute("baseurl"); + mIndexFile=el.attribute("indexfile"); + mPollInterval=el.attribute("pollinterval","-1").toInt(); + //go through archive sources + QDomNodeList nl; +#ifdef AURORA_INSTGEN_BUILD + nl=doc.elementsByTagName("ArchiveSource"); + for(int i=0;i +// protected under the GNU LGPL version 3 or at your option any newer. +// See COPYING.LGPL file that comes with this distribution. +// + +#ifndef AURORA_META_H +#define AURORA_META_H + +#include +#include +#include + +class QDomElement; +namespace AuroraUpdater { + +#define AURORA_INSTGEN_BUILD +#ifdef AURORA_INSTGEN_BUILD + +#ifdef Q_OS_WIN +#define CS Qt::CaseInsensitive +#else +#define CS Qt::CaseSensitive +#endif +class ArchiveFile { + QString mSource,mDest; + QRegExp mpat,mexclude; + + friend class Archive; + ArchiveFile(QString src,QString dst,QString pat,QString excl) + :mSource(src.replace('\\','/')), + mDest(dst.replace('\\','/')), + mpat(pat,CS,QRegExp::WildcardUnix), + mexclude(excl,CS,QRegExp::WildcardUnix) + {} +public: + ArchiveFile(){} + ArchiveFile(const ArchiveFile&)=default; + + QString sourcePath()const{return mSource;} + QString destinationPath()const{return mDest;} + QRegExp pattern()const{return mpat;} + QRegExp excludePattern()const{return mexclude;} + + bool fileMatches(QString filename)const; + QStringList getFiles()const; +}; +#undef CS +#endif + +///Description of a single Archive File +class Archive { + QString mName,msha1,mos,mcpu; + + friend class MetaFile; + ///instantiate from + Archive(const QDomElement&); +#ifdef AURORA_INSTGEN_BUILD + ///instantiate from and + Archive(const QDomElement&,const QString&,const QString&,const QString&); + QString mBuildBase,mZipBase; + bool misSource=false; + QListmFiles; +#endif +public: + Archive(){} + Archive(const Archive&)=default; + + QString name()const{return mName;} + + QString sha1sum()const{return msha1;} + + QString operatingSystem()const{return mos;} + QString cpu()const{return mcpu;} + +#ifdef AURORA_INSTGEN_BUILD + QString buildBaseDir()const{return mBuildBase;} + QString zipBaseDir()const{return mZipBase;} + bool isSource()const{return misSource;} + QListfilePatterns()const{return mFiles;} +#endif + +}; + +///Encapsulates meta files: XML descriptions of how to generate and/or download packages. +class MetaFile +{ + QDateTime mBuilt,mInstalled; + QString mVersionH,mVersionM,mBaseUrl,mIndexFile; + int mPollInterval=-1; + QListmArchives; + bool mValid=false; +public: + ///create empty meta file object, not recommended + MetaFile(){} + ///copies a meta file object + MetaFile(const MetaFile&)=default; + ///expects a file name and tries to read this file as an XML meta file + MetaFile(const QString&); + + QDateTime buildTime()const{return mBuilt;} + QDateTime installTime()const{return mInstalled;} + + QString version()const{return mVersionH;} + QString machineVersion()const{return mVersionM;} + + QString baseUrl()const{return mBaseUrl;} + QString indexFile()const{return mIndexFile;} + + int pollInterval()const{return mPollInterval;} + + QList archives()const{return mArchives;} + + bool isValid()const{return mValid;} + + static QString localPlatform(); +}; + +//end of namespace +}; + +using namespace AuroraUpdater; + +#endif diff --git a/aurora/dloader/dloader.pro b/aurora/dloader/dloader.pro index eb4acf6..8efa243 100644 --- a/aurora/dloader/dloader.pro +++ b/aurora/dloader/dloader.pro @@ -14,12 +14,14 @@ VERSION = 0.2.0 SOURCES += \ aurora.cpp \ subtask.cpp \ - gpgwrap.cpp + gpgwrap.cpp \ + ../common/metafile.cpp HEADERS += \ aurora.h \ subtask.h \ - gpgwrap.h + gpgwrap.h \ + ../common/metafile.h INCLUDEPATH += src gpg/include DEPENDPATH += $$INCLUDEPATH diff --git a/aurora/instgen/instgen.pro b/aurora/instgen/instgen.pro index bea4a7f..5758f88 100644 --- a/aurora/instgen/instgen.pro +++ b/aurora/instgen/instgen.pro @@ -3,7 +3,8 @@ TEMPLATE = app TARGET = instgen DESTDIR = $$PWD/../../bin QT -= gui -CONFIG += release hide_symbols separate_debug_info +QT += xml +CONFIG += release hide_symbols separate_debug_info console include ($$PWD/../../zip.pri) @@ -11,11 +12,26 @@ OBJECTS_DIR = .ctmp MOC_DIR = .ctmp RCC_DIR = .ctmp +DEFINES += AURORA_INSTGEN_BUILD=1 + +INCLUDEPATH += $$PWD/../common DEPENDPATH += $$INCLUDEPATH -SOURCES += main.cpp +SOURCES += main.cpp \ + ../common/metafile.cpp + +HEADERS += \ + ../common/metafile.h gcc { QMAKE_CXXFLAGS += -std=gnu++11 } + +linux { + QMAKE_CFLAGS += -fPIE + QMAKE_CXXFLAGS += -fPIE + QMAKE_LFLAGS += -pie + #make sure we find our libs + QMAKE_LFLAGS += -Wl,-rpath,\'\$$ORIGIN/../lib\' +} diff --git a/aurora/instgen/main.cpp b/aurora/instgen/main.cpp index 6bb1737..b13337f 100644 --- a/aurora/instgen/main.cpp +++ b/aurora/instgen/main.cpp @@ -4,11 +4,37 @@ // #include +#include +#include +#include + +#include "metafile.h" int main(int ac,char**av) { QCoreApplication app(ac,av); + //get parameters + if(app.arguments().size()!=2){ + qDebug()<<"Usage: instgen metafile.aurora"; + return 1; + } + + //get file + const QString mfname=app.arguments().at(1); + QFileInfo inf(mfname); + if(!inf.exists()){ + qDebug()<<"File"<