Merge branch 'master' of git.jhink.org:jacob/nancy

This commit is contained in:
Jacob Hinkle 2022-09-28 12:20:14 -04:00
commit e4b380b2c1
4 changed files with 30 additions and 36 deletions

View File

@ -65,7 +65,7 @@ def print_diff(ABdiff: fs.FSDiff, indent=2, indent_level=0, use_color=True,
_print_row('NEW', d.B, l)
elif d.B is None:
_print_row('DEL', d.A, l)
else:
elif d.A.sha256 != d.B.sha256:
_print_row('MOD', d.B, l)

View File

@ -34,7 +34,7 @@ def record(message, store_path=None, show_diff=True, show_hashes=False, use_colo
if show_diff:
print_diff(fsdiff, show_hashes=show_hashes, use_color=use_color)
logger.info('Recording with message:', message)
logger.info('Recording with message: {}', message)
if skip_confirm or confirm("Record the values above into the database?"):
s.record(fsdiff, message=message)

View File

@ -262,7 +262,6 @@ class FSEntry:
"""Given id of an entry in filedir, recursively fill this object"""
if root_row is None:
assert root_id is not None
logger.debug('root_id({})={}', type(root_id), root_id)
cursor.execute(
'SELECT id, name, frozen FROM filedir WHERE id=?',
(root_id,),
@ -391,7 +390,7 @@ class FSDiff:
])
if B is None: # deleted entry
return cls(A, B, [
cls.compute(c, N) \
cls.compute(c, None) \
for c in sorted(A.children, key=lambda e: e.filename)
])

View File

@ -2,15 +2,12 @@
from loguru import logger
from . import db, environment, fs, machine
from . import db, environment, fs
import datetime
import importlib
import json
import os
from pathlib import Path
import sqlite3
from typing import Callable
class Program:
@ -33,17 +30,19 @@ class Program:
env = environment.Environment.find_or_insert(cur)
cur.execute('INSERT INTO program VALUES (?, ?, ?, ?, ?, ?, ?)', (
None, #id INTEGER PRIMARY KEY NOT NULL,
self.name, #name TEXT, -- name of the program, usually written lowercase by calling code e.g. cnn_crossval
None, # id INTEGER PRIMARY KEY NOT NULL,
self.name, # name TEXT,
# name of the program, usually written lowercase by calling
# code e.g. cnn_crossval
#-- we use POSIX timestamps for time recording.
#-- e.g. datetime.datetime.now().timestamp()
None, #start_time REAL,
None, #end_time REAL,
# -- we use POSIX timestamps for time recording.
# -- e.g. datetime.datetime.now().timestamp()
None, # start_time REAL,
None, # end_time REAL,
os.getpid(), #process_id INTEGER, -- host PID of python process on host OS
env.id, #environment INTEGER NOT NULL,
self.message, #message TEXT, -- user-defined message to help distinguish similar runs
os.getpid(), # process_id INTEGER, -- host PID of python process on host OS
env.id, # environment INTEGER NOT NULL,
self.message, # message TEXT, -- user-defined message to help distinguish similar runs
))
self.id = cur.lastrowid
@ -150,8 +149,11 @@ class Store:
"""Get the database id for the table entry in this store having name '.'"""
if cur is None:
cur = self.conn.cursor()
cur.execute('SELECT * FROM filedir')
allfiledir = cur.fetchall()
cur.execute('SELECT id FROM filedir WHERE store=1 AND parent is NULL')
return cur.fetchone()
root_id, = cur.fetchone()
return root_id
def path_to_fsentry(self, path):
"""Find a path in the filedir database and return it as an fsentry.
@ -185,18 +187,12 @@ class Store:
return fd_id
return fs.FSEntry.from_db_index(cur, root_id=fd_id)
def recorded_status(self, filepath):
recorded = self.path_to_fsentry(filepath)
def fs_entries(self, shallow=False):
"""Return recursive structure containing FSEntry objects from db"""
root_id = self.filedir_root_index()
logger.debug('root_id={}', root_id)
if root_id is None:
logger.trace("Empty root")
return fs.FSEntry.empty_root()
return None
else:
logger.trace("Non-empty root", root_id)
return fs.FSEntry.from_db_index(self.conn.cursor(), root_id=root_id)
def program(self, name, message=None):
@ -204,20 +200,14 @@ class Store:
def diff(self):
"""
Find changes to files and directories compared to their recorded versions
Find changes to files and dirs compared to their recorded versions
"""
logger.trace("DIFF")
# get info about files currently at the given locations
current = fs.FSEntry.from_path(self.path)
logger.debug("CURRENT: \n{}", str(current))
# then find a listing covering all the expected paths
#recorded = self.recorded_status(self.path)
recorded = self.fs_entries(shallow=True)
logger.debug("RECORDED: \n{}", str(recorded))
return fs.FSDiff.compute(recorded, current)
@ -236,6 +226,7 @@ class Store:
source_task,
)
)
return cur.lastrowid
def _record_new_file_recursive(self, ob, cur, parent_id, source_task):
# Find entries with this name and parent
@ -269,12 +260,16 @@ class Store:
def _record_recursive(self, diff, cur, parent_id=None, source_task=None):
"""Record this level of a diff."""
if diff.A is None:
self._record_new_file_recursive(diff.B, cur, parent_id, source_task=None)
self._record_new_file_recursive(diff.B, cur, parent_id,
source_task=source_task)
elif diff.B is None:
self._record_deleted_file_recursive(diff.B, cur, parent_id)
else:
# modified
pass
# possibly modified, record new version then recurse into children
self._record_new_file_recursive(diff.B, cur, parent_id,
source_task=source_task)
self._record_file_version(cur, diff.B, diff.A.id,
source_task=source_task)
# descend into children