Skip to content
This repository has been archived by the owner on Nov 19, 2017. It is now read-only.

Commit

Permalink
Create manage tool
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeroen van der Heijden committed Oct 17, 2016
1 parent 2fa45a0 commit 3fa7739
Show file tree
Hide file tree
Showing 11 changed files with 261 additions and 11 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
siridb-manage (2.0.0) xenial; urgency=medium

* Manage Tool for SiriDB version 2.x

-- Jeroen van der Heijden <jeroen@transceptor.technology> Mon, 17 Oct 2016 18:43:03 +0000

1 change: 1 addition & 0 deletions ChangeLog-2.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Manage Tool for SiriDB version 2.x
173 changes: 173 additions & 0 deletions build_deb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
#!/usr/bin/python3

import sys
import os
import datetime
import platform
import subprocess
import shutil
import stat
import re

from version import __version__



def _get_changelog(version):
with open('ChangeLog-{}'.format(version), 'r') as f:
content = f.read()
return content

def _get_distribution():
'''Returns distribution code name. (Ubuntu)'''
proc = subprocess.Popen(['lsb_release', '-c'], stdout=subprocess.PIPE)
for line in proc.stdout:
if line:
return line.decode().split('\t')[1].strip()


if __name__ == '__main__':
# Run setup.py to create executable
subprocess.call(['python3', 'setup.py', 'build'])

# Read the current version
if __version__ is None:
exit('Cannot find version in file: {}'.format(VERSION_FILE))

changelog = _get_changelog(__version__)
# Explain architecture= amd64
# The architecture is AMD64-compatible and Debian AMD64 will run on AMD and
# Intel processors with 64-bit support.
# Because of the technology paternity, Debian uses the name "AMD64".

config = dict(
version=__version__,
name='Jeroen van der Heijden',
email='jeroen@transceptor.technology',
company='Transceptor Technology',
company_email='info@transceptor.technology',
datetime=datetime.datetime.utcnow().strftime(
'%a, %d %b %Y %H:%M:%S') + ' +0000',
architecture={
'32bit': 'i386',
'64bit': 'amd64'}[platform.architecture()[0]],
archother={
'32bit': 'i386',
'64bit': 'x86_64'}[platform.architecture()[0]],
homepage='http://siridb.net',
distribution=_get_distribution(),
curdate=datetime.datetime.utcnow().strftime('%d %b %Y'),
year=datetime.datetime.utcnow().year,
package='siridb-manage',
description='SiriDB Manage Tool',
long_description='''
Tool for creating and extending SiriDB time series databases.
'''.rstrip(),
explain='create and extend a SiriDB time series database',
depends='${shlibs:Depends}, '
'${misc:Depends}',
changelog=changelog.strip()
)

OVERRIDES = open(
'deb/OVERRIDES', 'r').read().strip().format(**config)
CHANGELOG = open(
'deb/CHANGELOG', 'r').read().strip().format(**config)
CONTROL = open(
'deb/CONTROL', 'r').read().strip().format(**config)
MANPAGE = open(
'deb/MANPAGE', 'r').read().strip().format(**config)
COPYRIGHT = open(
'deb/COPYRIGHT', 'r').read().strip().format(**config)
RULES = open(
'deb/RULES', 'r').read().strip()

temp_path = os.path.join('build', 'temp')
if os.path.isdir(temp_path):
shutil.rmtree(temp_path)

source_path = os.path.join('build', __version__)
if not os.path.isdir(source_path):
sys.exit('ERROR: Cannot find path: {}'.format(source_path))

deb_file = '{package}_{version}_{architecture}.deb'.format(**config)
source_deb = os.path.join(temp_path, deb_file)
dest_deb = os.path.join('build', deb_file)

if os.path.exists(dest_deb):
os.unlink(dest_deb)

pkg_path = os.path.join(temp_path, '{}-{}'.format(config['package'],
config['version']))
debian_path = os.path.join(pkg_path, 'debian')

pkg_src_path = os.path.join(pkg_path, 'src')

debian_source_path = os.path.join(debian_path, 'source')

target_path = os.path.join(pkg_src_path, 'usr', 'lib', 'siridb', 'manage')

os.makedirs(debian_source_path)
shutil.copytree(source_path, target_path)

with open(os.path.join(debian_path, 'source', 'format'), 'w') as f:
f.write('3.0 (quilt)')

with open(os.path.join(debian_path, 'compat'), 'w') as f:
f.write('9')

changelog_file = 'ChangeLog'

if os.path.isfile(changelog_file):
with open(changelog_file, 'r') as f:
current_changelog = f.read()
else:
current_changelog = ''

if '{package} ({version})'.format(**config) not in current_changelog:
changelog = CHANGELOG + '\n\n' + current_changelog

with open(changelog_file, 'w') as f:
f.write(changelog)

shutil.copy(changelog_file, os.path.join(debian_path, 'changelog'))

with open(os.path.join(debian_path, 'control'), 'w') as f:
f.write(CONTROL)

with open(os.path.join(debian_path, 'copyright'), 'w') as f:
f.write(COPYRIGHT)

rules_file = os.path.join(debian_path, 'rules')
with open(rules_file, 'w') as f:
f.write(RULES)

os.chmod(rules_file, os.stat(rules_file).st_mode | stat.S_IEXEC)

with open(os.path.join(debian_path, 'links'), 'w') as f:
f.write('/usr/lib/siridb/manage/{package} /usr/sbin/{package}\n'.format(
**config))

with open(os.path.join(debian_path, 'install'), 'w') as f:
f.write('''src/usr /''')

with open(os.path.join(debian_path, '{}.1'.format(
config['package'])), 'w') as f:
f.write(MANPAGE)

with open(os.path.join(debian_path, '{}.manpages'.format(
config['package'])), 'w') as f:
f.write('debian/{}.1'.format(config['package']))

with open(os.path.join(debian_path, '{}.lintian-overrides'.format(
config['package'])), 'w') as f:
f.write(OVERRIDES)

subprocess.call(['debuild', '-us', '-uc', '-b'], cwd=pkg_path)

if os.path.exists(source_deb):
shutil.move(source_deb, dest_deb)
shutil.rmtree(temp_path)
sys.exit('Successful created package: {}'.format(dest_deb))
else:
sys.exit('ERROR: {} not created'.format(source_deb))
6 changes: 0 additions & 6 deletions changelog

This file was deleted.

5 changes: 5 additions & 0 deletions deb/CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{package} ({version}) {distribution}; urgency=medium

{changelog}

-- {name} <{email}> {datetime}
15 changes: 15 additions & 0 deletions deb/CONTROL
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Source: {package}
Priority: optional
Section: database
Maintainer: {name} <{email}>
Standards-Version: 3.9.6
Build-Depends: debhelper (>= 9),
dh-exec (>=0.3),
dh-autoreconf,
pkg-config
Homepage: {homepage}

Package: {package}
Depends: {depends}
Architecture: {architecture}
Description: {description}{long_description}
23 changes: 23 additions & 0 deletions deb/COPYRIGHT
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Name: {package}
Maintainer: {name} <{email}>
Source: https://github.com/transceptor-technology/{package}/
Files: *
Copyright: {year}, {company} <{company_email}>
License: MIT
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
15 changes: 15 additions & 0 deletions deb/MANPAGE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.\" Manpage for {package}.
.\" Contact {email} to correct errors or typos.
.TH man 8 "{curdate}" "1.0" "{package} man page"
.SH NAME
{package} \- {explain}
.SH SYNOPSIS
{package}
.SH DESCRIPTION
{description}.
.SH OPTIONS
See {package} --help for more information.
.SH BUGS
No known bugs.
.SH AUTHOR
{name} ({email})
2 changes: 2 additions & 0 deletions deb/OVERRIDES
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{package}: postinst-has-useless-call-to-ldconfig
{package}: postrm-has-useless-call-to-ldconfig
8 changes: 8 additions & 0 deletions deb/RULES
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# Note: before dh $0, there should be a TAB, no spaces.
%:
dh $@
18 changes: 13 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,23 @@ def __init__(self, version, dblist):

async def set_local_siridb_info(host, port):
global local_siridb_info
result = await async_server_info(host, port)
if result:
local_siridb_info = SiriDBInfo(*result)
try:
result = await async_server_info(host, port)
except Exception as e:
logging.error('Connection error: {}'.format(e))
sys.exit(1)
else:
if result:
local_siridb_info = SiriDBInfo(*result)


async def set_remote_siridb_info(host, port):
global remote_siridb_info
result = await async_server_info(host, port)
try:
result = await async_server_info(host, port)
except:
result = None

if result:
remote_siridb_info = SiriDBInfo(*result)

Expand Down Expand Up @@ -1089,7 +1098,6 @@ def parse_create_replica_or_pool(args):
# Read configuration
settings.config_file = args.config
settings.read_config()

asyncio.get_event_loop().run_until_complete(set_local_siridb_info(
settings.listen_client_address,
settings.listen_client_port))
Expand Down

0 comments on commit 3fa7739

Please sign in to comment.