diff options
-rw-r--r-- | src/crystfel_gui.c | 45 | ||||
-rw-r--r-- | src/crystfel_gui.h | 2 | ||||
-rw-r--r-- | src/gui_backend_local.c | 45 | ||||
-rw-r--r-- | src/gui_backend_slurm.c | 63 |
4 files changed, 55 insertions, 100 deletions
diff --git a/src/crystfel_gui.c b/src/crystfel_gui.c index ad0b58a6..1c27ac7b 100644 --- a/src/crystfel_gui.c +++ b/src/crystfel_gui.c @@ -38,6 +38,9 @@ #include <gtk/gtk.h> #include <gdk/gdkkeysyms-compat.h> #include <assert.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> #include <datatemplate.h> #include <peaks.h> @@ -1328,3 +1331,45 @@ struct gui_job_notes_page *add_job_notes_page(GtkWidget *notebook) gtk_label_new("Notes")); return notes; } + + +GFile *make_job_folder(const char *job_title, const char *job_notes) +{ + struct stat s; + char *workdir; + GFile *workdir_file; + GFile *cwd_file; + GFile *notes_file; + char *notes_path; + FILE *fh; + + workdir = strdup(job_title); + if ( workdir == NULL ) return NULL; + + if ( stat(workdir, &s) != -1 ) { + ERROR("Working directory already exists. " + "Choose a different job name.\n"); + return NULL; + } + + if ( mkdir(workdir, S_IRWXU) ) { + ERROR("Failed to create working directory: %s\n", + strerror(errno)); + return NULL; + } + + cwd_file = g_file_new_for_path("."); + workdir_file = g_file_get_child(cwd_file, workdir); + g_object_unref(cwd_file); + + /* Write the notes into notes.txt */ + notes_file = g_file_get_child(workdir_file, "notes.txt"); + notes_path = g_file_get_path(notes_file); + fh = fopen(notes_path, "w"); + fputs(job_notes, fh); + fclose(fh); + g_free(notes_path); + g_object_unref(notes_file); + + return workdir_file; +} diff --git a/src/crystfel_gui.h b/src/crystfel_gui.h index 7dce84c4..fd80c9d1 100644 --- a/src/crystfel_gui.h +++ b/src/crystfel_gui.h @@ -54,4 +54,6 @@ extern char *get_crystfel_exe(const char *program); extern struct gui_job_notes_page *add_job_notes_page(GtkWidget *notebook); +extern GFile *make_job_folder(const char *job_title, const char *job_notes); + #endif diff --git a/src/gui_backend_local.c b/src/gui_backend_local.c index 26eda1ed..8cad40c3 100644 --- a/src/gui_backend_local.c +++ b/src/gui_backend_local.c @@ -35,6 +35,7 @@ #include <utils.h> +#include "crystfel_gui.h" #include "gui_project.h" #include "gui_index.h" #include "gui_merge.h" @@ -167,50 +168,6 @@ void setup_subprocess(gpointer user_data) } -static GFile *make_job_folder(const char *job_title, - const char *job_notes) -{ - struct stat s; - char *workdir; - GFile *workdir_file; - GFile *cwd_file; - GFile *notes_file; - char *notes_path; - FILE *fh; - - workdir = strdup(job_title); - if ( workdir == NULL ) return NULL; - - if ( stat(workdir, &s) != -1 ) { - ERROR("Working directory already exists. " - "Choose a different job name.\n"); - return NULL; - } - - if ( mkdir(workdir, S_IRWXU) ) { - ERROR("Failed to create working directory: %s\n", - strerror(errno)); - return NULL; - } - - cwd_file = g_file_new_for_path("."); - workdir_file = g_file_get_child(cwd_file, workdir); - g_object_unref(cwd_file); - - /* Write the notes into notes.txt */ - notes_file = g_file_get_child(workdir_file, "notes.txt"); - notes_path = g_file_get_path(notes_file); - fh = fopen(notes_path, "w"); - fputs(job_notes, fh); - fclose(fh); - g_free(notes_path); - g_object_unref(notes_file); - - return workdir_file; -} - - - static struct local_job *start_local_job(char **args, const char *job_title, GFile *workdir_file, diff --git a/src/gui_backend_slurm.c b/src/gui_backend_slurm.c index e6526574..c8572d5d 100644 --- a/src/gui_backend_slurm.c +++ b/src/gui_backend_slurm.c @@ -28,9 +28,6 @@ #include <glib.h> #include <gtk/gtk.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <unistd.h> #include <slurm/slurm.h> #include <gio/gio.h> @@ -356,49 +353,6 @@ static void write_partial_file_list(GFile *workdir, } -static char *make_workdir(const char *job_title, - const char *job_notes) -{ - char *workdir; - struct stat s; - GFile *cwd_file; - GFile *notes_file; - GFile *workdir_file; - char *notes_path; - FILE *fh; - - workdir = strdup(job_title); - if ( workdir == NULL ) return NULL; - - if ( stat(workdir, &s) != -1 ) { - ERROR("Working directory already exists. " - "Choose a different job name.\n"); - return NULL; - } - - if ( mkdir(workdir, S_IRWXU) ) { - ERROR("Failed to create working directory: %s\n", - strerror(errno)); - return NULL; - } - - cwd_file = g_file_new_for_path("."); - workdir_file = g_file_get_child(cwd_file, workdir); - g_object_unref(cwd_file); - - notes_file = g_file_get_child(workdir_file, "notes.txt"); - notes_path = g_file_get_path(notes_file); - fh = fopen(notes_path, "w"); - fputs(job_notes, fh); - fclose(fh); - g_free(notes_path); - g_object_unref(notes_file); - - workdir = g_file_get_path(workdir_file); - return workdir; -} - - static void *run_indexing(const char *job_title, const char *job_notes, struct crystfelproject *proj, @@ -411,12 +365,10 @@ static void *run_indexing(const char *job_title, int i; int fail = 0; char **streams; - char *workdir; GFile *workdir_gfile; - workdir = make_workdir(job_title, job_notes); - if ( workdir == NULL ) return NULL; - workdir_gfile = g_file_new_for_path(workdir); + workdir_gfile = make_job_folder(job_title, job_notes); + if ( workdir_gfile == NULL ) return NULL; env = create_env(&n_env, opts->path_add); @@ -471,7 +423,7 @@ static void *run_indexing(const char *job_title, env, n_env, job_name, - workdir, + g_file_get_path(workdir_gfile), stderr_file, stdout_file, &proj->peak_search_params, @@ -499,7 +451,6 @@ static void *run_indexing(const char *job_title, for ( i=0; i<n_env; i++ ) free(env[i]); free(env); - free(workdir); g_object_unref(workdir_gfile); if ( fail ) { @@ -762,11 +713,11 @@ static void *run_merging(const char *job_title, char **env; int n_env; struct slurm_merging_opts *opts = opts_priv; - char *workdir; + GFile *workdir_gfile; int r; - workdir = make_workdir(job_title, job_notes); - if ( workdir == NULL ) return NULL; + workdir_gfile = make_job_folder(job_title, job_notes); + if ( workdir_gfile == NULL ) return NULL; job = malloc(sizeof(struct slurm_job)); if ( job == NULL ) return NULL; @@ -800,7 +751,7 @@ static void *run_merging(const char *job_title, job_desc_msg.name = safe_strdup(job_title); job_desc_msg.std_err = strdup("stderr.log"); job_desc_msg.std_out = strdup("stdout.log"); - job_desc_msg.work_dir = strdup(workdir); + job_desc_msg.work_dir = g_file_get_path(workdir_gfile); job_desc_msg.script = script; job_desc_msg.environment = env; job_desc_msg.env_size = n_env; |