Beispiel #1
0
static rc_t populate_tool_ctx( tool_ctx_t * tool_ctx, const Args * args )
{
    rc_t rc = ArgsParamValue( args, 0, ( const void ** )&( tool_ctx -> accession_path ) );
    if ( rc != 0 )
        ErrMsg( "ArgsParamValue() -> %R", rc );
    else
    {
        tool_ctx -> lookup_filename[ 0 ] = 0;
        tool_ctx -> index_filename[ 0 ] = 0;
        tool_ctx -> dflt_output[ 0 ] = 0;
    
        get_user_input( tool_ctx, args );
        encforce_constrains( tool_ctx );
        get_environment( tool_ctx );
        
        rc = make_temp_dir( &tool_ctx -> temp_dir,
                          tool_ctx -> requested_temp_path,
                          tool_ctx -> dir );
    }
    
    if ( rc == 0 )
        rc = handle_accession( tool_ctx );
    
    if ( rc == 0 )
        rc = handle_lookup_path( tool_ctx );
    
    if ( rc == 0 && tool_ctx -> output_dirname != NULL )
    {
        if ( !dir_exists( tool_ctx -> dir, "%s", tool_ctx -> output_dirname ) )
            rc = create_this_dir_2( tool_ctx -> dir, tool_ctx -> output_dirname, true );
    }
    
    if ( rc == 0 )
    {
        if ( tool_ctx -> output_filename == NULL )
        {
            if ( tool_ctx -> output_dirname == NULL )
                rc = make_output_filename_from_accession( tool_ctx );
            else
                rc = make_output_filename_from_dir_and_accession( tool_ctx );
        }
        else
        {
            if ( tool_ctx -> output_dirname == NULL )
                rc = adjust_output_filename( tool_ctx );
            else
                rc = adjust_output_filename_by_dir( tool_ctx );
        }
    }
    
    if ( rc == 0 )
        rc = Make_FastDump_Cleanup_Task ( &( tool_ctx -> cleanup_task ) ); /* cleanup_task.c */
    if ( rc == 0 )
        rc = Add_Directory_to_Cleanup_Task ( tool_ctx -> cleanup_task, 
                get_temp_dir( tool_ctx -> temp_dir ) );
    return rc;
}
bool RcsInterfaceTarDiff::add(QString file)
{
	//printf("añadiendo archivo.\n");
	
	QString temp=make_temp_dir();
	
	QDate date=QDate::currentDate();
	QTime time=QTime::currentTime();
	QString version=date.toString("yyyy-MM-dd ")+time.toString("hh:mm:ss.zzz");
	
	
	QFile::copy(file, temp+"/"+ version);
	QString command, gzip;
	
	if(QFile::exists(repository))
	{
		QFile::copy(repository, temp+"/repo.tar.gz");
		command+="tar -uf repo.tar \""+version+"\"";
		//printf("El fichero exists.\n");
		gzip+="gzip -d repo.tar.gz";
		_system_(gzip, temp);
	}
	else
	{
		//printf("El fichero no exists.\n");
		command+="tar -cf repo.tar '"+version+"'";
	}
	
	int ok=_system_(command, temp);
	gzip="gzip repo.tar";
	_system_(gzip, temp);
	
	QFile::remove(repository);
	
	QFile::copy(temp+"/repo.tar.gz",repository);
	
// 	QFile::remove(temp+"/repo.tar.gz");
// 	QFile::remove( temp+"/"+ version);
	
	remove_temp_dir(temp);
	
	return ok!=0;
}
Beispiel #3
0
bool retcon::OnInit() {
	raii_set rs;
	//wxApp::OnInit();	//don't call this, it just calls the default command line processor
	SetAppName(appname);
	InitStdoutFilter();
	InitWxLogger();
	rs.add([&]() { DeInitWxLogger(); });

#if defined(__WXGTK__)
	InitGlibLogger();
	rs.add([&]() { DeInitGlibLogger(); });
#endif

	::wxInitAllImageHandlers();
	srand((unsigned int) time(nullptr));
	datadir = stdstrwx(wxStandardPaths::Get().GetUserDataDir());
	tmpdir = make_temp_dir("retcon-");
	cmdlineproc(argv, argc);
	if (terms_requested) {
		return false;
	}
	if (!globallogwindow) {
		new log_window(nullptr, LOGT::GROUP_LOGWINDEF, false);
	}
	if (!datadir.empty() && datadir.back() == '/') {
		datadir.pop_back();
	}
	wxString wxdatadir = wxstrstd(datadir);
	if (!::wxDirExists(wxdatadir)) {
		::wxMkdir(wxdatadir, 0700);
	}
	InitCFGDefaults();
	SetTermSigHandler();
	sm.InitMultiIOHandler();
	rs.add([&]() {
		sm.DeInitMultiIOHandler();
	});
	bool res = DBC_Init(datadir + "/retcondb.sqlite3");
	if (!res) {
		return false;
	}
	rs.add([&]() {
		DBC_DeInit();
	});
	if (terms_requested) {
		return false;
	}
	pool.reset(new ThreadPool::Pool(gc.threadpoollimit));

	InitGlobalFilters();

	RestoreWindowLayout();
	if (mainframelist.empty()) {
		mainframe *mf = new mainframe( appversionname, wxPoint(50, 50), wxSize(450, 340));

		if (alist.empty() && ad.tpanels.empty()) {
			//everything is empty, maybe new user
			//make 3 basic auto tpanels to make things more obvious
			auto flags = TPF::AUTO_ALLACCS | TPF::DELETEONWINCLOSE;
			auto tpt = tpanel::MkTPanel("", "", flags | TPF::AUTO_TW, 0);
			tpt->MkTPanelWin(mf, true);
			auto tpm = tpanel::MkTPanel("", "", flags | TPF::AUTO_MN, 0);
			tpm->MkTPanelWin(mf, false);
			auto tpd = tpanel::MkTPanel("", "", flags | TPF::AUTO_DM, 0);
			tpd->MkTPanelWin(mf, false);
		}
	}

	if (terms_requested) return false;

	mainframelist[0]->Show(true);
	for (auto &it : alist) {
		it->Setup();
		it->CalcEnabled();
		it->Exec();
	}

	if (terms_requested) return false;

	rs.cancel();
	return true;
}
bool RcsInterfaceTarDiff::setComment(QString version, QString comment)
{
	QString temp=make_temp_dir();
	
	QString command, gzip, properties_file;
	
	int ok;
	
	if(QFile::exists(repository))
	{
		QFile::copy(repository, temp+"/repo.tar.gz");
		gzip="gzip -d repo.tar.gz";
		ok=_system_(gzip, temp);
		command="tar -xf repo.tar ";
		ok=_system_(command, temp);
	}
	
	properties_file=temp+"/Properties.txt";
	
	QHash<QString, QString> list=readCommentsFromPropertiesFile(properties_file);
	
	list[version]=comment;
	
	writeCommentsToPropertiesFile(properties_file, list);
	
	
	QFile::remove(temp+"/repo.tar");
	
	//system(QString("ls -l '"+temp+"' ").toLocal8Bit().data());
	
	QDir d(temp);
	
	QStringList files=d.entryList();
	
	for(int i=0;i<files.size();i++)
	{
		if( files[i]=="." || files[i]==".." || files[i]=="repo.tar") continue;
		QString name=files[i];
		
		if(i==2) command="tar -cf repo.tar \""+name+"\" ";
		else command="tar -rf repo.tar \""+name+"\" ";
		
		ok=_system_(command, temp);
		
		//system(QString("cd '"+temp+"'; "+command).toLocal8Bit().data());
	}
	
	gzip="gzip repo.tar";
	ok=_system_(gzip, temp);
	
	//system(QString("tar -tzvf '"+temp+"/repo.tar.gz' ").toLocal8Bit().data());
	
	
	QFile::remove(repository);
	
	QFile::copy(temp+"/repo.tar.gz",repository);
	
	remove_temp_dir(temp);
	
	return ok!=0;
}
Beispiel #5
0
Datei: C.c Projekt: mattn/C-win32
int main(int argc, char** argv)
{
  int ret;
  
  setup_dir();
  
  /* init globals */
  gcc = sa_concat(gcc, "gcc"); /* replaced laterwards if c++ */
  gcc = sa_concat(gcc, "-I.");
  
  src_lines =
    sa_concat(src_lines,
	      "#define __LARGE_C__ " VERSION_INT_STR "\n"
	      "#ifdef __cplusplus\n"
	      "extern \"C\" {\n"
	      "#endif\n"
	      "#include <stdio.h>\n"
	      "#include <stdlib.h>\n"
	      "#ifdef __cplusplus\n"
	      "}\n"
	      "#include <iostream>\n"
	      "using namespace std;\n"
	      "#endif\n"
	      "\n"
	      "__LARGE_C_PREFIX__\n");
  
  argv++;
  { /* parse args, determine cache dir */
    char** new_argv = parse_args(argv, NULL, 0);
    for (; argv != new_argv; argv++) {
      add_spec(*argv, strlen(*argv) + 1);
    }
    if (! keep_files && (oneliner || *argv != NULL)) {
      struct stat st;
      if (oneliner) {
	build_store_dir();
      } else if (stat(*argv, &st) == 0) {
	add_spec(*argv, strlen(*argv) + 1);
	add_spec(&st.st_size, sizeof(st.st_size));
	add_spec(&st.st_mtime, sizeof(st.st_mtime));
	build_store_dir();
      }
    }
  }
  
  /* use cache if possible */
  if (store_dir != NULL && check_specs()) {
    char** child_argv = NULL;
#ifdef _WIN32
    _utime(store_dir, NULL); /* update mtime of the directory */
#else
    utimes(store_dir, NULL); /* update mtime of the directory */
#endif
    exec_file = str_concat(str_dup(store_dir), "/"A_OUT);
    child_argv = sa_concat(child_argv, exec_file);
#ifdef _WIN32
    {
      int status;
	  ret = spawn_w32(child_argv, &status);
      if (status == 0) exit(ret);
    }
#else
    execv(exec_file, child_argv);
#endif
    // if execv failed, we compile
    free(exec_file);
    remove_dir(store_dir);
  }
  
  /* prepare files */
  make_temp_dir();
  exec_file = str_concat(str_dup(temp_dir), "/"A_OUT);
  c_file = str_concat(str_dup(temp_dir), "/source.c");
  if ((src_fp = fopen(c_file, "wt")) == NULL) {
    cmd_error("failed to create temporary file: %s : %s\n", c_file,
	      strerror(errno));
  }
  while (src_lines != NULL && *src_lines != NULL) {
    fputs(*src_lines++, src_fp);
  }
  
  /* write source with adjustments */
  if (! oneliner) {
    FILE* fp;
    char* file;
    char* line;
    int line_no = 0;
    if (argv[0] == NULL) {
      fp = stdin;
      file = "stdin";
    } else if (strcmp(argv[0], "-") == 0) {
      fp = stdin;
      argv++;
      file = "stdin";
    } else {
      file = *argv++;
      if ((fp = fopen(file, "rt")) == NULL) {
	cmd_error("cannot open file: %s : %s\n", file, strerror(errno));
      }
      fprintf(src_fp, "# 1 \"%s\" 1\n", file);
    }
    while ((line = get_line(fp)) != NULL) {
      int comment_out = 0;
      line_no++;
      if (line_no == 1 && strncmp(line, "#!", 2) == 0) {
	comment_out = 1;
      } else if (line[0] == '#') {
	char* buf = str_dup(line + 1);
	char** tokens = split_tokens(buf);
	if (*tokens != NULL) {
	  if (strcmp(tokens[0], "option") == 0) {
	    parse_args(tokens + 1, file, line_no);
	    comment_out = 1;
	  }
	}
	free(buf);
	free(tokens);
      }
      if (comment_out == 1) {
	fprintf(src_fp, "// ");
      }
      fputs(line, src_fp);
    }
    fputs("\n", src_fp);
    if (fp != stdin) {
      fclose(fp);
    }
  }
  
  /* close source file */
  fputs("__LARGE_C_SUFFIX__\n", src_fp);
  fclose(src_fp);
  src_fp = NULL;
  
  /* compile */
  if (use_plusplus) {
    gcc[0] = "g++";
  }
  if (use_main) {
    gcc = sa_concat(gcc, "-D__LARGE_C_PREFIX__=");
    gcc = sa_concat(gcc, "-D__LARGE_C_SUFFIX__=");
  } else {
    gcc =
      sa_concat(gcc, "-D__LARGE_C_PREFIX__=int main(int argc, char** argv) {");
    gcc = sa_concat(gcc, "-D__LARGE_C_SUFFIX__=; return 0; }");
  }
  gcc = sa_concat(gcc, "-o");
  gcc = sa_concat(gcc, show_disassembly ? "-" : exec_file);
  gcc = sa_concat(gcc, c_file);
  gcc = sa_merge(gcc, lopts);
  if ((ret = call_proc(gcc, "could not execute compiler")) != 0) {
    cleanup();
    exit(ret);
  }
  
  if (show_disassembly) {
    cleanup();
    exit(0);
  }
  
  { /* execute */
    char** child_argv = NULL;
    if (use_debugger) {
      child_argv = sa_concat(child_argv, "gdb");
    }
    child_argv = sa_concat(child_argv, exec_file);
    child_argv = sa_merge(child_argv, argv);
    ret = call_proc(child_argv, "could not spawn child process");
  }
  
  /* move temp_dir to store_dir, if possible.
   * or, remove work_dir
   */
  if (store_dir == NULL) {
    cleanup();
  } else {
    save_specs();
    update_cache();
    if (rename(temp_dir, store_dir) != 0) {
      cleanup();
    }
  }
  
  return ret;
}