Browse Source

setup

master
Volker Birk 7 years ago
parent
commit
d65b2d1d52
  1. 91
      setup.py
  2. 3
      src/basic_api.cc
  3. 3
      src/basic_api.hh
  4. 24
      src/identity.cc
  5. 15
      src/identity.hh
  6. 61
      src/locked_queue.hh
  7. 3
      src/message.cc
  8. 3
      src/message.hh
  9. 3
      src/message_api.cc
  10. 3
      src/message_api.hh
  11. 8
      src/pEpmodule.cc
  12. 3
      src/str_attr.cc
  13. 3
      src/str_attr.hh
  14. 6
      src/sync_mixin.cc
  15. 5
      src/sync_mixin.hh

91
setup.py

@ -1,49 +1,72 @@
# -*- coding: utf-8 -*-
import sys
import os
from distutils.core import setup, Extension
# This file is under GNU Affero General Public License 3.0
# see LICENSE.txt
from setuptools import setup, Extension
from glob import glob
from distutils.errors import DistutilsOptionError
def option_value(name):
for index, option in enumerate(sys.argv):
if option == '--' + name:
if index+1 >= len(sys.argv):
raise DistutilsOptionError(
'The option %s requires a value' % option)
value = sys.argv[index+1]
sys.argv[index:index+2] = []
return value
if option.startswith('--' + name + '='):
value = option[len(name)+3:]
sys.argv[index:index+1] = []
return value
env_val = os.getenv(name.upper().replace('-', '_'))
return env_val
OPTION_PREFIX = option_value("prefix")
OPTION_BOOST = option_value("boost")
if OPTION_PREFIX is None :
OPTION_PREFIX = os.environ["HOME"]
if OPTION_BOOST is None :
OPTION_BOOST = '/opt/local'
from os import environ, uname
from os.path import dirname, exists, join
from sys import argv
compile_args = ['-O0', '-g', '-UNDEBUG', '-std=c++14'] \
if '--debug' in argv or '-g' in argv else ['-std=c++14']
def find(file, pathlist):
for path in pathlist:
_file = join(path, file)
if exists(_file):
return dirname(_file)
raise FileNotFoundError(file)
includes = [
join(environ['HOME'], 'include'),
'/usr/include',
'/usr/local/include',
'/opt/local/include',
join(environ['HOME'], 'share'),
'/usr/share',
'/usr/local/share',
'/opt/local/share',
]
libraries = [
join(environ['HOME'], 'lib'),
'/usr/lib',
'/usr/local/lib',
'/opt/local/lib',
]
libext = '.dylib' if uname().sysname == 'Darwin' else '.so'
search_for_includes = 'pEp', 'boost', 'asn1c/asn_system.h'
search_for_libraries = 'libpEpengine' + libext, 'libboost_python3-mt' + libext
module_pEp = Extension('pEp',
sources = glob('src/*.cc'),
include_dirs = [OPTION_PREFIX+'/include', OPTION_BOOST+'/include',],
library_dirs = [OPTION_PREFIX+'/lib', OPTION_BOOST+'/lib',],
libraries = ['pEpEngine', 'boost_python3-mt', 'boost_locale-mt',],
extra_compile_args = ['-O0', '-UNDEBUG', '-std=c++14',],
extra_compile_args = compile_args,
include_dirs = set( [ find(file, includes) for file in
search_for_includes ] ),
library_dirs = set( [ find(file, libraries) for file in
search_for_libraries ] ),
)
setup(
name='p≡p Python adapter',
version='1.0',
version='2.0',
description='Provides a Python module giving access to p≡p engine',
author="Volker Birk",
author_email="vb@pep-project.org",
ext_modules=[module_pEp]
ext_modules=[module_pEp,],
)

3
src/basic_api.cc

@ -1,3 +1,6 @@
// This file is under GNU Affero General Public License 3.0
// see LICENSE.txt
#include "basic_api.hh"
#include <sstream>
#include <pEp/keymanagement.h>

3
src/basic_api.hh

@ -1,3 +1,6 @@
// This file is under GNU Affero General Public License 3.0
// see LICENSE.txt
#pragma once
#include "pEpmodule.hh"

24
src/identity.cc

@ -1,3 +1,6 @@
// This file is under GNU Affero General Public License 3.0
// see LICENSE.txt
#include "identity.hh"
#include "pEpmodule.hh"
#include "basic_api.hh"
@ -19,10 +22,6 @@ namespace pEp {
{
if (!_ident)
throw bad_alloc();
if (username.length() && username.length() < 5) {
_ident = nullptr;
throw length_error("username must be at least 5 characters");
}
_ident->comm_type = (PEP_comm_type) comm_type;
_ident->flags = (identity_flags_t) flags;
this->lang(lang);
@ -149,7 +148,22 @@ namespace pEp {
update_identity(*this);
}
void Identity::myself()
Myself::Myself(string address, string username, string user_id, string lang)
: Identity(address, username, user_id, "", 0, lang)
{
if (!(address.length() && username.length()))
throw invalid_argument("address and username must be set");
if (lang.length() && lang.length() != 2)
throw length_error("lang must be an ISO 639-1 language code or empty");
// FIXME: should set .me
// _ident->me = true;
if (user_id.length())
throw runtime_error("user_id feature not yet implemented for Myself");
}
void Myself::update()
{
pEp::PythonAdapter::myself(*this);
}

15
src/identity.hh

@ -1,3 +1,6 @@
// This file is under GNU Affero General Public License 3.0
// see LICENSE.txt
#pragma once
#include <boost/python.hpp>
@ -15,6 +18,7 @@ namespace pEp {
// Identity is owning a pEp_identity
class Identity {
protected:
shared_ptr< pEp_identity > _ident;
public:
@ -24,7 +28,7 @@ namespace pEp {
Identity(const Identity& second);
Identity(pEp_identity *ident);
~Identity();
virtual ~Identity();
operator pEp_identity *();
operator const pEp_identity *() const;
@ -58,8 +62,13 @@ namespace pEp {
Identity copy();
Identity deepcopy(dict& memo);
void update();
void myself();
virtual void update();
};
class Myself : public Identity {
public:
Myself(string address, string username, string user_id="", string lang="");
virtual void update();
};
Identity identity_attr(pEp_identity *&ident);

61
src/locked_queue.hh

@ -0,0 +1,61 @@
#pragma once
#include <list>
#include <mutex>
namespace utility
{
using namespace std;
template<class T> class locked_queue
{
mutex _mtx;
list<T> _q;
public:
T& back()
{
lock_guard<mutex> lg(_mtx);
return _q.back();
}
T& front()
{
lock_guard<mutex> lg(_mtx);
return _q.front();
}
T pop_back()
{
lock_guard<mutex> lg(_mtx);
T r = _q.back();
_q.pop_back();
return r;
}
T pop_front()
{
lock_guard<mutex> lg(_mtx);
T r = _q.front();
_q.pop_front();
return r;
}
void push_back(const T& data)
{
lock_guard<mutex> lg(_mtx);
_q.push_back(data);
}
void push_front(const T& data)
{
lock_guard<mutex> lg(_mtx);
_q.push_front(data);
}
size_t size()
{
lock_guard<mutex> lg(_mtx);
return _q.size();
}
bool empty()
{
lock_guard<mutex> lg(_mtx);
return _q.empty();
}
};
};

3
src/message.cc

@ -1,3 +1,6 @@
// This file is under GNU Affero General Public License 3.0
// see LICENSE.txt
#include <Python.h>
#include "message.hh"
#include "message_api.hh"

3
src/message.hh

@ -1,3 +1,6 @@
// This file is under GNU Affero General Public License 3.0
// see LICENSE.txt
#pragma once
#include <boost/python.hpp>

3
src/message_api.cc

@ -1,3 +1,6 @@
// This file is under GNU Affero General Public License 3.0
// see LICENSE.txt
#include "message_api.hh"
#include <pEp/pEpEngine.h>
#include <pEp/message_api.h>

3
src/message_api.hh

@ -1,3 +1,6 @@
// This file is under GNU Affero General Public License 3.0
// see LICENSE.txt
#pragma once
#include "pEpmodule.hh"

8
src/pEpmodule.cc

@ -1,3 +1,6 @@
// This file is under GNU Affero General Public License 3.0
// see LICENSE.txt
#include "pEpmodule.hh"
#include <boost/locale.hpp>
#include <string>
@ -10,13 +13,13 @@
#include <mutex>
#include <pEp/message_api.h>
#include <pEp/sync.h>
#include <pEp/sync_api.h>
namespace pEp {
namespace PythonAdapter {
using namespace std;
static const char *version_string = "p≡p Python adapter version 0.1";
static const char *version_string = "p≡p Python adapter version 0.2";
static string about()
{
string version = string(version_string) + "\np≡p version "
@ -120,7 +123,6 @@ BOOST_PYTHON_MODULE(pEp)
.add_property("color", &pEp::PythonAdapter::Identity::color, "color of Identity")
.def("__deepcopy__", &pEp::PythonAdapter::Identity::deepcopy)
.def("update", &pEp::PythonAdapter::Identity::update, "update Identity")
.def("myself", &pEp::PythonAdapter::Identity::myself, "mark as own Identity")
.def("__copy__", &pEp::PythonAdapter::Identity::copy);
identity_class.attr("PEP_OWN_USERID") = "pEp_own_userId";

3
src/str_attr.cc

@ -1,3 +1,6 @@
// This file is under GNU Affero General Public License 3.0
// see LICENSE.txt
#include <boost/python.hpp>
#include <boost/locale.hpp>
#include "str_attr.hh"

3
src/str_attr.hh

@ -1,3 +1,6 @@
// This file is under GNU Affero General Public License 3.0
// see LICENSE.txt
#pragma once
#include <string>

6
src/sync_mixin.cc

@ -1,7 +1,9 @@
// This file is under GNU Affero General Public License 3.0
// see LICENSE.txt
#include "sync_mixin.hh"
#include <pEp/sync.h>
#ifndef NDEBUG
#include <pEp/sync_fsm.h>
#include <pEp/KeySync_fsm.h>
#endif
#include <assert.h>

5
src/sync_mixin.hh

@ -1,8 +1,11 @@
// This file is under GNU Affero General Public License 3.0
// see LICENSE.txt
#pragma once
#include "pEpmodule.hh"
#include <setjmp.h>
#include <pEp/sync.h>
#include <pEp/sync_api.h>
namespace pEp {
namespace PythonAdapter {

Loading…
Cancel
Save