def load(cls, campaign_dir):
        """
        Initialize from an existing database.

        It is assumed that the database json file has the same name as its
        containing folder.

        Args:
            campaign_dir (str): The path to the campaign directory.
        """

        # We only accept absolute paths
        if not Path(campaign_dir).is_absolute():
            raise ValueError("Path is not absolute")

        # Verify file exists
        if not Path(campaign_dir).exists():
            raise ValueError("Directory does not exist")

        # Extract filename from campaign dir
        filename = "%s.json" % os.path.split(campaign_dir)[1]
        filepath = os.path.join(campaign_dir, filename)

        try:
            # Read TinyDB instance from file
            tinydb = TinyDB(filepath)

            # Make sure the configuration is a valid dictionary
            assert set(
                tinydb.table('config').all()[0].keys()) == set(['script',
                                                                'params',
                                                                'commit'])
        except:
            # Remove the database instance created by tinydb
            os.remove(filepath)
            raise ValueError("Specified campaign directory seems corrupt")

        return cls(tinydb, campaign_dir)
def load ( cls , campaign_dir ) : if not Path ( campaign_dir ) . is_absolute ( ) : raise ValueError ( "Path is not absolute" ) if not Path ( campaign_dir ) . exists ( ) : raise ValueError ( "Directory does not exist" ) filename = "%s.json" % os . path . split ( campaign_dir ) [ 1 ] filepath = os . path . join ( campaign_dir , filename ) try : tinydb = TinyDB ( filepath ) assert set ( tinydb . table ( 'config' ) . all ( ) [ 0 ] . keys ( ) ) == set ( [ 'script' , 'params' , 'commit' ] ) except : os . remove ( filepath ) raise ValueError ( "Specified campaign directory seems corrupt" ) return cls ( tinydb , campaign_dir )
Initialize from an existing database.

        It is assumed that the database json file has the same name as its
        containing folder.

        Args:
            campaign_dir (str): The path to the campaign directory.