Initial commit with some basic code

parents
Parcel.*
===============================
Contribution Guide for Parcel
===============================
:Author:
* **A. Wilcox**, documentation writer
:Status:
Draft
:Copyright:
© 2018 Adélie Linux Team. NCSA open source licence.
Introduction
============
This repository contains code and documentation for Parcel, the next-generation
package lifecycle management system for Adélie Linux.
License
```````
As the Adélie Linux project is an open-source Linux distribution, this package
is distributed under the same NCSA open source license as the distribution.
Changes
```````
Any changes to this repository must be reviewed before being pushed to the
master branch. There are no exceptions to this rule. For security-sensitive
updates, contact the Security Team at sec-bugs@adelielinux.org.
Testing
=======
You **must** test any changes on Adélie Linux. It is recommended that you
additionally test your changes on at least a glibc-based Linux distribution.
Contributing Changes
====================
This section describes the usual flows of contribution to this repository.
GitLab Pull Requests
````````````````````
#. If you do not already have a GitLab account, you must create one.
#. Create a *fork* of the packages repository. For more information, consult
the GitLab online documentation.
#. Clone your forked repository to your computer.
#. Make your changes.
#. Test your changes to ensure they are correct.
#. Add (or remove) changed files using ``git add`` and ``git rm``.
#. Commit your changes to the tree using the command ``git commit`` and
``git push``.
#. Visit your forked repository in a Web browser.
#. Choose the *Create Pull Request* button.
#. Review your changes to ensure they are correct, and then submit the form.
Mailing List
````````````
#. Clone the packages repository to your computer.
#. Make your changes.
#. Test your changes to ensure they are correct.
#. Add (or remove) changed files using ``git add`` and ``git rm``.
#. Commit your changes to the tree using the command ``git commit``.
#. Use the command ``git format-patch HEAD^`` to create a patch file for your
commit.
.. note:: If you have made multiple commits to the tree, you will need to
add an additional ^ for each commit you have made. For example,
if you have made three commits, you will use the command
``git format-patch HEAD^^^``.
#. Email the resulting patch to the `Parcel mailing list`_.
.. _Parcel mailing list: https://lists.adelielinux.org/postorius/lists/parcel.lists.adelielinux.org/
Copyright (c) 2018 Adélie Linux Team.
All rights reserved.
Developed by: Adélie Linux Team
http://adelielinux.org/
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal with the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject
to the following conditions:
Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimers.
Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimers in
the documentation and/or other materials provided with the distribution.
Neither the names of Adélie Linux, nor the names of its contributors, may
be used to endorse or promote products derived from this Software without
specific prior written permission.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE.
===================
README for Parcel
===================
:Authors:
* **A. Wilcox**, maintainer, principal developer
:Status:
Early Alpha
:Copyright:
© 2018 Adélie Linux Team. NCSA open source licence.
Introduction
============
This repository contains code and documentation for Parcel, the next-generation
package lifecycle management system for Adélie Linux.
The main code lives in the lib directory, which is where the Parcel library
code lives. The utilities, tools, and Web site that comprise the Parcel system
are all based upon this library.
License
```````
As the Adélie Linux project is an open-source Linux distribution, this package
is distributed under the same NCSA open source license as the distribution.
Changes
```````
Any changes to this repository must be reviewed before being pushed to the
master branch. There are no exceptions to this rule. For security-sensitive
updates, contact the Security Team at sec-bugs@adelielinux.org.
Building
========
Use CMake. XX: write more here
#include <cassert>
#include "Package.hh"
namespace Parcel {
bool operator<(const PackageVersion &left, const PackageVersion &right)
{
assert("NYI");
return false;
}
Package::Package(std::istream& from_pkginfo)
{
}
}
#include <cstdint>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>
using std::string;
namespace Parcel {
class PackageVersion {
public:
PackageVersion(std::string from) {
string::size_type revplace = from.rfind("-r");
if(revplace == string::npos) {
_version = string(from);
_revision = 0;
} else {
_version = string(from, 0, revplace);
try {
_revision = std::stoul(from.substr(revplace + 2));
} catch (std::invalid_argument) {
std::cerr << "invalid revision number: " << from.substr(revplace + 2) << std::endl;
_revision = 0;
} catch (std::out_of_range) {
std::cerr << "revision number unrepresentable: " << from.substr(revplace + 2) << std::endl;
_revision = 0;
}
}
}
const string version() {
return this->_version;
}
unsigned long revision() {
return this->_revision;
}
friend bool operator<(const PackageVersion &left, const PackageVersion &right);
friend bool operator>(const PackageVersion &left, const PackageVersion &right) { return right < left; }
private:
string _version;
unsigned long _revision;
};
class Package {
public:
const string pkgname() { return _name; }
const PackageVersion pkgver() { return PackageVersion(_version); }
const string pkgdesc() { return _description; }
const string url() { return _url; }
uint64_t size() { return _install_size; }
const string license() { return _license; }
const string arch() { return _arch; }
std::vector<string> depends() { return _dependencies; }
std::vector<string> install_if() { return _install_if; }
std::vector<string> provides() { return _provides; }
std::vector<string> replaces() { return _replaces; }
const string maintainer() { return _maintainer; }
uint64_t builddate() { return _built_at; }
const string commit() { return _commit_id; }
const string origin() { return _origin; }
private:
string _name;
string _version;
string _description;
string _url;
uint64_t _install_size;
string _license;
string _arch;
std::vector<string> _dependencies;
std::vector<string> _install_if;
std::vector<string> _provides;
std::vector<string> _replaces;
uint64_t _replaces_priority;
string _maintainer;
uint64_t _built_at;
string _commit_id;
string _origin;
Package(std::istream& from_pkginfo);
friend class Repository;
};
}
#include "Repository.hh"
#include <iostream>
#include <sstream>
namespace Parcel {
Repository::Repository(std::istream& from_index) {
string nextpkg;
// libreoffice-common p: line is current record with 4241 bytes
char nextline[16384];
while(from_index.getline(nextline, 16384)) {
if(nextline[0] == '\0') {
// Spurious empty line at beginning / end of index?
if(nextpkg.length() == 0) { continue; }
// Empty line means this package is completely read.
std::istringstream stream(nextpkg);
_packages.push_back(Package(stream));
nextpkg = "";
continue;
}
nextpkg.append(nextline);
nextpkg.append("\n");
}
if(from_index.fail() && !from_index.eof()) {
std::cerr << "I/O FAILURE parsing repository index file" << std::endl;
}
for(auto pkg : _packages) _origins.insert(pkg.origin());
}
}
#include <iostream>
#include <string>
#include <unordered_set>
#include <vector>
#include "Package.hh"
using std::string;
namespace Parcel {
class Repository
{
public:
Repository(std::istream& from_index);
std::vector<Package> packages() { return _packages; }
unsigned long package_count() { return _packages.size(); }
std::vector<string> origins() { return std::vector<string>(_origins.begin(), _origins.end()); }
unsigned long origin_count() { return _origins.size(); }
private:
std::vector<Package> _packages;
std::unordered_set<string> _origins;
};
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#include <cassert>
#include "../Package.hh"
using namespace Parcel;
void test_packageversions()
{
PackageVersion valid("1.1-r1");
assert(valid.version() == "1.1");
assert(valid.revision() == 1);
PackageVersion norev("1.2.3");
assert(norev.version() == "1.2.3");
assert(norev.revision() == 0);
PackageVersion blank("");
assert(blank.version() == "");
assert(blank.revision() == 0);
PackageVersion corruptrev("1.1_alpha4-rX");
assert(corruptrev.version() == "1.1_alpha4");
assert(corruptrev.revision() == 0);
PackageVersion multirev("1.1-r1-r4");
assert(multirev.version() == "1.1-r1");
assert(multirev.revision() == 4);
}
int main(void)
{
test_packageversions();
return 0;
}
#include <cassert>
#include <fstream>
#include <iostream>
#include <map>
#include "../Repository.hh"
using namespace Parcel;
Repository *make_repo_from_file(string filename) {
std::ifstream my_file(filename);
if(!my_file) return nullptr;
return new Repository(my_file);
}
std::multimap<unsigned long, string> repofiles = {
// Number of packages in repo, Repo file name
{ 43, "NormalRepo" },
{ 43, "ExtraNewlineAtBegin" },
{ 43, "ExtraNewlineAtEnd" },
{ 43, "ExtraNewlineAtBoth" },
{ 43, "ExtraNewlineInMiddle" },
{ 1524, "ActualSystemRepo" },
{ 7320, "ActualUserRepo" }
};
void test_repository() {
Repository *test_repo;
for(auto repo : repofiles) {
test_repo = make_repo_from_file(repo.second);
if(test_repo == nullptr) {
std::cerr << "Ack! Can't load index file: " << repo.second << std::endl;
continue;
}
assert(test_repo->package_count() == repo.first);
delete test_repo;
}
}
int main(void)
{
test_repository();
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment