save scp backend work
This commit is contained in:
parent
1781584c75
commit
1f3ab4f529
139
SparkleLib/Scp/SparkleFetcherScp.cs
Normal file
139
SparkleLib/Scp/SparkleFetcherScp.cs
Normal file
|
@ -0,0 +1,139 @@
|
||||||
|
// SparkleShare, an instant update workflow to Git.
|
||||||
|
// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Xml;
|
||||||
|
|
||||||
|
namespace SparkleLib {
|
||||||
|
|
||||||
|
// Sets up a fetcher that can get remote folders
|
||||||
|
public class SparkleFetcherScp : SparkleFetcherBase {
|
||||||
|
|
||||||
|
public SparkleFetcherScp (string remote_url, string target_folder) :
|
||||||
|
base (remote_url, target_folder) { }
|
||||||
|
|
||||||
|
|
||||||
|
public override bool Fetch ()
|
||||||
|
{
|
||||||
|
SparkleScp scp = new SparkleScp (SparklePaths.SparkleTmpPath,
|
||||||
|
"-r \"" + base.remote_url + "\" " + "\"" + base.target_folder + "\"");
|
||||||
|
|
||||||
|
scp.Start ();
|
||||||
|
scp.WaitForExit ();
|
||||||
|
|
||||||
|
SparkleHelpers.DebugInfo ("Scp", "Exit code " + scp.ExitCode.ToString ());
|
||||||
|
|
||||||
|
if (scp.ExitCode != 0) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
InstallConfiguration ();
|
||||||
|
InstallExcludeRules ();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Install the user's name and email and some config into
|
||||||
|
// the newly cloned repository
|
||||||
|
private void InstallConfiguration ()
|
||||||
|
{
|
||||||
|
string log_file_path = SparkleHelpers.CombineMore (base.target_folder, ".sparkleshare", "log");
|
||||||
|
File.Create (log_file_path);
|
||||||
|
|
||||||
|
string config_file_path = SparkleHelpers.CombineMore (base.target_folder, ".sparkleshare", "config");
|
||||||
|
File.Create (config_file_path);
|
||||||
|
|
||||||
|
string config = "";
|
||||||
|
|
||||||
|
// Write the config to the file
|
||||||
|
TextWriter writer = new StreamWriter (config_file_path);
|
||||||
|
writer.WriteLine (config);
|
||||||
|
writer.Close ();
|
||||||
|
|
||||||
|
SparkleHelpers.DebugInfo ("Config", "Added configuration to '" + config_file_path + "'");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Add a .gitignore file to the repo
|
||||||
|
private void InstallExcludeRules ()
|
||||||
|
{
|
||||||
|
string exlude_rules_file_path = SparkleHelpers.CombineMore (base.target_folder, ".sparkleshare", "exclude");
|
||||||
|
File.Create (exlude_rules_file_path);
|
||||||
|
|
||||||
|
TextWriter writer = new StreamWriter (exlude_rules_file_path);
|
||||||
|
|
||||||
|
// gedit and emacs
|
||||||
|
writer.WriteLine ("*~");
|
||||||
|
|
||||||
|
// vi(m)
|
||||||
|
writer.WriteLine (".*.sw[a-z]");
|
||||||
|
writer.WriteLine ("*.un~");
|
||||||
|
writer.WriteLine ("*.swp");
|
||||||
|
writer.WriteLine ("*.swo");
|
||||||
|
|
||||||
|
// KDE
|
||||||
|
writer.WriteLine (".directory");
|
||||||
|
|
||||||
|
// Mac OSX
|
||||||
|
writer.WriteLine (".DS_Store");
|
||||||
|
writer.WriteLine ("Icon?");
|
||||||
|
writer.WriteLine ("._*");
|
||||||
|
writer.WriteLine (".Spotlight-V100");
|
||||||
|
writer.WriteLine (".Trashes");
|
||||||
|
|
||||||
|
// Mac OSX
|
||||||
|
writer.WriteLine ("*(Autosaved).graffle");
|
||||||
|
|
||||||
|
// Windows
|
||||||
|
writer.WriteLine ("Thumbs.db");
|
||||||
|
writer.WriteLine ("Desktop.ini");
|
||||||
|
|
||||||
|
// CVS
|
||||||
|
writer.WriteLine ("*/CVS/*");
|
||||||
|
writer.WriteLine (".cvsignore");
|
||||||
|
writer.WriteLine ("*/.cvsignore");
|
||||||
|
|
||||||
|
// Subversion
|
||||||
|
writer.WriteLine ("/.svn/*");
|
||||||
|
writer.WriteLine ("*/.svn/*");
|
||||||
|
|
||||||
|
writer.Close ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class SparkleScp : Process {
|
||||||
|
|
||||||
|
public SparkleScp (string path, string args) : base ()
|
||||||
|
{
|
||||||
|
EnableRaisingEvents = true;
|
||||||
|
StartInfo.FileName = SparkleBackend.DefaultBackend.Path;
|
||||||
|
StartInfo.Arguments = args;
|
||||||
|
StartInfo.RedirectStandardOutput = true;
|
||||||
|
StartInfo.UseShellExecute = false;
|
||||||
|
StartInfo.WorkingDirectory = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
new public void Start ()
|
||||||
|
{
|
||||||
|
SparkleHelpers.DebugInfo ("Cmd", StartInfo.FileName + " " + StartInfo.Arguments);
|
||||||
|
base.Start ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
122
SparkleLib/Scp/SparkleRepoScp.cs
Normal file
122
SparkleLib/Scp/SparkleRepoScp.cs
Normal file
|
@ -0,0 +1,122 @@
|
||||||
|
// SparkleShare, an instant update workflow to Git.
|
||||||
|
// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
namespace SparkleLib {
|
||||||
|
|
||||||
|
public class SparkleRepoScp : SparkleRepoBase {
|
||||||
|
|
||||||
|
public SparkleRepoScp (string path, SparkleBackend backend) :
|
||||||
|
base (path, backend) { }
|
||||||
|
|
||||||
|
|
||||||
|
public override string Url {
|
||||||
|
get {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override string Identifier {
|
||||||
|
get {
|
||||||
|
return "sparkles";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override string CurrentRevision {
|
||||||
|
get {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override bool CheckForRemoteChanges ()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override bool SyncUp ()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override bool SyncDown ()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override bool AnyDifferences {
|
||||||
|
get {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override bool HasUnsyncedChanges {
|
||||||
|
get {
|
||||||
|
string unsynced_file_path = SparkleHelpers.CombineMore (LocalPath,
|
||||||
|
".sparkleshare", "has_unsynced_changes");
|
||||||
|
|
||||||
|
return File.Exists (unsynced_file_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
set {
|
||||||
|
string unsynced_file_path = SparkleHelpers.CombineMore (LocalPath,
|
||||||
|
".sparkleshare", "has_unsynced_changes");
|
||||||
|
|
||||||
|
if (value) {
|
||||||
|
if (!File.Exists (unsynced_file_path))
|
||||||
|
File.Create (unsynced_file_path);
|
||||||
|
} else {
|
||||||
|
File.Delete (unsynced_file_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override List <SparkleChangeSet> GetChangeSets (int count)
|
||||||
|
{
|
||||||
|
var l = new List<SparkleChangeSet> ();
|
||||||
|
l.Add (new SparkleChangeSet () { UserName = "test", UserEmail = "test", Revision = "test", Timestamp = DateTime.Now });
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override void CreateInitialChangeSet ()
|
||||||
|
{
|
||||||
|
base.CreateInitialChangeSet ();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override bool UsesNotificationCenter
|
||||||
|
{
|
||||||
|
get {
|
||||||
|
string file_path = SparkleHelpers.CombineMore (LocalPath, ".sparkleshare", "disable_notification_center");
|
||||||
|
return !File.Exists (file_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue