@@ -10,7 +10,7 @@ pub mod policy;
1010pub mod util;
1111pub mod transform;
1212
13- use crate :: config:: Config ;
13+ use crate :: config:: { Config , HowCreated } ;
1414use crate :: doctor:: { Doctor , DuplicateOntology , OntologyDeclaration } ;
1515use crate :: ontology:: { GraphIdentifier , Ontology , OntologyLocation } ;
1616use anyhow:: Result ;
@@ -63,6 +63,8 @@ pub struct EnvironmentStatus {
6363 last_updated : Option < DateTime < Utc > > ,
6464 // size of the oxigraph store, in bytes
6565 store_size : u64 ,
66+ // how this environment was last created
67+ how_created : HowCreated ,
6668}
6769
6870// impl Display pretty print for EnvironmentStatus
@@ -81,9 +83,11 @@ impl std::fmt::Display for EnvironmentStatus {
8183 write ! (
8284 f,
8385 "Environment Status\n \
86+ How Created: {}\n \
8487 Number of Ontologies: {}\n \
8588 Last Updated: {}\n \
8689 Store Size: {} bytes",
90+ self . how_created,
8791 self . num_ontologies,
8892 last_updated,
8993 pretty_bytes( self . store_size as f64 ) ,
@@ -99,6 +103,7 @@ pub struct OntoEnv {
99103 dependency_graph : DiGraph < GraphIdentifier , ( ) , petgraph:: Directed > ,
100104 #[ serde( skip) ]
101105 read_only : bool ,
106+ how_created : HowCreated ,
102107}
103108
104109// probably need some graph "identifier" that incorporates location and version..
@@ -111,27 +116,38 @@ impl OntoEnv {
111116 // is created
112117 let ontoenv_dir = config. root . join ( ".ontoenv" ) ;
113118 let config_path = ontoenv_dir. join ( "ontoenv.json" ) ;
119+ let mut how_created = HowCreated :: New ;
120+ info ! ( "Creating OntoEnv with config: {:?}" , config) ;
114121
115122 // test if the config in the ontoenv_dir is different from the current config.
116123 // If it is, replace the config with the current config and turn 'recreate' on
117- if ontoenv_dir. exists ( ) && config_path. exists ( ) {
118- println ! (
124+ if ontoenv_dir. exists ( ) && config_path. exists ( ) && !recreate {
125+ info ! (
119126 "OntoEnv directory exists: {:?}. Checking config" ,
120127 ontoenv_dir
121128 ) ;
129+ how_created = HowCreated :: SameConfig ;
122130 let file = std:: fs:: File :: open ( & config_path) ?;
123131 let reader = BufReader :: new ( file) ;
124- let env: OntoEnv = serde_json:: from_reader ( reader) ?;
132+ let mut env: OntoEnv = serde_json:: from_reader ( reader) ?;
125133 // print old and new config
126- println ! ( "Old config: {:?}" , env. config) ;
127- println ! ( "New config: {:?}" , config) ;
128134 if env. config != config {
129135 info ! ( "OntoEnv configuration has changed. Recreating environment." ) ;
130136 fs:: remove_dir_all ( & ontoenv_dir) ?;
131- return Self :: new ( config, true ) ;
137+ env = Self :: new ( config, true ) ?;
138+ env. how_created = HowCreated :: RecreatedDifferentConfig ;
139+ return Ok ( env) ;
132140 }
133141 }
134142
143+ if recreate {
144+ info ! ( "Recreating environment" ) ;
145+ if ontoenv_dir. exists ( ) {
146+ fs:: remove_dir_all ( & ontoenv_dir) ?;
147+ }
148+ how_created = HowCreated :: RecreatedFlag ;
149+ }
150+
135151 // if recreate is False, raise an error if the directory already exists
136152 //if ontoenv_dir.exists() && !recreate {
137153 // return Err(anyhow::anyhow!(
@@ -148,6 +164,7 @@ impl OntoEnv {
148164 ontologies : HashMap :: new ( ) ,
149165 dependency_graph : DiGraph :: new ( ) ,
150166 read_only : false ,
167+ how_created,
151168 } )
152169 }
153170
@@ -178,6 +195,10 @@ impl OntoEnv {
178195 Ok ( size)
179196 }
180197
198+ pub fn get_how_created ( & self ) -> HowCreated {
199+ self . how_created . clone ( )
200+ }
201+
181202 /// Calculates and returns the environment status
182203 pub fn status ( & self ) -> Result < EnvironmentStatus > {
183204 let store = self . store ( ) ?;
@@ -191,6 +212,7 @@ impl OntoEnv {
191212 num_ontologies,
192213 last_updated : Some ( last_updated) ,
193214 store_size : size,
215+ how_created : self . how_created . clone ( ) ,
194216 } )
195217 }
196218
0 commit comments