From d65b2d1d520d0051c5f964cc75dd869ef69a284b Mon Sep 17 00:00:00 2001 From: Volker Birk Date: Fri, 24 Aug 2018 21:29:24 +0200 Subject: [PATCH] setup --- setup.py | 91 ++++++++++++++++++++++++++++----------------- src/basic_api.cc | 3 ++ src/basic_api.hh | 3 ++ src/identity.cc | 24 +++++++++--- src/identity.hh | 15 ++++++-- src/locked_queue.hh | 61 ++++++++++++++++++++++++++++++ src/message.cc | 3 ++ src/message.hh | 3 ++ src/message_api.cc | 3 ++ src/message_api.hh | 3 ++ src/pEpmodule.cc | 8 ++-- src/str_attr.cc | 3 ++ src/str_attr.hh | 3 ++ src/sync_mixin.cc | 6 ++- src/sync_mixin.hh | 5 ++- 15 files changed, 186 insertions(+), 48 deletions(-) create mode 100644 src/locked_queue.hh diff --git a/setup.py b/setup.py index a213224..609f524 100644 --- a/setup.py +++ b/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,], ) + diff --git a/src/basic_api.cc b/src/basic_api.cc index a747bb6..27341e3 100644 --- a/src/basic_api.cc +++ b/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 #include diff --git a/src/basic_api.hh b/src/basic_api.hh index 065b46c..332755d 100644 --- a/src/basic_api.hh +++ b/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" diff --git a/src/identity.cc b/src/identity.cc index 57fd096..691645d 100644 --- a/src/identity.cc +++ b/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); } diff --git a/src/identity.hh b/src/identity.hh index f07c828..02f7d09 100644 --- a/src/identity.hh +++ b/src/identity.hh @@ -1,3 +1,6 @@ +// This file is under GNU Affero General Public License 3.0 +// see LICENSE.txt + #pragma once #include @@ -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); diff --git a/src/locked_queue.hh b/src/locked_queue.hh new file mode 100644 index 0000000..88c7430 --- /dev/null +++ b/src/locked_queue.hh @@ -0,0 +1,61 @@ +#pragma once + +#include +#include + +namespace utility +{ + using namespace std; + + template class locked_queue + { + mutex _mtx; + list _q; + + public: + T& back() + { + lock_guard lg(_mtx); + return _q.back(); + } + T& front() + { + lock_guard lg(_mtx); + return _q.front(); + } + T pop_back() + { + lock_guard lg(_mtx); + T r = _q.back(); + _q.pop_back(); + return r; + } + T pop_front() + { + lock_guard lg(_mtx); + T r = _q.front(); + _q.pop_front(); + return r; + } + void push_back(const T& data) + { + lock_guard lg(_mtx); + _q.push_back(data); + } + void push_front(const T& data) + { + lock_guard lg(_mtx); + _q.push_front(data); + } + size_t size() + { + lock_guard lg(_mtx); + return _q.size(); + } + bool empty() + { + lock_guard lg(_mtx); + return _q.empty(); + } + }; +}; diff --git a/src/message.cc b/src/message.cc index d402654..81999bf 100644 --- a/src/message.cc +++ b/src/message.cc @@ -1,3 +1,6 @@ +// This file is under GNU Affero General Public License 3.0 +// see LICENSE.txt + #include #include "message.hh" #include "message_api.hh" diff --git a/src/message.hh b/src/message.hh index d910e9b..b4cb038 100644 --- a/src/message.hh +++ b/src/message.hh @@ -1,3 +1,6 @@ +// This file is under GNU Affero General Public License 3.0 +// see LICENSE.txt + #pragma once #include diff --git a/src/message_api.cc b/src/message_api.cc index 601ec75..74e8c90 100644 --- a/src/message_api.cc +++ b/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 #include diff --git a/src/message_api.hh b/src/message_api.hh index a652838..98daee7 100644 --- a/src/message_api.hh +++ b/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" diff --git a/src/pEpmodule.cc b/src/pEpmodule.cc index 3932029..c5551a9 100644 --- a/src/pEpmodule.cc +++ b/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 #include @@ -10,13 +13,13 @@ #include #include -#include +#include 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"; diff --git a/src/str_attr.cc b/src/str_attr.cc index 68ee145..3069e37 100644 --- a/src/str_attr.cc +++ b/src/str_attr.cc @@ -1,3 +1,6 @@ +// This file is under GNU Affero General Public License 3.0 +// see LICENSE.txt + #include #include #include "str_attr.hh" diff --git a/src/str_attr.hh b/src/str_attr.hh index 2f7bd8d..1292b6c 100644 --- a/src/str_attr.hh +++ b/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 diff --git a/src/sync_mixin.cc b/src/sync_mixin.cc index 6741b93..8333609 100644 --- a/src/sync_mixin.cc +++ b/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 #ifndef NDEBUG -#include +#include #endif #include diff --git a/src/sync_mixin.hh b/src/sync_mixin.hh index 6104af7..65c0e0d 100644 --- a/src/sync_mixin.hh +++ b/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 -#include +#include namespace pEp { namespace PythonAdapter {