Skip to content

Commit

Permalink
Rev546, Sidebar drag fix, Fix rebuild on dbschema changes, Test Dbsch…
Browse files Browse the repository at this point in the history
…ema changes, Fix atomicWrite error when old file already exists
  • Loading branch information
shortcutme committed Nov 5, 2015
1 parent bd67d8f commit c2fc131
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 8 deletions.
2 changes: 2 additions & 0 deletions plugins/Sidebar/media/Scrollable.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ window.initScrollable = function () {
contentPosition = scrollContentWrapper.scrollTop;
scrollerBeingDragged = true;
window.addEventListener('mousemove', scrollBarScroll)
return false
}

function stopDrag(evt) {
Expand All @@ -42,6 +43,7 @@ window.initScrollable = function () {

function scrollBarScroll(evt) {
if (scrollerBeingDragged === true) {
evt.preventDefault();
var mouseDifferential = evt.pageY - normalizedPosition;
var scrollEquivalent = mouseDifferential * (scrollContentWrapper.scrollHeight / scrollContainer.offsetHeight);
scrollContentWrapper.scrollTop = contentPosition + scrollEquivalent;
Expand Down
2 changes: 1 addition & 1 deletion plugins/Sidebar/media/Scrollbable.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
-o-transition: top .08s;
transition: top .08s;
}
.content {
.scroller {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
Expand Down
4 changes: 2 additions & 2 deletions plugins/Sidebar/media/all.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
-o-transition: top .08s;
-webkit-transition: top .08s; -moz-transition: top .08s; -o-transition: top .08s; -ms-transition: top .08s; transition: top .08s ;
}
.content {
.scroller {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
Expand All @@ -58,7 +58,7 @@


.body-sidebar { background-color: #666 !important; }
#inner-iframe { -webkit-transition: 0.3s ease-in-out; -moz-transition: 0.3s ease-in-out; -o-transition: 0.3s ease-in-out; -ms-transition: 0.3s ease-in-out; transition: 0.3s ease-in-out ; transform-origin: left; backface-visibility: hidden; outline: 1px solid transparent }
#inner-iframe { -webkit-transition: 0.3s ease-in-out; -moz-transition: 0.3s ease-in-out; -o-transition: 0.3s ease-in-out; -ms-transition: 0.3s ease-in-out; transition: 0.3s ease-in-out ; transform-origin: left; -webkit-backface-visibility: hidden; -moz-backface-visibility: hidden; -o-backface-visibility: hidden; -ms-backface-visibility: hidden; backface-visibility: hidden ; outline: 1px solid transparent }
.body-sidebar iframe { -webkit-transform: rotateY(5deg); -moz-transform: rotateY(5deg); -o-transform: rotateY(5deg); -ms-transform: rotateY(5deg); transform: rotateY(5deg) ; opacity: 0.8; pointer-events: none } /* translateX(-200px) scale(0.95)*/

/* SIDEBAR */
Expand Down
3 changes: 2 additions & 1 deletion plugins/Sidebar/media/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ window.initScrollable = function () {
contentPosition = scrollContentWrapper.scrollTop;
scrollerBeingDragged = true;
window.addEventListener('mousemove', scrollBarScroll)
return false
}

function stopDrag(evt) {
Expand All @@ -104,6 +105,7 @@ window.initScrollable = function () {

function scrollBarScroll(evt) {
if (scrollerBeingDragged === true) {
evt.preventDefault();
var mouseDifferential = evt.pageY - normalizedPosition;
var scrollEquivalent = mouseDifferential * (scrollContentWrapper.scrollHeight / scrollContainer.offsetHeight);
scrollContentWrapper.scrollTop = contentPosition + scrollEquivalent;
Expand Down Expand Up @@ -536,7 +538,6 @@ window.initScrollable = function () {
}).call(this);



/* ---- plugins/Sidebar/media/morphdom.js ---- */


Expand Down
2 changes: 1 addition & 1 deletion src/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Config(object):

def __init__(self, argv):
self.version = "0.3.2"
self.rev = 542
self.rev = 546
self.argv = argv
self.action = None
self.createParser()
Expand Down
2 changes: 1 addition & 1 deletion src/Peer/Peer.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def request(self, cmd, params={}, stream_to=None):
self.onConnectionError()
return None # Connection failed

for retry in range(0, 3): # Retry 3 times
for retry in range(1, 4): # Retry 3 times
try:
res = self.connection.request(cmd, params, stream_to)
if not res:
Expand Down
6 changes: 4 additions & 2 deletions src/Site/SiteStorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def openDb(self, check=True):
if check and not self.db_checked:
changed_tables = self.db.checkTables()
if changed_tables:
self.rebuildDb(delete_db=False) # Todo only update the changed table datas
self.rebuildDb(delete_db=False) # TODO: only update the changed table datas

def closeDb(self):
if self.db:
Expand Down Expand Up @@ -176,7 +176,9 @@ def onUpdated(self, inner_path):
# Update Sql cache
if inner_path == "dbschema.json":
self.has_db = self.isFile("dbschema.json")
self.getDb().checkTables() # Check if any if table schema changed
# Reopen DB to check changes
self.closeDb()
self.openDb()
elif inner_path.endswith(".json") and self.has_db: # Load json file to db
self.log.debug("Loading json file to db: %s" % inner_path)
try:
Expand Down
15 changes: 15 additions & 0 deletions src/Test/TestDb.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ def testCheckTables(self):
assert "test_id" in cols
assert "title" in cols

# Add new table
assert "newtest" not in tables
db.schema["tables"]["newtest"] = {
"cols": [
["newtest_id", "INTEGER"],
["newtitle", "TEXT"],
],
"indexes": ["CREATE UNIQUE INDEX newtest_id ON newtest(newtest_id)"],
"schema_changed": 1426195822
}
db.checkTables()
tables = [row["name"] for row in db.execute("SELECT name FROM sqlite_master WHERE type='table'")]
assert "test" in tables
assert "newtest" in tables

db.close()

# Cleanup
Expand Down
3 changes: 3 additions & 0 deletions src/util/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
import struct
import re
import collections
import time


def atomicWrite(dest, content, mode="w"):
with open(dest + "-new", mode) as f:
f.write(content)
f.flush()
os.fsync(f.fileno())
if os.path.isfile(dest + "-old"): # Previous incomplete write
os.rename(dest + "-old", dest + "-old-%s" % time.time())
os.rename(dest, dest + "-old")
os.rename(dest + "-new", dest)
os.unlink(dest + "-old")
Expand Down

0 comments on commit c2fc131

Please sign in to comment.