def _remove(path): try: remove(path) except: err('failed attempting to remove %s\n' % _nice(path)) raise return True
def notify(checkfornew, time_del): result = os.popen( """osascript -e 'display dialog "Do you want what you just downloaded to be a single-use file?" buttons {"Yes","No & Move","No"} default button "No" with title "Single-Use File? " with icon Caution '""").readlines() if result == ['button returned:Yes\n']: remove(checkfornew, time_del) if result == ['button returned:No & Move\n']: move(checkfornew)
def _remove(path): if os.path.isdir(path) and len(os.listdir(path)) > 0: warn('directory %s is nonempty; not redoing\n' % _nice(path)) return False else: try: remove(path) except: err('failed attempting to remove %s\n' % _nice(path)) raise return True
def train(self, lr=1e-2, epochs=1): remove(self.log_path) model = self.build_model(lr) model.summary() X_train, X_test, y_train, y_test = self.get_data() model.fit(x=X_train, y=y_train, batch_size=self.batch_size, epochs=epochs, verbose=1, callbacks=self.get_callbacks(), validation_data=(X_test, y_test), shuffle=True, initial_epoch=0, steps_per_epoch=None, validation_steps=None) save_model(model, self.last_model_path)
must_create = not os.path.exists(dbfile) if not must_create: _db = _connect(dbfile) try: row = _db.cursor().execute("select version from Schema").fetchone() except sqlite3.OperationalError: row = None ver = row and row[0] or None if ver != SCHEMA_VER: err("state database: discarding v%s (wanted v%s)\n" % (ver, SCHEMA_VER)) must_create = True _db = None if must_create: remove(dbfile) _db = _connect(dbfile) _db.execute("create table Schema " " (version int)") _db.execute("create table Runid " " (id integer primary key autoincrement)") _db.execute("create table Files " " (name not null primary key, " " is_generated int, " " is_override int, " " checked_runid int, " " changed_runid int, " " failed_runid int, " " stamp, " " csum)") _db.execute("create table Deps " " (target int, "
def db(): global _db if _db: return _db dbdir = '%s/.redo' % vars.BASE dbfile = '%s/db.sqlite3' % dbdir try: os.mkdir(dbdir) except OSError as e: if e.errno == errno.EEXIST: pass # if it exists, that's okay else: raise must_create = not os.path.exists(dbfile) if not must_create: _db = _connect(dbfile) try: row = _db.cursor().execute("select version from Schema").fetchone() except sqlite3.OperationalError: row = None ver = row and row[0] or None if ver != SCHEMA_VER: err("state database: discarding v%s (wanted v%s)\n" % (ver, SCHEMA_VER)) must_create = True _db = None if must_create: remove(dbfile) _db = _connect(dbfile) _db.execute("create table Schema " " (version int)") _db.execute("create table Runid " " (id integer primary key autoincrement)") _db.execute("create table Files " " (name not null primary key, " " is_generated int, " " is_override int, " " checked_runid int, " " changed_runid int, " " failed_runid int, " " stamp, " " csum)") _db.execute("create table Deps " " (target int, " " source int, " " mode not null, " " delete_me int, " " primary key (target,source))") _db.execute("insert into Schema (version) values (?)", [SCHEMA_VER]) # eat the '0' runid and File id _db.execute("insert into Runid values " " ((select max(id)+1 from Runid))") _db.execute("insert into Files (name) values (?)", [ALWAYS]) if not vars.RUNID: _db.execute("insert into Runid values " " ((select max(id)+1 from Runid))") vars.RUNID = _db.execute("select last_insert_rowid()").fetchone()[0] os.environ['REDO_RUNID'] = str(vars.RUNID) _db.commit() return _db