Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
313 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[report] | ||
show_missing = True | ||
skip_covered = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[flake8] | ||
exclude = bin,lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
language: python | ||
python: | ||
- "2.7" | ||
- "3.5" | ||
install: "pip install -r requirements.txt" | ||
script: | ||
- make test | ||
after_success: | ||
- coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
# polycul.es | ||
|
||
[![Build Status](https://travis-ci.org/makyo/polycul.es.svg?branch=master)](https://travis-ci.org/makyo/polycul.es) | ||
[![Coverage Status](https://coveralls.io/repos/github/makyo/polycul.es/badge.svg?branch=master)](https://coveralls.io/github/makyo/polycul.es?branch=master) | ||
|
||
Graphing polyamorous relationships with force directed layouts. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from six.moves import input | ||
import sys | ||
|
||
from model import Polycule | ||
import polycules | ||
|
||
|
||
db = polycules.connect_db() | ||
|
||
id = input('Enter the ID of the polycule to delete > ') | ||
polycule = Polycule.get(db, int(id), None, force=True) | ||
if polycule is None: | ||
print('\nNo polycule with that ID found.') | ||
db.close() | ||
sys.exit(1) | ||
|
||
if polycule.delete_pass is not None: | ||
confirm = input( | ||
'\nPolycule has a delete password, are you sure? [y/n] > ') | ||
if confirm[0].lower() != 'y': | ||
print('\nOkay, exiting without deleting.') | ||
db.close() | ||
sys.exit(1) | ||
|
||
confirm = input( | ||
'\nAre you sure you want to delete {}? [y/n] > '.format(id)) | ||
if confirm[0].lower() == 'y': | ||
print('\nDeleting {}...'.format(id)) | ||
polycule.delete(None, force=True) | ||
print('Polycule deleted.') | ||
db.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
drop table if exists polycules; | ||
create table polycules ( | ||
create table if not exists polycules ( | ||
id integer primary key autoincrement, | ||
graph text not null | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
alter table polycules | ||
add column view_pass char(60); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
alter table polycules | ||
add column delete_pass char(60); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import bcrypt | ||
|
||
|
||
class Polycule(object): | ||
def __init__(self, db=None, id=None, graph=None, view_pass=None, | ||
delete_pass=None): | ||
self._db = db | ||
self.id = id | ||
self.graph = graph | ||
self.view_pass = view_pass | ||
self.delete_pass = delete_pass | ||
|
||
@classmethod | ||
def get(cls, db, id, password, force=False): | ||
result = db.execute('select * from polycules where id = ?', [id]) | ||
graph = result.fetchone() | ||
if graph is None: | ||
return None | ||
polycule = Polycule( | ||
db=db, | ||
id=graph[0], | ||
graph=graph[1], | ||
view_pass=graph[2], | ||
delete_pass=graph[3]) | ||
if not force and ( | ||
polycule.view_pass is not None and | ||
not bcrypt.checkpw(password.encode('utf-8'), | ||
polycule.view_pass.encode('utf-8'))): | ||
raise Polycule.PermissionDenied | ||
return polycule | ||
|
||
@classmethod | ||
def create(cls, db, graph, raw_view_pass, raw_delete_pass): | ||
if raw_view_pass is not None: | ||
view_pass = bcrypt.hashpw( | ||
raw_view_pass.encode(), bcrypt.gensalt()).decode() | ||
else: | ||
view_pass = None | ||
if raw_delete_pass is not None: | ||
delete_pass = bcrypt.hashpw( | ||
raw_delete_pass.encode(), bcrypt.gensalt()).decode() | ||
else: | ||
delete_pass = None | ||
result = db.execute('select count(*) from polycules where graph = ?', | ||
[graph]) | ||
existing = result.fetchone()[0] | ||
if existing != 0: | ||
raise Polycule.IdenticalGraph | ||
cur = db.cursor() | ||
result = cur.execute('''insert into polycules | ||
(graph, view_pass, delete_pass) values (?, ?, ?)''', [ | ||
graph, | ||
view_pass, | ||
delete_pass, | ||
]) | ||
db.commit() | ||
return Polycule.get(db, result.lastrowid, None, force=True) | ||
|
||
def delete(self, password, force=False): | ||
if not force and not bcrypt.checkpw(password.encode('utf-8'), | ||
self.delete_pass.encode('utf-8')): | ||
raise Polycule.PermissionDenied | ||
cur = self._db.cursor() | ||
cur.execute('delete from polycules where id = ?', [self.id]) | ||
self._db.commit() | ||
|
||
class PermissionDenied(Exception): | ||
pass | ||
|
||
class IdenticalGraph(Exception): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,20 @@ | ||
bcrypt==3.1.1 | ||
cffi==1.9.1 | ||
configparser==3.5.0 | ||
coverage==4.0.3 | ||
enum34==1.1.6 | ||
flake8==3.2.1 | ||
Flask==0.10.1 | ||
itsdangerous==0.24 | ||
Jinja2==2.8 | ||
MarkupSafe==0.23 | ||
mccabe==0.5.2 | ||
nose==1.3.7 | ||
pycodestyle==2.2.0 | ||
pycparser==2.17 | ||
pyflakes==1.3.0 | ||
python-coveralls==2.9.0 | ||
PyYAML==3.12 | ||
requests==2.12.1 | ||
six==1.10.0 | ||
Werkzeug==0.11.4 | ||
wheel==0.24.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.