예제 #1
0
파일: SparkleRepo.cs 프로젝트: shish/guts
        // Returns a list of the latest change sets
        public override List<SparkleChangeSet> GetChangeSets(int count)
        {
            if (count < 1)
                count = 30;

            List <SparkleChangeSet> change_sets = new List <SparkleChangeSet> ();

            // Console.InputEncoding  = System.Text.Encoding.Unicode;
            Console.OutputEncoding = System.Text.Encoding.Unicode;

            SparkleGut gut_log = new SparkleGut (LocalPath, "get-change-sets --count=" + count);
            gut_log.Start ();

            // Reading the standard output HAS to go before
            // WaitForExit, or it will hang forever on output > 4096 bytes
            string output = gut_log.StandardOutput.ReadToEnd ();
            string [] lines = output.Split ("\n".ToCharArray ());
            gut_log.WaitForExit ();

            SparkleChangeSet change_set = null;
            foreach (string line in lines) {
                if (line.StartsWith ("revision")) {
                    change_set = new SparkleChangeSet ();
                    change_set.Folder = Name;
                    change_set.Url = Url;
                    change_sets.Add (change_set);
                }
                if(change_set == null)
                    continue;

                string[] kv = line.Split (":".ToCharArray (), 2);
                if(kv.Length != 2)
                    continue;

                string key = kv[0];
                string val = kv[1];

                if(key.Equals("revision")) {
                    change_set.Revision = val;
                }
                if(key.Equals("user")) {
                    Regex regex = new Regex (@"(.+) <(.+)>");
                    Match match = regex.Match (val);
                    change_set.User = new SparkleUser (match.Groups [1].Value, match.Groups [2].Value);
                }
                if(key.Equals("magical")) {
                    change_set.IsMagical = val.Equals("true");
                }
                if(key.Equals("timestamp")) {
                    Regex regex = new Regex (@"([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2}) (.[0-9]{4})");
                    Match match = regex.Match (val);
                    change_set.Timestamp = new DateTime (int.Parse (match.Groups [1].Value),
                        int.Parse (match.Groups [2].Value), int.Parse (match.Groups [3].Value),
                        int.Parse (match.Groups [4].Value), int.Parse (match.Groups [5].Value),
                        int.Parse (match.Groups [6].Value));
                    string time_zone     = match.Groups [7].Value;
                    int our_offset       = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).Hours;
                    int their_offset     = int.Parse (time_zone.Substring (0, 3));
                    change_set.Timestamp = change_set.Timestamp.AddHours (their_offset * -1);
                    change_set.Timestamp = change_set.Timestamp.AddHours (our_offset);
                }
                if(key.Equals("added")) {
                    change_set.Added.Add(val);
                }
                if(key.Equals("edited")) {
                    change_set.Edited.Add(val);
                }
                if(key.Equals("deleted")) {
                    change_set.Deleted.Add(val);
                }
            }

            return change_sets;
        }
예제 #2
0
파일: SparkleRepo.cs 프로젝트: shish/guts
        public override bool SyncUp()
        {
            SparkleGut gut = new SparkleGut (LocalPath, "sync-up");
            gut.StartInfo.RedirectStandardError = true;
            gut.Start ();

            double percentage = 1.0;
            Regex progress_regex = new Regex (@"([0-9]+)%", RegexOptions.Compiled);
            Regex speed_regex = new Regex (@"([0-9]+[KMG]?B/s)", RegexOptions.Compiled);
            while (!gut.StandardError.EndOfStream) {
                string line   = gut.StandardError.ReadLine ();
                Match progress_match = progress_regex.Match (line);
                Match speed_match    = speed_regex.Match (line);
                string speed  = "";
                double number = 0.0;

                if (progress_match.Success) {
                    number = double.Parse (progress_match.Groups [1].Value);
                }

                if (speed_match.Success) {
                    speed = speed_match.Groups [1].Value;
                }

                if (number >= percentage) {
                    percentage = number;
                    base.OnProgressChanged (percentage, speed);
                }
            }

            string output = gut.StandardOutput.ReadToEnd ().TrimEnd ();
            gut.WaitForExit ();
            return (output.Equals("true"));
        }
예제 #3
0
        public override bool Fetch()
        {
            // place settings into the folder
            this.gut = new SparkleGut (SparkleConfig.DefaultConfig.TmpPath,
                "configure \"" + TargetFolder + "\" --url=\"" + RemoteUrl + "\"" +
                " --user=\"" + SparkleConfig.DefaultConfig.User.Name +
                " <" + SparkleConfig.DefaultConfig.User.Email + ">\"");
            this.gut.Start ();
            this.gut.StandardOutput.ReadToEnd ().TrimEnd ();
            this.gut.WaitForExit ();

            // use the previously-set settings to fetch the base data
            this.gut = new SparkleGut (TargetFolder, "fetch");

            this.gut.StartInfo.RedirectStandardError = true;
            this.gut.Start ();

            double percentage = 1.0;
            Regex progress_regex = new Regex (@"([0-9]+)%", RegexOptions.Compiled);

            DateTime last_change     = DateTime.Now;
            TimeSpan change_interval = new TimeSpan (0, 0, 0, 1);

            while (!this.gut.StandardError.EndOfStream) {
                string line = this.gut.StandardError.ReadLine ();
                Match match = progress_regex.Match (line);

                double number = 0.0;
                if (match.Success) {
                    number = double.Parse (match.Groups [1].Value);
                }

                if (number >= percentage) {
                    percentage = number;

                    if (DateTime.Compare (last_change, DateTime.Now.Subtract (change_interval)) < 0) {
                        base.OnProgressChanged (percentage);
                        last_change = DateTime.Now;
                    }
                }
            }

            this.gut.WaitForExit ();
            SparkleHelpers.DebugInfo ("Gut", "Exit code " + this.gut.ExitCode.ToString ());

            while (percentage < 100) {
                percentage += 25;

                if (percentage >= 100)
                    break;

                base.OnProgressChanged (percentage);
                Thread.Sleep (750);
            }

            base.OnProgressChanged (100);
            Thread.Sleep (1000);

            if (this.gut.ExitCode != 0) {
                return false;
            } else {
                return true;
            }
        }