Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 89 additions & 14 deletions dvc/dagascii.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,88 @@
import math

from asciicanvas.asciicanvas import AsciiCanvas
from asciicanvas.style import Style

from grandalf.graphs import Vertex, Edge, Graph
from grandalf.layouts import SugiyamaLayout
from grandalf.routing import route_with_lines, EdgeViewer


class AsciiCanvas(object):
def __init__(self, cols, lines):
assert cols > 1
assert lines > 1

self.cols = cols
self.lines = lines
self.canvas = [[' '] * cols for l in range(lines)]

def draw(self):
for line in self.canvas:
print(''.join(line))

def point(self, x, y, char):
assert x >= 0
assert x < self.cols
assert y >= 0
assert y < self.lines

self.canvas[y][x] = char

def line(self, x0, y0, x1, y1, char):
if x0 > x1:
x1, x0 = x0, x1
y1, y0 = y0, y1

dx = x1 - x0
dy = y1 - y0

if dx == 0 and dy == 0:
self.point(x0, y0, char)
elif abs(dx) >= abs(dy):
for x in range(x0, x1 + 1):
if dx == 0:
y = y0
else:
y = y0 + int(round((x - x0) * dy / float((dx))))
self.point(x, y, char)
elif y0 < y1:
for y in range(y0, y1 + 1):
if dy == 0:
x = x0
else:
x = x0 + int(round((y - y0) * dx / float((dy))))
self.point(x, y, char)
else:
for y in range(y1, y0 + 1):
if dy == 0:
x = x0
else:
x = x1 + int(round((y - y1) * dx / float((dy))))
self.point(x, y, char)

def text(self, x, y, text):
for i, c in enumerate(text):
self.point(x + i, y, c)

def box(self, x0, y0, w, h):
assert w > 1
assert h > 1

w -= 1
h -= 1

for x in range(x0, x0 + w):
self.point(x, y0, '-')
self.point(x, y0 + h, '-')

for y in range(y0, y0 + h):
self.point(x0, y, '|')
self.point(x0 + w, y, '|')

self.point(x0, y0, '+')
self.point(x0 + w, y0, '+')
self.point(x0, y0 + h, '+')
self.point(x0 + w, y0 + h, '+')


class Dagascii(object):
def __init__(self, vertexes, edges):
#
Expand Down Expand Up @@ -100,22 +175,22 @@ def draw(self):
assert end_x >= 0
assert end_y >= 0

canvas.add_line(start_x, start_y,
end_x, end_y,
style=Style('*'))
canvas.line(start_x, start_y,
end_x, end_y,
'*')

for v in self.sug.g.sV:
# NOTE: moving boxes w/2 to the left
x = v.view.xy[0] - v.view.w/2.0
y = v.view.xy[1]

canvas.add_nine_patch_rect(int(round(x - minx)),
int(round(y - miny)),
v.view.w,
v.view.h)
canvas.box(int(round(x - minx)),
int(round(y - miny)),
v.view.w,
v.view.h)

canvas.add_text(int(round(x - minx)) + 1,
int(round(y - miny)) + 1,
v.data)
canvas.text(int(round(x - minx)) + 1,
int(round(y - miny)) + 1,
v.data)

canvas.print_out()
canvas.draw()
4 changes: 2 additions & 2 deletions dvc/output/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def save(self):
super(OutputLOCAL, self).save()
self._verify_metric()
msg = 'Output \'{}\' doesn\'t use cache. Skipping saving.'
self.project.logger.debug(msg.format(self.rel_path))
self.project.logger.info(msg.format(self.rel_path))
return

if not os.path.exists(self.path):
Expand All @@ -99,7 +99,7 @@ def save(self):

if not self.changed():
msg = 'Output \'{}\' didn\'t change. Skipping saving.'
self.project.logger.debug(msg.format(self.rel_path))
self.project.logger.info(msg.format(self.rel_path))
return

if self.is_local:
Expand Down
61 changes: 47 additions & 14 deletions dvc/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class StateDuplicateError(DvcException):


class State(object):
VERSION = 0
STATE_FILE = 'state'
STATE_TABLE = 'state'
STATE_TABLE_LAYOUT = "inode INTEGER PRIMARY KEY, " \
Expand Down Expand Up @@ -81,6 +82,51 @@ def changed(self, path, md5):

return actual.split('.')[0] != md5.split('.')[0]

def _load(self):
from dvc import VERSION

cmd = "PRAGMA user_version;"
self.c.execute(cmd)
ret = self.c.fetchall()
assert len(ret) == 1
assert len(ret[0]) == 1
assert isinstance(ret[0][0], int)
self.version = ret[0][0]

if self.version > self.VERSION:
msg = "You are using an old version '{}' of dvc that is using " \
"state file version '{}' which is not compatible with the " \
"state file version '{}' that is used in this projet. " \
"Please upgrade right now!"
raise DvcException(msg.format(VERSION,
self.VERSION,
self.version))
elif self.version < self.VERSION:
msg = "State file version '{}' is too old. " \
"Reformatting to the current version '{}'."
self.project.logger.warn(msg.format(self.version, self.VERSION))
cmd = "DROP TABLE IF EXISTS {};"
self.c.execute(cmd.format(self.STATE_TABLE))
self.c.execute(cmd.format(self.STATE_INFO_TABLE))
self.c.execute(cmd.format(self.LINK_STATE_TABLE))

# Check that the state file is indeed a database
cmd = "CREATE TABLE IF NOT EXISTS {} ({})"
self.c.execute(cmd.format(self.STATE_TABLE,
self.STATE_TABLE_LAYOUT))
self.c.execute(cmd.format(self.STATE_INFO_TABLE,
self.STATE_INFO_TABLE_LAYOUT))
self.c.execute(cmd.format(self.LINK_STATE_TABLE,
self.LINK_STATE_TABLE_LAYOUT))

cmd = "INSERT OR IGNORE INTO {} (count) SELECT 0 " \
"WHERE NOT EXISTS (SELECT * FROM {})"
self.c.execute(cmd.format(self.STATE_INFO_TABLE,
self.STATE_INFO_TABLE))

cmd = "PRAGMA user_version = {};"
self.c.execute(cmd.format(self.VERSION))

def load(self):
retries = 1
while True:
Expand All @@ -93,20 +139,7 @@ def load(self):
# Try loading once to check that the file is indeed a database
# and reformat it if it is not.
try:
# Check that the state file is indeed a database
cmd = "CREATE TABLE IF NOT EXISTS {} ({})"
self.c.execute(cmd.format(self.STATE_TABLE,
self.STATE_TABLE_LAYOUT))
self.c.execute(cmd.format(self.STATE_INFO_TABLE,
self.STATE_INFO_TABLE_LAYOUT))
self.c.execute(cmd.format(self.LINK_STATE_TABLE,
self.LINK_STATE_TABLE_LAYOUT))

cmd = "INSERT OR IGNORE INTO {} (count) SELECT 0 " \
"WHERE NOT EXISTS (SELECT * FROM {})"
self.c.execute(cmd.format(self.STATE_INFO_TABLE,
self.STATE_INFO_TABLE))

self._load()
return
except sqlite3.DatabaseError:
self.c.close()
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ requests>=2.18.4
wheel>=0.31.1
futures>=3.2.0; python_version == "2.7"
grandalf==0.6
asciicanvas==0.0.3
pydot>=1.2.4
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"jsonpath-rw==1.4.0",
"requests>=2.18.4",
"grandalf==0.6",
"asciicanvas==0.0.3",
]

# Extra dependencies for remote integrations
Expand Down