diff --git a/.gitignore b/.gitignore index f7defeefe4797bd1bef2f7f657caaa1734c5fbc1..676fb2d172068cfe2b94d2240e947ce0c07e6039 100644 --- a/.gitignore +++ b/.gitignore @@ -130,3 +130,6 @@ tests/failed_blocks/ # pyrest tests *.out.json + +# version.py +version.py diff --git a/hive/conf.py b/hive/conf.py index ee80ad06585f7591526317faf637ce5a469ccffa..b2dc0fc827dc11472bd81df99a22cf8c3bbaadd1 100644 --- a/hive/conf.py +++ b/hive/conf.py @@ -61,8 +61,13 @@ class Conf(): # configure logger and print config root = logging.getLogger() root.setLevel(conf.log_level()) - root.info("loaded configuration:\n%s", - _sanitized_conf(parser)) + + from sys import argv + root.info("Used command line args: %s", " ".join(argv[1:])) + + # uncomment for full list of program args + #args_list = ["--" + k + " " + str(v) for k,v in vars(args).items()] + #root.info("Full command line args: %s", " ".join(args_list)) if conf.mode() == 'server': #DbStats.SLOW_QUERY_MS = 750 diff --git a/hive/server/hive_api/public.py b/hive/server/hive_api/public.py index 290cf777910345cbc2488d7cd7c75d7264f38548..b68ec808fd49c9fb6c63c7d3a4c109adb3779a53 100644 --- a/hive/server/hive_api/public.py +++ b/hive/server/hive_api/public.py @@ -10,6 +10,7 @@ from hive.server.condenser_api.cursor import get_followers, get_following from hive.server.bridge_api.cursor import ( pids_by_blog, pids_by_comments, pids_by_feed_with_reblog) +from hive.db.schema import DB_VERSION as SCHEMA_DB_VERSION log = logging.getLogger(__name__) @@ -108,3 +109,20 @@ async def list_account_feed(context, account, limit=10, observer=None, last_post if rby: post['reblogged_by'] = list(rby) return posts + +async def get_info(context): + db = context['db'] + + sql = "SELECT num FROM hive_blocks ORDER BY num DESC LIMIT 1" + database_head_block = await db.query_one(sql) + + from hive.version import VERSION, GIT_REVISION + + ret = { + "hivemind_version" : VERSION, + "hivemind_git_rev" : GIT_REVISION, + "database_schema_version" : SCHEMA_DB_VERSION, + "database_head_block" : database_head_block + } + + return ret diff --git a/hive/server/serve.py b/hive/server/serve.py index 03789a5bcfb628f59d97eeb18aa17c05faf4dfd0..23770fb7f5969bbf88bfd0f049fdd5e48ea54ceb 100644 --- a/hive/server/serve.py +++ b/hive/server/serve.py @@ -27,6 +27,7 @@ from hive.server.bridge_api.support import get_post_header as bridge_api_get_pos from hive.server.hive_api import community as hive_api_community from hive.server.hive_api import notify as hive_api_notify from hive.server.hive_api import stats as hive_api_stats +from hive.server.hive_api.public import get_info as hive_api_get_info from hive.server.follow_api import methods as follow_api from hive.server.tags_api import methods as tags_api @@ -62,6 +63,8 @@ def build_methods(): db_head_state, )}) + methods.add(**{'hive.get_info' : hive_api_get_info}) + methods.add(**{'condenser_api.' + method.__name__: method for method in ( condenser_api.get_followers, condenser_api.get_following, @@ -220,7 +223,24 @@ def run_server(conf): app['db'].close() await app['db'].wait_closed() + async def show_info(app): + sql = "SELECT num FROM hive_blocks ORDER BY num DESC LIMIT 1" + database_head_block = await app['db'].query_one(sql) + + import pkg_resources + hivemind_version, hivemind_git_rev = pkg_resources.get_distribution("hivemind").version.split("+") + + from hive.version import VERSION, GIT_REVISION + log.info("hivemind_version : %s", VERSION) + log.info("hivemind_git_rev : %s", GIT_REVISION) + + from hive.db.schema import DB_VERSION as SCHEMA_DB_VERSION + log.info("database_schema_version : %s", SCHEMA_DB_VERSION) + + log.info("database_head_block : %s", database_head_block) + app.on_startup.append(init_db) + app.on_startup.append(show_info) app.on_cleanup.append(close_db) async def head_age(request): diff --git a/hive/version.py b/hive/version.py new file mode 100644 index 0000000000000000000000000000000000000000..d0ae1a49a62f29971ea2b2eff545df2cf6a41082 --- /dev/null +++ b/hive/version.py @@ -0,0 +1,4 @@ +# generated by setup.py +# contents will be overwritten +VERSION = '0.0.1' +GIT_REVISION = '5c0b832' diff --git a/setup.py b/setup.py index 7ade2c64711c120aa1fb42e054df1446ad373ce8..ee620402ef511d844a44d780d3735700493a957e 100644 --- a/setup.py +++ b/setup.py @@ -1,11 +1,20 @@ # coding=utf-8 import sys +import os from setuptools import find_packages from setuptools import setup assert sys.version_info[0] == 3 and sys.version_info[1] >= 6, "hive requires Python 3.6 or newer" +def get_git_version(): + from git import Repo + repo = Repo(os.path.abspath(".")) + return repo.git.rev_parse('--short', 'HEAD') + +VERSION = '0.0.1' +GIT_REVISION = get_git_version() + tests_require = [ 'pytest', 'pytest-cov', @@ -17,10 +26,16 @@ tests_require = [ 'yapf', ] +with open("hive/version.py", 'w') as version_file: + version_file.write("# generated by setup.py\n") + version_file.write("# contents will be overwritten\n") + version_file.write("VERSION = '{}'\n".format(VERSION)) + version_file.write("GIT_REVISION = '{}'\n".format(GIT_REVISION)) + # yapf: disable setup( name='hivemind', - version_format='0.0.1+{gitsha}', + version_format=VERSION + "+" + GIT_REVISION, description='Developer-friendly microservice powering social networks on the Steem blockchain.', long_description=open('README.md').read(), packages=find_packages(exclude=['scripts']),