From a7c3d8869c2efa17ad9a02fdc1c48811258e090d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Fri, 18 Sep 2015 12:03:56 +0200 Subject: [PATCH] Add version-related methods --- pymisp/__init__.py | 2 ++ pymisp/api.py | 34 +++++++++++++++++++++++++++++++++- setup.py | 4 +++- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/pymisp/__init__.py b/pymisp/__init__.py index e4c98cb..592d0af 100644 --- a/pymisp/__init__.py +++ b/pymisp/__init__.py @@ -1 +1,3 @@ +__version__ = '1.10' + from .api import PyMISP diff --git a/pymisp/api.py b/pymisp/api.py index dc457f4..2f94a92 100644 --- a/pymisp/api.py +++ b/pymisp/api.py @@ -5,9 +5,10 @@ import json import datetime -import requests import os import base64 +import re + try: from urllib.parse import urljoin except ImportError: @@ -17,6 +18,14 @@ import zipfile import warnings import functools +try: + import requests + HAVE_REQUESTS = True +except ImportError: + HAVE_REQUESTS = False + +from . import __version__ + # Least dirty way to support python 2 and 3 try: basestring @@ -38,6 +47,10 @@ class NewAttributeError(PyMISPError): pass +class MissingDependency(PyMISPError): + pass + + def deprecated(func): '''This is a decorator which can be used to mark functions as deprecated. It will result in a warning being emitted @@ -92,6 +105,8 @@ class PyMISP(object): (overwrite the constructor) """ + if not HAVE_REQUESTS: + raise MissingDependency('Missing dependency, install requests (`pip install requests`)') if force_out is not None: out = force_out else: @@ -597,6 +612,23 @@ class PyMISP(object): # ########## Version ########## + def get_api_version(self): + """ + Returns the current version of PyMISP installed on the system + """ + return {'version': __version__} + + def get_api_version_master(self): + """ + Get the most recent version of PyMISP from github + """ + r = requests.get('https://raw.githubusercontent.com/MISP/PyMISP/master/pymisp/__init__.py') + if r.status_code == 200: + version = re.findall("__version__ = '(.*)'", r.text) + return {'version': version[0]} + else: + return {'message': 'Impossible to retrieve the version of the master branch.'} + def get_version(self): """ Returns the version of the instance. diff --git a/setup.py b/setup.py index c7fc2e5..46c76de 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,12 @@ #!/usr/bin/python # -*- coding: utf-8 -*- from setuptools import setup +import pymisp + setup( name='pymisp', - version='1.10', + version=pymisp.__version__, author='Raphaël Vinot', author_email='raphael.vinot@circl.lu', maintainer='Raphaël Vinot',