Merge branch 'fix-bm-list'
This commit is contained in:
commit
38158e2edf
5 changed files with 73 additions and 53 deletions
|
@ -123,6 +123,7 @@ fn get_filtered_files_from_backend<'a>(module: &'a Module,
|
|||
env.bk.iter_files(module, &parser)
|
||||
.map(|files| {
|
||||
let f = files.filter(|file| {
|
||||
debug!("Backend returns file: {:?}", file);
|
||||
if tags.len() != 0 {
|
||||
debug!("Checking tags of: {:?}", file.id());
|
||||
get_tags_from_header(&file.header()).iter()
|
||||
|
@ -138,6 +139,7 @@ fn get_filtered_files_from_backend<'a>(module: &'a Module,
|
|||
}).collect::<Vec<File>>();
|
||||
f.into_iter()
|
||||
}).map_err(|e| {
|
||||
debug!("Error from Backend: {:?}", e);
|
||||
let mut merr = ModuleError::new("Could not filter files");
|
||||
merr.caused_by = Some(Box::new(e));
|
||||
merr
|
||||
|
|
|
@ -52,41 +52,26 @@ impl StorageBackend {
|
|||
})
|
||||
}
|
||||
|
||||
fn get_file_ids(&self, m: &Module) -> Option<Vec<FileID>> {
|
||||
let list = glob(&self.prefix_of_files_for_module(m)[..]);
|
||||
|
||||
if let Ok(globlist) = list {
|
||||
let mut v = vec![];
|
||||
for entry in globlist {
|
||||
if let Ok(path) = entry {
|
||||
debug!(" - File: {:?}", path);
|
||||
v.push(FileID::from(&path));
|
||||
} else {
|
||||
// Entry is not a path
|
||||
}
|
||||
}
|
||||
|
||||
Some(v)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn iter_ids(&self, m: &Module) -> Result<IntoIter<FileID>, StorageBackendError>
|
||||
{
|
||||
glob(&self.prefix_of_files_for_module(m)[..])
|
||||
let globstr = self.prefix_of_files_for_module(m) + "*.imag";
|
||||
debug!("Globstring = {}", globstr);
|
||||
glob(&globstr[..])
|
||||
.and_then(|globlist| {
|
||||
let v = globlist.filter_map(Result::ok)
|
||||
.map(|pbuf| FileID::from(&pbuf))
|
||||
.collect::<Vec<FileID>>()
|
||||
.into_iter();
|
||||
Ok(v)
|
||||
debug!("Iterating over globlist");
|
||||
Ok(globlist.filter_map(Result::ok)
|
||||
.map(|pbuf| FileID::from(&pbuf))
|
||||
.collect::<Vec<FileID>>()
|
||||
.into_iter())
|
||||
})
|
||||
.map_err(|e| {
|
||||
debug!("glob() returned error: {:?}", e);
|
||||
let serr = StorageBackendError::new(
|
||||
"iter_ids()",
|
||||
"Cannot iter on file ids",
|
||||
None);
|
||||
// Why the hack is Error not implemented for glob::PatternError
|
||||
// serr.caused_by = Some(Box::new(e));
|
||||
serr
|
||||
})
|
||||
}
|
||||
|
@ -97,15 +82,18 @@ impl StorageBackend {
|
|||
{
|
||||
self.iter_ids(m)
|
||||
.and_then(|ids| {
|
||||
debug!("Iterating ids and building files from them");
|
||||
debug!(" number of ids = {}", ids.len());
|
||||
Ok(ids.filter_map(|id| self.get_file_by_id(m, &id, p))
|
||||
.collect::<Vec<File>>()
|
||||
.into_iter())
|
||||
})
|
||||
.map_err(|e| {
|
||||
let serr = StorageBackendError::new(
|
||||
"iter_files()",
|
||||
"Cannot iter on files",
|
||||
None);
|
||||
debug!("StorageBackend::iter_ids() returned error = {:?}", e);
|
||||
let mut serr = StorageBackendError::new("iter_files()",
|
||||
"Cannot iter on files",
|
||||
None);
|
||||
serr.caused_by = Some(Box::new(e));
|
||||
serr
|
||||
})
|
||||
}
|
||||
|
@ -205,7 +193,7 @@ impl StorageBackend {
|
|||
if let Ok(mut fs) = FSFile::open(self.build_filepath_with_id(m, id.clone())) {
|
||||
let mut s = String::new();
|
||||
fs.read_to_string(&mut s);
|
||||
debug!("Success reading file with id '{}'", id);
|
||||
debug!("Success opening file with id '{}'", id);
|
||||
debug!("Parsing to internal structure now");
|
||||
p.read(s).and_then(|(h, d)| Ok(File::from_parser_result(m, id.clone(), h, d))).ok()
|
||||
} else {
|
||||
|
|
|
@ -179,8 +179,9 @@ impl From<PathBuf> for FileID {
|
|||
|
||||
impl<'a> From<&'a PathBuf> for FileID {
|
||||
|
||||
fn from(s: &'a PathBuf) -> FileID {
|
||||
unimplemented!()
|
||||
fn from(pb: &'a PathBuf) -> FileID {
|
||||
let s = pb.to_str().unwrap_or("");
|
||||
FileID::from(String::from(s))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ pub struct ParserError {
|
|||
parsertext: String,
|
||||
index: i32,
|
||||
explanation: Option<String>,
|
||||
caused_by: Option<Box<Error>>,
|
||||
}
|
||||
|
||||
impl ParserError {
|
||||
|
@ -19,6 +20,7 @@ impl ParserError {
|
|||
parsertext: text,
|
||||
index: idx,
|
||||
explanation: Some(String::from(expl)),
|
||||
caused_by: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,9 +29,16 @@ impl ParserError {
|
|||
summary: String::from(sum),
|
||||
parsertext: text,
|
||||
index: idx,
|
||||
explanation: None
|
||||
explanation: None,
|
||||
caused_by: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_cause(mut self, e: Box<Error>) -> ParserError {
|
||||
self.caused_by = Some(e);
|
||||
self
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Error for ParserError {
|
||||
|
@ -38,6 +47,10 @@ impl Error for ParserError {
|
|||
&self.summary[..]
|
||||
}
|
||||
|
||||
fn cause(&self) -> Option<&Error> {
|
||||
self.caused_by.as_ref().map(|e| &**e)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Debug for ParserError {
|
||||
|
@ -98,7 +111,10 @@ impl<HP> Parser<HP> where
|
|||
|
||||
if divided.is_err() {
|
||||
debug!("Error reading into internal datastructure");
|
||||
return Err(divided.err().unwrap());
|
||||
let mut p = ParserError::new("Dividing text failed",
|
||||
s, 0,
|
||||
"Dividing text with divide_text() failed");
|
||||
return Err(p.with_cause(Box::new(divided.err().unwrap())));
|
||||
}
|
||||
|
||||
let (header, data) = divided.ok().unwrap();
|
||||
|
@ -118,31 +134,38 @@ impl<HP> Parser<HP> where
|
|||
let h_text = try!(self.headerp.write(&header));
|
||||
debug!("Success translating header");
|
||||
|
||||
Ok(h_text + &data[..])
|
||||
let text = format!("---\n{}\n---\n{}", h_text, data);
|
||||
Ok(text)
|
||||
}
|
||||
|
||||
fn divide_text(&self, text: &String) -> Result<TextTpl, ParserError> {
|
||||
let re = Regex::new(r"(?sm)^---$(.*)^---$(.*)").unwrap();
|
||||
|
||||
debug!("Splitting: '{}'", text);
|
||||
let re = Regex::new(r"(?m)^\-\-\-$\n(.*)^\-\-\-$\n(.*)").unwrap();
|
||||
debug!(" regex = {:?}", re);
|
||||
|
||||
let captures = re.captures(&text[..]).unwrap_or(
|
||||
return Err(ParserError::new("Cannot run regex on text",
|
||||
text.clone(), 0,
|
||||
"Cannot run regex on text to divide it into header and content."))
|
||||
);
|
||||
re.captures(text).map(|captures| {
|
||||
|
||||
if captures.len() != 2 {
|
||||
return Err(ParserError::new("Unexpected Regex output",
|
||||
text.clone(), 0,
|
||||
"The regex to divide text into header and content had an unexpected output."))
|
||||
}
|
||||
if captures.len() != 3 {
|
||||
debug!("Unexpected amount of captures");
|
||||
return Err(ParserError::new("Unexpected Regex output",
|
||||
text.clone(), 0,
|
||||
"The regex to divide text into header and content had an unexpected output."))
|
||||
}
|
||||
|
||||
let header = captures.at(0).map(|s| String::from(s));
|
||||
let content = captures.at(1).map(|s| String::from(s));
|
||||
let header = captures.at(1).map(|s| String::from(s));
|
||||
let content = captures.at(2).map(|s| String::from(s));
|
||||
|
||||
debug!("Splitted, Header = '{:?}'", header);
|
||||
debug!("Splitted, Data = '{:?}'", content);
|
||||
Ok((header, content))
|
||||
debug!("Splitted, Header = '{:?}'", header.clone().unwrap_or("NONE".into()));
|
||||
debug!("Splitted, Data = '{:?}'", content.clone().unwrap_or("NONE".into()));
|
||||
Ok((header, content))
|
||||
}).or_else(|| {
|
||||
debug!("Cannot capture from text");
|
||||
let e = ParserError::new("Cannot run regex on text",
|
||||
text.clone(), 0,
|
||||
"Cannot run regex on text to divide it into header and content.");
|
||||
Some(Err(e))
|
||||
}).unwrap()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -101,6 +101,7 @@ impl FilePrinter for TablePrinter {
|
|||
|
||||
let mut i = 0;
|
||||
for file in files {
|
||||
debug!("Printing file: {:?}", file);
|
||||
i += 1;
|
||||
let cell_i = Cell::new(&format!("{}", i)[..]);
|
||||
let cell_o = Cell::new(&format!("{}", file.owner().name())[..]);
|
||||
|
@ -111,7 +112,12 @@ impl FilePrinter for TablePrinter {
|
|||
tab.add_row(row);
|
||||
}
|
||||
|
||||
tab.printstd();
|
||||
if i != 0 {
|
||||
debug!("Printing {} table entries", i);
|
||||
tab.printstd();
|
||||
} else {
|
||||
debug!("Not printing table because there are zero entries");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue