Browse Source

setup

PYADPT-55
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 -*- # -*- coding: utf-8 -*-
import sys # This file is under GNU Affero General Public License 3.0
import os # see LICENSE.txt
from distutils.core import setup, Extension
from setuptools import setup, Extension
from glob import glob from glob import glob
from distutils.errors import DistutilsOptionError from os import environ, uname
from os.path import dirname, exists, join
def option_value(name): from sys import argv
for index, option in enumerate(sys.argv):
if option == '--' + name:
if index+1 >= len(sys.argv): compile_args = ['-O0', '-g', '-UNDEBUG', '-std=c++14'] \
raise DistutilsOptionError( if '--debug' in argv or '-g' in argv else ['-std=c++14']
'The option %s requires a value' % option)
value = sys.argv[index+1]
sys.argv[index:index+2] = [] def find(file, pathlist):
return value for path in pathlist:
if option.startswith('--' + name + '='): _file = join(path, file)
value = option[len(name)+3:] if exists(_file):
sys.argv[index:index+1] = [] return dirname(_file)
return value raise FileNotFoundError(file)
env_val = os.getenv(name.upper().replace('-', '_'))
return env_val
includes = [
OPTION_PREFIX = option_value("prefix") join(environ['HOME'], 'include'),
OPTION_BOOST = option_value("boost") '/usr/include',
'/usr/local/include',
if OPTION_PREFIX is None : '/opt/local/include',
OPTION_PREFIX = os.environ["HOME"] join(environ['HOME'], 'share'),
'/usr/share',
if OPTION_BOOST is None : '/usr/local/share',
OPTION_BOOST = '/opt/local' '/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', module_pEp = Extension('pEp',
sources = glob('src/*.cc'), 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',], 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( setup(
name='p≡p Python adapter', name='p≡p Python adapter',
version='1.0', version='2.0',
description='Provides a Python module giving access to p≡p engine', description='Provides a Python module giving access to p≡p engine',
author="Volker Birk", author="Volker Birk",
author_email="vb@pep-project.org", 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 "basic_api.hh"
#include <sstream> #include <sstream>
#include <pEp/keymanagement.h> #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 #pragma once
#include "pEpmodule.hh" #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 "identity.hh"
#include "pEpmodule.hh" #include "pEpmodule.hh"
#include "basic_api.hh" #include "basic_api.hh"
@ -19,10 +22,6 @@ namespace pEp {
{ {
if (!_ident) if (!_ident)
throw bad_alloc(); 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->comm_type = (PEP_comm_type) comm_type;
_ident->flags = (identity_flags_t) flags; _ident->flags = (identity_flags_t) flags;
this->lang(lang); this->lang(lang);
@ -149,7 +148,22 @@ namespace pEp {
update_identity(*this); 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); 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 #pragma once
#include <boost/python.hpp> #include <boost/python.hpp>
@ -15,6 +18,7 @@ namespace pEp {
// Identity is owning a pEp_identity // Identity is owning a pEp_identity
class Identity { class Identity {
protected:
shared_ptr< pEp_identity > _ident; shared_ptr< pEp_identity > _ident;
public: public:
@ -24,7 +28,7 @@ namespace pEp {
Identity(const Identity& second); Identity(const Identity& second);
Identity(pEp_identity *ident); Identity(pEp_identity *ident);
~Identity(); virtual ~Identity();
operator pEp_identity *(); operator pEp_identity *();
operator const pEp_identity *() const; operator const pEp_identity *() const;
@ -58,8 +62,13 @@ namespace pEp {
Identity copy(); Identity copy();
Identity deepcopy(dict& memo); Identity deepcopy(dict& memo);
void update(); virtual void update();
void myself(); };
class Myself : public Identity {
public:
Myself(string address, string username, string user_id="", string lang="");
virtual void update();
}; };
Identity identity_attr(pEp_identity *&ident); 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 <Python.h>
#include "message.hh" #include "message.hh"
#include "message_api.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 #pragma once
#include <boost/python.hpp> #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 "message_api.hh"
#include <pEp/pEpEngine.h> #include <pEp/pEpEngine.h>
#include <pEp/message_api.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 #pragma once
#include "pEpmodule.hh" #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 "pEpmodule.hh"
#include <boost/locale.hpp> #include <boost/locale.hpp>
#include <string> #include <string>
@ -10,13 +13,13 @@
#include <mutex> #include <mutex>
#include <pEp/message_api.h> #include <pEp/message_api.h>
#include <pEp/sync.h> #include <pEp/sync_api.h>
namespace pEp { namespace pEp {
namespace PythonAdapter { namespace PythonAdapter {
using namespace std; 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() static string about()
{ {
string version = string(version_string) + "\np≡p version " 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") .add_property("color", &pEp::PythonAdapter::Identity::color, "color of Identity")
.def("__deepcopy__", &pEp::PythonAdapter::Identity::deepcopy) .def("__deepcopy__", &pEp::PythonAdapter::Identity::deepcopy)
.def("update", &pEp::PythonAdapter::Identity::update, "update Identity") .def("update", &pEp::PythonAdapter::Identity::update, "update Identity")
.def("myself", &pEp::PythonAdapter::Identity::myself, "mark as own Identity")
.def("__copy__", &pEp::PythonAdapter::Identity::copy); .def("__copy__", &pEp::PythonAdapter::Identity::copy);
identity_class.attr("PEP_OWN_USERID") = "pEp_own_userId"; 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/python.hpp>
#include <boost/locale.hpp> #include <boost/locale.hpp>
#include "str_attr.hh" #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 #pragma once
#include <string> #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 "sync_mixin.hh"
#include <pEp/sync.h>
#ifndef NDEBUG #ifndef NDEBUG
#include <pEp/sync_fsm.h> #include <pEp/KeySync_fsm.h>
#endif #endif
#include <assert.h> #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 #pragma once
#include "pEpmodule.hh" #include "pEpmodule.hh"
#include <setjmp.h> #include <setjmp.h>
#include <pEp/sync.h> #include <pEp/sync_api.h>
namespace pEp { namespace pEp {
namespace PythonAdapter { namespace PythonAdapter {

Loading…
Cancel
Save