Browse Source

Update

master
Adrian Heine 6 years ago
parent
commit
34f8dbffab
  1. 12
      src/symbols/dir.rs
  2. 28
      src/symbols/factory.rs
  3. 10
      src/symbols/file.rs
  4. 28
      src/symbols/git/checkout.rs
  5. 4
      src/symbols/nginx/server.rs
  6. 10
      src/symbols/owner.rs
  7. 16
      src/symbols/wordpress/plugin.rs
  8. 20
      src/symbols/wordpress/translation.rs

12
src/symbols/dir.rs

@ -7,17 +7,17 @@ use std::path::Path;
use resources::Resource; use resources::Resource;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner}; use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
pub struct Dir<D> where D: AsRef<str> + fmt::Display {
pub struct Dir<D> where D: AsRef<str> {
path: D path: D
} }
impl<D> Dir<D> where D: AsRef<str> + fmt::Display {
impl<D> Dir<D> where D: AsRef<str> {
pub fn new(path: D) -> Self { pub fn new(path: D) -> Self {
Dir { path: path } Dir { path: path }
} }
} }
impl<D> Symbol for Dir<D> where D: AsRef<str> + fmt::Display {
impl<D> Symbol for Dir<D> where D: AsRef<str> {
fn target_reached(&self) -> Result<bool, Box<Error>> { fn target_reached(&self) -> Result<bool, Box<Error>> {
let metadata = fs::metadata(self.path.as_ref()); let metadata = fs::metadata(self.path.as_ref());
// Check if dir exists // Check if dir exists
@ -48,7 +48,7 @@ impl<D> Symbol for Dir<D> where D: AsRef<str> + fmt::Display {
} }
fn provides(&self) -> Option<Vec<Resource>> { fn provides(&self) -> Option<Vec<Resource>> {
Some(vec![ Resource::new("dir", self.path.to_string()) ])
Some(vec![ Resource::new("dir", self.path.as_ref()) ])
} }
fn as_action<'a>(&'a self, runner: &'a SymbolRunner) -> Box<Action + 'a> { fn as_action<'a>(&'a self, runner: &'a SymbolRunner) -> Box<Action + 'a> {
@ -60,8 +60,8 @@ impl<D> Symbol for Dir<D> where D: AsRef<str> + fmt::Display {
} }
} }
impl<D> fmt::Display for Dir<D> where D: AsRef<str> + fmt::Display {
impl<D> fmt::Display for Dir<D> where D: AsRef<str> {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error>{ fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error>{
write!(f, "Dir {}", self.path)
write!(f, "Dir {}", self.path.as_ref())
} }
} }

28
src/symbols/factory.rs

@ -1,10 +1,17 @@
use std::ops::Deref;
use std::path::Path;
use command_runner::{CommandRunner, SetuidCommandRunner}; use command_runner::{CommandRunner, SetuidCommandRunner};
use storage::SimpleStorage;
use symbols::{Action, Symbol, SymbolRunner}; use symbols::{Action, Symbol, SymbolRunner};
use symbols::acme::{AcmeCert, AcmeCertChain}; use symbols::acme::{AcmeCert, AcmeCertChain};
use symbols::file::File; use symbols::file::File;
use symbols::git::checkout::GitCheckout;
use symbols::hook::Hook; use symbols::hook::Hook;
use symbols::list::ListAction; use symbols::list::ListAction;
use symbols::nginx::server::NginxServer; use symbols::nginx::server::NginxServer;
use symbols::owner::Owner;
use symbols::stored_directory::{StoredDirectory, StorageDirection};
use symbols::systemd::reload::ReloadService; use symbols::systemd::reload::ReloadService;
use symbols::tls::SelfSignedTlsCert; use symbols::tls::SelfSignedTlsCert;
@ -86,4 +93,25 @@ pm.max_children = 10"
self.command_runner self.command_runner
) )
} }
pub fn get_stored_directory<'a, T: Into<String>>(&'a self, storage_name: &'static str, target: T) -> (Box<Action + 'a>, Box<Action + 'a>) {
let data = SimpleStorage::new("/root/data".to_string(), storage_name.to_string());
let string_target = target.into();
(
Box::new(StoredDirectory::new(string_target.clone().into(), data.clone(), StorageDirection::Save, self.command_runner)).into_action(self.symbol_runner),
Box::new(StoredDirectory::new(string_target.into(), data.clone(), StorageDirection::Load, self.command_runner)).into_action(self.symbol_runner)
)
}
pub fn get_git_checkout<'a, T: 'a + AsRef<str>>(&'a self, target: T, source: &'a str, branch: &'a str) -> Box<Action + 'a> {
Box::new(GitCheckout::new(target, source, branch, self.command_runner)).into_action(self.symbol_runner)
}
pub fn get_owner<'a, F: 'a + AsRef<str>>(&'a self, file: F, user: &'a str) -> Box<Action + 'a> {
Box::new(Owner::new(file, user.into(), self.command_runner)).into_action(self.symbol_runner)
}
pub fn get_file<'a, F: 'a + Deref<Target=str>, P: 'a + AsRef<Path>>(&'a self, path: P, content: F) -> Box<Action + 'a> {
Box::new(File::new(path, content)).into_action(self.symbol_runner)
}
} }

10
src/symbols/file.rs

@ -9,12 +9,12 @@ use std::path::Path;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner}; use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
use resources::Resource; use resources::Resource;
pub struct File<C, D> where C: Deref<Target=str>, D: AsRef<str> + fmt::Display {
pub struct File<C, D> where C: Deref<Target=str>, D: AsRef<Path> {
path: D, path: D,
content: C content: C
} }
impl<C, D> File<C, D> where C: Deref<Target=str>, D: AsRef<str> + fmt::Display {
impl<C, D> File<C, D> where C: Deref<Target=str>, D: AsRef<Path> {
pub fn new(path: D, content: C) -> Self { pub fn new(path: D, content: C) -> Self {
File { File {
path: path, path: path,
@ -23,7 +23,7 @@ impl<C, D> File<C, D> where C: Deref<Target=str>, D: AsRef<str> + fmt::Display {
} }
} }
impl<C, D> Symbol for File<C, D> where C: Deref<Target=str>, D: AsRef<str> + fmt::Display {
impl<C, D> Symbol for File<C, D> where C: Deref<Target=str>, D: AsRef<Path> {
fn target_reached(&self) -> Result<bool, Box<Error>> { fn target_reached(&self) -> Result<bool, Box<Error>> {
let file = FsFile::open(self.path.as_ref()); let file = FsFile::open(self.path.as_ref());
// Check if file exists // Check if file exists
@ -66,8 +66,8 @@ impl<C, D> Symbol for File<C, D> where C: Deref<Target=str>, D: AsRef<str> + fmt
} }
} }
impl<C, D> fmt::Display for File<C, D> where C: Deref<Target=str>, D: AsRef<str> + fmt::Display {
impl<C, D> fmt::Display for File<C, D> where C: Deref<Target=str>, D: AsRef<Path> {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error>{ fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error>{
write!(f, "File {}", self.path)
write!(f, "File {}", self.path.as_ref().display())
} }
} }

28
src/symbols/git/checkout.rs

@ -7,15 +7,15 @@ use command_runner::CommandRunner;
use resources::Resource; use resources::Resource;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner}; use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
pub struct GitCheckout<'a, C: 'a + CommandRunner> {
target: &'a str,
pub struct GitCheckout<'a, C: 'a + CommandRunner, T: AsRef<str>> {
target: T,
source: &'a str, source: &'a str,
branch: &'a str, branch: &'a str,
command_runner: &'a C command_runner: &'a C
} }
impl<'a, C: CommandRunner> GitCheckout<'a, C> {
pub fn new(target: &'a str, source: &'a str, branch: &'a str, command_runner: &'a C) -> Self {
impl<'a, C: CommandRunner, T: AsRef<str>> GitCheckout<'a, C, T> {
pub fn new(target: T, source: &'a str, branch: &'a str, command_runner: &'a C) -> Self {
GitCheckout { GitCheckout {
target: target, target: target,
source: source, source: source,
@ -25,25 +25,25 @@ impl<'a, C: CommandRunner> GitCheckout<'a, C> {
} }
} }
impl<'a, C: CommandRunner> fmt::Display for GitCheckout<'a, C> {
impl<'a, C: CommandRunner, T: AsRef<str>> fmt::Display for GitCheckout<'a, C, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Checkout {} (branch {}) into {}", self.source, self.branch, self.target)
write!(f, "Checkout {} (branch {}) into {}", self.source, self.branch, self.target.as_ref())
} }
} }
use std::fs::metadata; use std::fs::metadata;
impl<'a, C: CommandRunner> GitCheckout<'a, C> {
impl<'a, C: CommandRunner, T: AsRef<str>> GitCheckout<'a, C, T> {
fn _run_in_target_repo(&self, args: &[&str]) -> Result<Vec<u8>, Box<Error>> { fn _run_in_target_repo(&self, args: &[&str]) -> Result<Vec<u8>, Box<Error>> {
let mut new_args = vec!["-C", self.target];
let mut new_args = vec!["-C", self.target.as_ref()];
new_args.extend_from_slice(args); new_args.extend_from_slice(args);
self.command_runner.get_output("git", &new_args) self.command_runner.get_output("git", &new_args)
} }
} }
impl<'a, C: CommandRunner> Symbol for GitCheckout<'a, C> {
impl<'a, C: CommandRunner, T: AsRef<str>> Symbol for GitCheckout<'a, C, T> {
fn target_reached(&self) -> Result<bool, Box<Error>> { fn target_reached(&self) -> Result<bool, Box<Error>> {
if let Err(e) = metadata(self.target) {
if let Err(e) = metadata(self.target.as_ref()) {
return if e.kind() == io::ErrorKind::NotFound { return if e.kind() == io::ErrorKind::NotFound {
Ok(false) Ok(false)
} else { } else {
@ -58,8 +58,8 @@ impl<'a, C: CommandRunner> Symbol for GitCheckout<'a, C> {
} }
fn execute(&self) -> Result<(), Box<Error>> { fn execute(&self) -> Result<(), Box<Error>> {
if !Path::new(self.target).exists() {
return self.command_runner.run_successfully("git", &["clone", "--depth", "1", "-b", self.branch, self.source, self.target]);
if !Path::new(self.target.as_ref()).exists() {
return self.command_runner.run_successfully("git", &["clone", "--depth", "1", "-b", self.branch, self.source, self.target.as_ref()]);
} }
try!(self._run_in_target_repo(&["fetch", self.source, self.branch])); try!(self._run_in_target_repo(&["fetch", self.source, self.branch]));
try!(self._run_in_target_repo(&["merge", "FETCH_HEAD"])); try!(self._run_in_target_repo(&["merge", "FETCH_HEAD"]));
@ -67,11 +67,11 @@ impl<'a, C: CommandRunner> Symbol for GitCheckout<'a, C> {
} }
fn get_prerequisites(&self) -> Vec<Resource> { fn get_prerequisites(&self) -> Vec<Resource> {
vec![ Resource::new("dir", Path::new(self.target).parent().unwrap().to_string_lossy()) ]
vec![ Resource::new("dir", Path::new(self.target.as_ref()).parent().unwrap().to_string_lossy()) ]
} }
fn provides(&self) -> Option<Vec<Resource>> { fn provides(&self) -> Option<Vec<Resource>> {
Some(vec![ Resource::new("dir", self.target.to_string()) ])
Some(vec![ Resource::new("dir", self.target.as_ref().to_string()) ])
} }
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> { fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {

4
src/symbols/nginx/server.rs

@ -43,7 +43,7 @@ impl<E: Error> fmt::Display for NginxServerError<E> {
pub struct NginxServer<'a, C: 'a + CommandRunner, T> where T: Deref<Target=str> { pub struct NginxServer<'a, C: 'a + CommandRunner, T> where T: Deref<Target=str> {
command_runner: &'a C, command_runner: &'a C,
file: FileSymbol<T, Cow<'a, str>>,
file: FileSymbol<T, String>,
} }
use std::borrow::Cow; use std::borrow::Cow;
@ -121,7 +121,7 @@ location @proxy {{
} }
pub fn new(domain: &'a str, content: String, command_runner: &'a C) -> Self { pub fn new(domain: &'a str, content: String, command_runner: &'a C) -> Self {
let file_path: Cow<str> = Cow::from(String::from("/etc/nginx/sites-enabled/") + domain);
let file_path = String::from("/etc/nginx/sites-enabled/") + domain;
NginxServer { NginxServer {
command_runner: command_runner, command_runner: command_runner,
file: FileSymbol::new(file_path, content) file: FileSymbol::new(file_path, content)

10
src/symbols/owner.rs

@ -11,19 +11,19 @@ use command_runner::CommandRunner;
use resources::Resource; use resources::Resource;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner}; use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
pub struct Owner<'a, C: 'a + CommandRunner, D> where D: AsRef<str> + fmt::Display {
pub struct Owner<'a, C: 'a + CommandRunner, D> where D: AsRef<str> {
path: D, path: D,
user_name: Cow<'a, str>, user_name: Cow<'a, str>,
command_runner: &'a C command_runner: &'a C
} }
impl<'a, C: CommandRunner, D> Owner<'a, C, D> where D: AsRef<str> + fmt::Display {
impl<'a, C: CommandRunner, D> Owner<'a, C, D> where D: AsRef<str> {
pub fn new(path: D, user_name: Cow<'a, str>, command_runner: &'a C) -> Self { pub fn new(path: D, user_name: Cow<'a, str>, command_runner: &'a C) -> Self {
Owner { path: path, user_name: user_name, command_runner: command_runner } Owner { path: path, user_name: user_name, command_runner: command_runner }
} }
} }
impl<'a, C: CommandRunner, D> Symbol for Owner<'a, C, D> where D: AsRef<str> + fmt::Display {
impl<'a, C: CommandRunner, D> Symbol for Owner<'a, C, D> where D: AsRef<str> {
fn target_reached(&self) -> Result<bool, Box<Error>> { fn target_reached(&self) -> Result<bool, Box<Error>> {
if !Path::new(self.path.as_ref()).exists() { if !Path::new(self.path.as_ref()).exists() {
return Ok(false); return Ok(false);
@ -50,8 +50,8 @@ impl<'a, C: CommandRunner, D> Symbol for Owner<'a, C, D> where D: AsRef<str> + f
} }
} }
impl<'a, C: CommandRunner, D> fmt::Display for Owner<'a, C, D> where D: AsRef<str> + fmt::Display {
impl<'a, C: CommandRunner, D> fmt::Display for Owner<'a, C, D> where D: AsRef<str> {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error>{ fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error>{
write!(f, "Owner {} for {}", self.user_name, self.path)
write!(f, "Owner {} for {}", self.user_name, self.path.as_ref())
} }
} }

16
src/symbols/wordpress/plugin.rs

@ -11,13 +11,13 @@ use command_runner::CommandRunner;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner}; use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
use resources::Resource; use resources::Resource;
pub struct WordpressPlugin<'a, C, R> where C: Deref<Target=str> + fmt::Display, R: 'a + CommandRunner {
pub struct WordpressPlugin<'a, C, R> where C: Deref<Target=str>, R: 'a + CommandRunner {
base: C, base: C,
name: C, name: C,
command_runner: &'a R command_runner: &'a R
} }
impl<'a, C, R> WordpressPlugin<'a, C, R> where C: Deref<Target=str> + fmt::Display, R: CommandRunner {
impl<'a, C, R> WordpressPlugin<'a, C, R> where C: Deref<Target=str>, R: CommandRunner {
pub fn new(base: C, name: C, command_runner: &'a R) -> Self { pub fn new(base: C, name: C, command_runner: &'a R) -> Self {
WordpressPlugin { WordpressPlugin {
base: base, base: base,
@ -31,7 +31,7 @@ impl<'a, C, R> WordpressPlugin<'a, C, R> where C: Deref<Target=str> + fmt::Displ
} }
} }
impl<'a, C, R> Symbol for WordpressPlugin<'a, C, R> where C: Deref<Target=str> + fmt::Display, R: CommandRunner {
impl<'a, C, R> Symbol for WordpressPlugin<'a, C, R> where C: Deref<Target=str>, R: CommandRunner {
fn target_reached(&self) -> Result<bool, Box<Error>> { fn target_reached(&self) -> Result<bool, Box<Error>> {
if !self.get_path().exists() { if !self.get_path().exists() {
return Ok(false); return Ok(false);
@ -62,13 +62,13 @@ impl<'a, C, R> Symbol for WordpressPlugin<'a, C, R> where C: Deref<Target=str> +
} }
} }
} }
let upstream = try!(self.command_runner.get_output("curl", &["--form", &format!(r###"plugins={{"plugins":{{"{0}/{0}.php":{{"Version":"{1}", "PluginURI":"{2}"}}}}}}"###, self.name, version, plugin_uri), "https://api.wordpress.org/plugins/update-check/1.1/"]));
let upstream = try!(self.command_runner.get_output("curl", &["--form", &format!(r###"plugins={{"plugins":{{"{0}/{0}.php":{{"Version":"{1}", "PluginURI":"{2}"}}}}}}"###, &*self.name, version, plugin_uri), "https://api.wordpress.org/plugins/update-check/1.1/"]));
Ok(try!(String::from_utf8(upstream)).contains(r###""plugins":[]"###)) Ok(try!(String::from_utf8(upstream)).contains(r###""plugins":[]"###))
} }
fn execute(&self) -> Result<(), Box<Error>> { fn execute(&self) -> Result<(), Box<Error>> {
let source = format!("https://downloads.wordpress.org/plugin/{}.zip", self.name);
let zip = format!("/tmp/{}.zip", self.name);
let source = format!("https://downloads.wordpress.org/plugin/{}.zip", &*self.name);
let zip = format!("/tmp/{}.zip", &*self.name);
try!(self.command_runner.run_successfully("curl", &[source.as_ref() as &str, "-o", zip.as_ref()])); try!(self.command_runner.run_successfully("curl", &[source.as_ref() as &str, "-o", zip.as_ref()]));
try!(self.command_runner.run_successfully("rm", &["-rf", &self.get_path().to_string_lossy()])); try!(self.command_runner.run_successfully("rm", &["-rf", &self.get_path().to_string_lossy()]));
self.command_runner.run_successfully("unzip", &[zip.as_ref(), "-d".as_ref(), Path::new(&*self.base).join("wp-content/plugins").as_os_str()]) self.command_runner.run_successfully("unzip", &[zip.as_ref(), "-d".as_ref(), Path::new(&*self.base).join("wp-content/plugins").as_os_str()])
@ -90,9 +90,9 @@ impl<'a, C, R> Symbol for WordpressPlugin<'a, C, R> where C: Deref<Target=str> +
} }
} }
impl<'a, C, R> fmt::Display for WordpressPlugin<'a, C, R> where C: Deref<Target=str> + fmt::Display, R: CommandRunner {
impl<'a, C, R> fmt::Display for WordpressPlugin<'a, C, R> where C: Deref<Target=str>, R: CommandRunner {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error>{ fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error>{
write!(f, "WordpressPlugin {}", self.name)
write!(f, "WordpressPlugin {}", &*self.name)
} }
} }

20
src/symbols/wordpress/translation.rs

@ -11,15 +11,15 @@ use command_runner::CommandRunner;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner}; use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
use resources::Resource; use resources::Resource;
pub struct WordpressTranslation<'a, C, D, R> where C: AsRef<str> + fmt::Display, D: AsRef<str> + fmt::Display, R: 'a + CommandRunner {
pub struct WordpressTranslation<'a, C, D, R> where C: AsRef<str>, D: AsRef<str>, R: 'a + CommandRunner {
path: D, path: D,
version: &'a str, version: &'a str,
locale: C, locale: C,
command_runner: &'a R command_runner: &'a R
} }
impl<'a, C, R> WordpressTranslation<'a, C, String, R> where C: AsRef<str> + fmt::Display, R: CommandRunner {
pub fn new<D: AsRef<str> + fmt::Display>(path: D, version: &'a str, locale: C, command_runner: &'a R) -> Self {
impl<'a, C, R> WordpressTranslation<'a, C, String, R> where C: AsRef<str>, R: CommandRunner {
pub fn new<D: AsRef<str>>(path: D, version: &'a str, locale: C, command_runner: &'a R) -> Self {
WordpressTranslation { WordpressTranslation {
path: Path::new(path.as_ref()).join("wp-content/languages").to_string_lossy().to_string(), path: Path::new(path.as_ref()).join("wp-content/languages").to_string_lossy().to_string(),
version: version, version: version,
@ -29,7 +29,7 @@ impl<'a, C, R> WordpressTranslation<'a, C, String, R> where C: AsRef<str> + fmt:
} }
} }
impl<'a, C, D, R> WordpressTranslation<'a, C, D, R> where C: AsRef<str> + fmt::Display, D: AsRef<str> + fmt::Display, R: CommandRunner {
impl<'a, C, D, R> WordpressTranslation<'a, C, D, R> where C: AsRef<str>, D: AsRef<str>, R: CommandRunner {
fn get_pairs(&self) -> Vec<(String, String)> { fn get_pairs(&self) -> Vec<(String, String)> {
let version_x = self.version.trim_right_matches(|c: char| c.is_digit(10)).to_owned() + "x"; let version_x = self.version.trim_right_matches(|c: char| c.is_digit(10)).to_owned() + "x";
let locale: &str = self.locale.as_ref(); let locale: &str = self.locale.as_ref();
@ -39,7 +39,7 @@ impl<'a, C, D, R> WordpressTranslation<'a, C, D, R> where C: AsRef<str> + fmt::D
for format in ["po", "mo"].into_iter() { for format in ["po", "mo"].into_iter() {
res.push(( res.push((
format!("https://translate.wordpress.org/projects/wp/{}/{}{}/default/export-translations?format={}", version_x, in_slug, path_locale, format), format!("https://translate.wordpress.org/projects/wp/{}/{}{}/default/export-translations?format={}", version_x, in_slug, path_locale, format),
format!("{}/{}{}.{}", self.path, out_slug, self.locale, format)
format!("{}/{}{}.{}", self.path.as_ref(), out_slug, self.locale.as_ref(), format)
)) ))
} }
} }
@ -47,7 +47,7 @@ impl<'a, C, D, R> WordpressTranslation<'a, C, D, R> where C: AsRef<str> + fmt::D
} }
} }
impl<'a, C, D, R> Symbol for WordpressTranslation<'a, C, D, R> where C: AsRef<str> + fmt::Display, D: AsRef<str> + fmt::Display, R: CommandRunner {
impl<'a, C, D, R> Symbol for WordpressTranslation<'a, C, D, R> where C: AsRef<str>, D: AsRef<str>, R: CommandRunner {
fn target_reached(&self) -> Result<bool, Box<Error>> { fn target_reached(&self) -> Result<bool, Box<Error>> {
let mut newest = String::new(); let mut newest = String::new();
let match_date = Regex::new("(?m)^\"PO-Revision-Date: (.+)\\+0000\\\\n\"$").unwrap(); let match_date = Regex::new("(?m)^\"PO-Revision-Date: (.+)\\+0000\\\\n\"$").unwrap();
@ -72,8 +72,8 @@ impl<'a, C, D, R> Symbol for WordpressTranslation<'a, C, D, R> where C: AsRef<st
} }
} }
} }
let upstream = try!(self.command_runner.get_output("curl", &[&format!("https://api.wordpress.org/core/version-check/1.7/?version={}&locale={}", self.version, self.locale)]));
Ok(try!(String::from_utf8(upstream)).contains(&format!(r###"language":"{}","version":"{}","updated":"{}"###, self.locale, self.version, newest)))
let upstream = try!(self.command_runner.get_output("curl", &[&format!("https://api.wordpress.org/core/version-check/1.7/?version={}&locale={}", self.version, self.locale.as_ref())]));
Ok(try!(String::from_utf8(upstream)).contains(&format!(r###"language":"{}","version":"{}","updated":"{}"###, self.locale.as_ref(), self.version, newest)))
} }
fn execute(&self) -> Result<(), Box<Error>> { fn execute(&self) -> Result<(), Box<Error>> {
@ -96,9 +96,9 @@ impl<'a, C, D, R> Symbol for WordpressTranslation<'a, C, D, R> where C: AsRef<st
} }
} }
impl<'a, C, D, R> fmt::Display for WordpressTranslation<'a, C, D, R> where C: AsRef<str> + fmt::Display, D: AsRef<str> + fmt::Display, R: CommandRunner {
impl<'a, C, D, R> fmt::Display for WordpressTranslation<'a, C, D, R> where C: AsRef<str>, D: AsRef<str>, R: CommandRunner {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error>{ fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error>{
write!(f, "WordpressTranslation {}", self.path)
write!(f, "WordpressTranslation {}", self.path.as_ref())
} }
} }
Loading…
Cancel
Save