bool RemoteRepositoryAssistant::try_git_push_repository (const ustring& name)
// Push repository.
{
  GwSpawn spawn ("git");
  spawn.workingdirectory (git_testing_directory (name));
  spawn.arg ("push");
  spawn.run();
  bool okay = (spawn.exitstatus == 0);
  if (!okay) {
    gtk_label_set_text(GTK_LABEL(label_try_git), _("git push to remote repository failed"));
  }
  return okay;
}
Esempio n. 2
0
void XeTeX::place_ptx2pdf_macros ()
{
  GwSpawn spawn (Directories->get_tar());
  spawn.workingdirectory (working_directory);
  spawn.arg ("zxf");
  spawn.arg (gw_build_filename (Directories->get_package_data (), "ptx2pdf.tar.gz"));
  spawn.run ();
  ustring ptx2pdf_directory = "ptx2pdf";
  ReadFiles rf (gw_build_filename (working_directory, ptx2pdf_directory), "", "");
  for (unsigned int i = 0; i < rf.files.size(); i++) {
    unix_mv (gw_build_filename (working_directory, ptx2pdf_directory, rf.files[i]), gw_build_filename (working_directory, rf.files[i]));
  }
  unix_rmdir (gw_build_filename (working_directory, ptx2pdf_directory));
}
Esempio n. 3
0
void gw_mkdir_with_parents(const ustring & directory)
// Creates directory, with the parents, if need be.
// Function mkdir could be used (see man 2 mkdir), but this does not allow for 
// the creation of the parent directories. The core utility mkdir provides
// this functionality, so is preferred, and used here.
// Later one g_mkdir_with_parents () was used, but this did not create 
// directories properly. Hence we are stuck with mkdir.
{
#if 0
  ustring s;
  GwSpawn spawn (Directories->get_mkdir());
  spawn.arg (Directories->get_mkdir_args());
  spawn.arg (directory);
/*   GwSpawn spawn("mkdir");
#ifndef WIN32
  spawn.arg("-p");
#endif
  spawn.arg(directory);
#ifdef WIN32
  spawn.devnull();
#endif
 */  spawn.run();
 #endif
 
#ifdef WIN32
	// Use Windows system call to do this "right"
	bool retval = CreateDirectory(directory.c_str(), NULL);
	// Returns 0 if OK
	// Returns non-zero if error, and GetLastError will tell us:
	// ERROR_ALREADY_EXISTS The specified directory already exists.
	// ERROR_PATH_NOT_FOUND One or more intermediate directories do not exist; this function will only create the final directory in the path.
	if (retval == 0) {
		int lasterr = GetLastError();
		if (lasterr == ERROR_ALREADY_EXISTS) { 
			// Not really an error, just informative
			mkdir_info("Already exists " + directory);
		}
		else if (lasterr == ERROR_PATH_NOT_FOUND) {
			mkdir_info("Cannot create " + directory + " because intermediate directories don't exist.");
			// Strip off last part of directory and try again recursively
			Glib::ustring::size_type idx = directory.find_last_of("\\");
			ustring newdir = directory.substr(0, idx);
			gw_mkdir_with_parents(newdir);
			// Now try the full path again
			gw_mkdir_with_parents(directory);
		}
	}
	else {
		// Not really an error, just informative
		mkdir_info("Created " + directory);
	}
#else
  GwSpawn spawn (Directories->get_mkdir());
  spawn.arg (Directories->get_mkdir_args());
  spawn.arg (directory);
  spawn.run();
#endif
}
Esempio n. 4
0
bool uncompress(const ustring & archive, const ustring & directory)
// Uncompresses "archive" into "directory".
// Returns whether this was successful.
{
  // Bail out if the archive was not recognized.
  if (!compressed_archive_recognized(archive)) {
    gw_critical(_("cannot uncompress unrecognized archive"));
    return false;
  }
  // Ensure that the output directory is there.
  gw_mkdir_with_parents (directory);

  // Get the uncompression identifier.
  int uncompression_identifier = uncompression_identifier_get (archive);

  // Do the uncompression.
  int result = -1;
  switch (uncompression_identifier) {
  case 0:
    {
		gw_message("I'm not yet smart enough to handle the " + archive + " file type");
		break;
    }
  case 1:
    { // If you have a zip utility installed in Windows, etc.
      GwSpawn spawn (Directories->get_unzip());
      spawn.arg ("-o"); // overwrite without prompting
      if (!directory.empty ()) {
        spawn.arg ("-d"); // extract files into exdir
        spawn.arg (directory);
      }
      spawn.arg (archive);
      spawn.progress (_("Unpacking"), false);
      spawn.run ();
      result = 0;
      break;
    }
  case 2:
    {
      GwSpawn spawn(Directories->get_tar());
	  spawn.arg ("--force-local"); // to permit : in filename (like C:\Users\...)
      spawn.arg("-xvzf"); // x=eXtract, z=gunZip, f=Filename to extract
      if (!directory.empty()) {
        spawn.workingdirectory(directory);
      }
      spawn.arg(archive);
      spawn.progress(_("Unpacking"), false);
      spawn.run();
      result = spawn.exitstatus;
	  DEBUG("tar return code="+std::to_string(result));
      break;
    }
  }

  // Return whether things were ok.  
  return (result == 0);
}
void RemoteRepositoryAssistant::on_assistant_apply ()
{
  // Configurations.
  extern Settings *settings;
  ProjectConfiguration *projectconfig = settings->projectconfig(bible);

  // Whether to use the remote repository.
  bool use_remote_repository = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbutton_use_repository));
  if (bible_notes_selector_bible ())
    projectconfig->git_use_remote_repository_set(use_remote_repository);
  else
    settings->genconfig.consultation_notes_git_use_remote_repository_set(use_remote_repository);

  // The remote repository URL.
  if (bible_notes_selector_bible ())
    projectconfig->git_remote_repository_url_set(repository_url_get());
  else
    settings->genconfig.consultation_notes_git_remote_repository_url_set(repository_url_get());
  
  // If the repository was cloned, move it into place.
  if (repository_was_cloned()) {
    ustring destination_data_directory;
    if (bible_notes_selector_bible ())
      destination_data_directory = project_data_directory_project(bible);
    else
      destination_data_directory = notes_shared_storage_folder ();
    unix_rmdir(destination_data_directory);
    unix_mv(persistent_clone_directory, destination_data_directory);
    // Switch rename detection off. 
    // This is necessary for the consultation notes, since git has been seen to cause spurious renames.
    GwSpawn spawn ("git");
    spawn.workingdirectory (destination_data_directory);
    spawn.arg ("config");
    spawn.arg ("--global");
    spawn.arg ("diff.renamelimit");
    spawn.arg ("0");
    spawn.run ();
  }

  if (bible_notes_selector_bible ()) {
    // Take a snapshot of the whole project.
    snapshots_shoot_project (bible);
  } else{
    // Create the index for the consultation notes.
    notes_create_index ();
  }

  // Show summary.
  gtk_assistant_set_current_page (GTK_ASSISTANT (assistant), summary_page_number);
}
bool RemoteRepositoryAssistant::try_git_fetch_repository (const ustring& remote, const ustring& local)
// Fetch the local into the remote repository.
{
  GwSpawn spawn ("git");
  spawn.workingdirectory (git_testing_directory (remote));
  spawn.arg ("--bare");
  spawn.arg ("fetch");
  spawn.arg (git_testing_directory (local));
  spawn.arg ("master:master");
  spawn.run();
  bool okay = (spawn.exitstatus == 0);
  if (!okay) {
    gtk_label_set_text(GTK_LABEL(label_try_git), _("git --bare fetch fails to fetch data into remote repository"));
  }
  return okay;
}
bool RemoteRepositoryAssistant::try_git_create_repository (const ustring& name, bool remote)
{
  ustring directory = git_testing_directory (name);
  gw_mkdir_with_parents (directory);
  GwSpawn spawn ("git");
  spawn.workingdirectory (directory);
  if (remote) 
    spawn.arg ("--bare");
  spawn.arg ("init");
  if (remote)
    spawn.arg ("--shared");
  spawn.run();
  bool okay = (spawn.exitstatus == 0);
  if (!okay) {
    gtk_label_set_text(GTK_LABEL(label_try_git), _("git init fails to create a repository"));
  }
  return okay;
}
Esempio n. 8
0
ustring XeTeX::run ()
{
  write_document_tex_file ();
  ustring pdf_file;
  if (runtime_check (rtXeTeX)) {
    pdf_file = gw_build_filename (working_directory, "document.pdf");
    bool re_run = false;
    unsigned int run_count = 0;
    do {
      run_count++;
      GwSpawn spawn (runtime_program (rtXeTeX));
      spawn.workingdirectory (working_directory);
      spawn.arg ("document.tex");
      spawn.read ();
      spawn.progress ("Formatting run " + convert_to_string (run_count), true);
      spawn.run ();
      re_run = false;
      for (unsigned int i = 0; i < spawn.standardout.size(); i++) {
        gw_message (spawn.standardout[i]);
        if (spawn.standardout[i].find ("re-run") != string::npos) 
        re_run = true;
      }
      for (unsigned int i = 0; i < spawn.standarderr.size(); i++) {
        gw_critical (spawn.standarderr[i]);
        if (spawn.standarderr[i].find ("re-run") != string::npos) 
          re_run = true;
      }
      // If the formatting process was cancelled, bail out, with no pdf file.
      if (spawn.cancelled) {
        return "";
      }
    } while (re_run && (run_count < 10));
  }
  // Info for user in logfile.
  gw_message (_("All the data for this document is available in temporal folder ") + working_directory + ".");
  gw_message (_("You can tune the files by hand, then run \"xetex document.tex\" in this folder to convert it into a PDF file."));
  return pdf_file;
}
void RemoteRepositoryAssistant::on_button_push ()
/*
It copies the existing data, without the .git directory, into the persistent clone,
replaces any data that was there, and then pushes this data to the remote repository.
This makes the remote repository to have an exact copy of our data.
*/
{
  // Progress.
  ProgressWindow progresswindow (_("Pushing your data"), false);
  progresswindow.set_fraction (0.2);
  
  // Copy our data into a temporal location.
  ustring my_data_directory = notes_shared_storage_folder ();
  if (bible_notes_selector_bible ())
    my_data_directory = project_data_directory_project(bible);
  ustring temporal_data_directory = git_testing_directory ("mydata");
  unix_cp_r (my_data_directory, temporal_data_directory);

  // In rare cases a .git directory could have been copied along with our data. Remove that.
  unix_rmdir (gw_build_filename (temporal_data_directory, ".git"));

  // Remove all directories and all files from the persistent clone directory, but leave the .git directory
  {
    ReadDirectories rd (persistent_clone_directory, "", "");
    for (unsigned int i = 0; i < rd.directories.size(); i++) {
      if (rd.directories[i] != ".git") {
        unix_rmdir (gw_build_filename (persistent_clone_directory, rd.directories[i]));
      }
    }
    ReadFiles rf (persistent_clone_directory, "", "");
    for (unsigned int i = 0; i < rf.files.size(); i++) {
      unlink (gw_build_filename (persistent_clone_directory, rf.files[i]).c_str());
    }
  }
  
  // Move our data, from its temporal location, into the persistent clone directory.
  progresswindow.set_fraction (0.4);
  {
    ReadDirectories rd (temporal_data_directory, "", "");
    for (unsigned int i = 0; i < rd.directories.size(); i++) {
      unix_mv (gw_build_filename (temporal_data_directory, rd.directories[i]), persistent_clone_directory);
    }
    ReadFiles rf (temporal_data_directory, "", "");
    for (unsigned int i = 0; i < rf.files.size(); i++) {
      unix_mv (gw_build_filename (temporal_data_directory, rf.files[i]), persistent_clone_directory);
    }
  }

  // Commit the new data in the persistent clone directory.
  progresswindow.set_fraction (0.55);
  {
    GwSpawn spawn ("git");
    spawn.workingdirectory (persistent_clone_directory);
    spawn.arg ("add");
    spawn.arg (".");
    spawn.run ();
  }
  progresswindow.set_fraction (0.65);
  {
    GwSpawn spawn ("git");
    spawn.workingdirectory (persistent_clone_directory);
    spawn.arg ("commit");
    spawn.arg ("-a");
    spawn.arg ("-m");
    spawn.arg ("user data into repo");
    spawn.run ();
  }

  // Push our data to the remote repository.
  progresswindow.set_fraction (0.8);
  GwSpawn spawn("git");
  spawn.workingdirectory(persistent_clone_directory);
  spawn.arg ("push");
  spawn.run();

  // Take action depending on the outcome of pushing to the remote repository.
  if (spawn.exitstatus == 0) {
    // Clone okay.
    gtk_label_set_text (GTK_LABEL (label_push), _("Your data has been pushed to the remote repository"));
  } else {
    // Clone failed.
    gtk_label_set_text (GTK_LABEL (label_push), _("Your data could not be pushed to the remote repository,\nplease restart the assistant"));
    repository_unclone();
  }  
}
bool RemoteRepositoryAssistant::try_git_store_data_in_repository (const ustring& repository, const gchar* data)
// Put data into the repository.
{
  ustring filename = git_testing_file (repository);
  g_file_set_contents(filename.c_str(), data, -1, NULL);
  ustring directory = git_testing_directory (repository);

  GwSpawn spawn ("git");
  spawn.workingdirectory (directory);
  spawn.arg ("add");
  spawn.arg (".");
  spawn.run();
  bool okay = (spawn.exitstatus == 0);
  
  if (!okay) {
    gtk_label_set_text(GTK_LABEL(label_try_git), _("git add fails to add data to the repository"));
  }

  if (okay) {
    GwSpawn spawn ("git");
    spawn.workingdirectory (directory);
    spawn.arg ("commit");
    spawn.arg ("-m");
    spawn.arg ("Commit");
    spawn.arg ("-a");  
    spawn.run();
    okay = (spawn.exitstatus == 0);
  }
  if (!okay) {
    gtk_label_set_text(GTK_LABEL(label_try_git), _("git commit fails to commit data to the repository"));
  }

  return okay;
}