Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/rev/15c2b5180c3a
Дата изменения: Unknown
Дата индексирования: Tue Oct 2 00:50:55 2012
Кодировка:
allpy: 15c2b5180c3a

allpy

changeset 465:15c2b5180c3a

blocks3d/wt: remove old temp files temp files are being deleted when user closes window or runs new task
author boris <bnagaev@gmail.com>
date Thu, 17 Feb 2011 00:56:42 +0300
parents c0eceeb6b223
children 80df4de5073a
files blocks3d/wt/blocks3d-wt-widget.C blocks3d/wt/blocks3d-wt-widget.h blocks3d/wt/locales/blocks3d.xml
diffstat 3 files changed, 41 insertions(+), 11 deletions(-) [+]
line diff
     1.1 --- a/blocks3d/wt/blocks3d-wt-widget.C	Thu Feb 17 00:34:55 2011 +0300
     1.2 +++ b/blocks3d/wt/blocks3d-wt-widget.C	Thu Feb 17 00:56:42 2011 +0300
     1.3 @@ -116,6 +116,12 @@
     1.4      timer->setInterval(Malakite::refresh_period);
     1.5  }
     1.6  
     1.7 +
     1.8 +Blocks3DWidget::~Blocks3DWidget()
     1.9 +{
    1.10 +    drop_tempfiles();
    1.11 +}
    1.12 +
    1.13  void Blocks3DWidget::go_button_click()
    1.14  {
    1.15      try_to_run();
    1.16 @@ -218,13 +224,18 @@
    1.17          return;
    1.18      }
    1.19  
    1.20 -    char* tmpdir = strdup(Malakite::temp_mkstemp_path);
    1.21 -    mkdtemp(tmpdir);
    1.22 -    tempfile_alignment = std::string(tmpdir) + "/alignment.fasta";
    1.23 -    tempfile_conformity = std::string(tmpdir) + "/conformity";
    1.24 -    tempfile_html = std::string(tmpdir) + "/html";
    1.25 -    tempfile_check = std::string(tmpdir) + "/check";
    1.26 -    tempfile_sh = std::string(tmpdir) + "/run.sh";
    1.27 +    drop_tempfiles();
    1.28 +    {
    1.29 +        char* tmpdir = strdup(Malakite::temp_mkstemp_path);
    1.30 +        mkdtemp(tmpdir);
    1.31 +        temp_dir = std::string(tmpdir);
    1.32 +        free(tmpdir);
    1.33 +    }
    1.34 +    tempfile_alignment = temp_dir + "/alignment.fasta";
    1.35 +    tempfile_conformity = temp_dir + "/conformity";
    1.36 +    tempfile_html = temp_dir + "/html";
    1.37 +    tempfile_check = temp_dir + "/check";
    1.38 +    tempfile_sh = temp_dir + "/run.sh";
    1.39  
    1.40      std::ofstream alignment_file;
    1.41      alignment_file.open(tempfile_alignment.c_str());
    1.42 @@ -242,7 +253,8 @@
    1.43      std::string conformity_option = "";
    1.44      if (!conformity.empty())
    1.45      {
    1.46 -        conformity_option = str(boost::format("-c %s") % tempfile_conformity);
    1.47 +        conformity_option = str(boost::format("-c %s")
    1.48 +            % tempfile_conformity);
    1.49      }
    1.50  
    1.51      std::string cmd = str(
    1.52 @@ -254,8 +266,10 @@
    1.53      % tempfile_alignment
    1.54      % conformity_option
    1.55      % tempfile_html
    1.56 -    % delta_input->text().toUTF8() % min_block_width_input->text().toUTF8()
    1.57 -    % timeout_input->text().toUTF8() % timeout2_input->text().toUTF8()
    1.58 +    % delta_input->text().toUTF8()
    1.59 +    % min_block_width_input->text().toUTF8()
    1.60 +    % timeout_input->text().toUTF8()
    1.61 +    % timeout2_input->text().toUTF8()
    1.62      % tempfile_check
    1.63      );
    1.64  
    1.65 @@ -280,7 +294,6 @@
    1.66      go_button->hide();
    1.67  
    1.68      current_taks.push_back(tempfile_check);
    1.69 -    free(tmpdir);
    1.70  }
    1.71  
    1.72  void Blocks3DWidget::timeout()
    1.73 @@ -319,6 +332,17 @@
    1.74      Wt::WFileResource* html_download =
    1.75      new Wt::WFileResource("application/html", tempfile_html, this);
    1.76      new Wt::WAnchor(html_download, tr("Download"), results_panel);
    1.77 +
    1.78 +    new Wt::WBreak(results_panel);
    1.79 +    new Wt::WText(tr("tempfiles_comments"), results_panel);
    1.80  }
    1.81  
    1.82 +void Blocks3DWidget::drop_tempfiles()
    1.83 +{
    1.84 +    if (!temp_dir.empty())
    1.85 +    {
    1.86 +        system((str(boost::format("/bin/rm -rf %s") % temp_dir)).c_str());
    1.87 +        temp_dir = "";
    1.88 +    }
    1.89 +}
    1.90  
     2.1 --- a/blocks3d/wt/blocks3d-wt-widget.h	Thu Feb 17 00:34:55 2011 +0300
     2.2 +++ b/blocks3d/wt/blocks3d-wt-widget.h	Thu Feb 17 00:56:42 2011 +0300
     2.3 @@ -22,6 +22,7 @@
     2.4  {
     2.5  public:
     2.6      Blocks3DWidget(Wt::WContainerWidget* parent=0);
     2.7 +    virtual ~Blocks3DWidget();
     2.8  
     2.9  private:
    2.10      Wt::WFileUpload* alignment_upload;
    2.11 @@ -44,6 +45,7 @@
    2.12      Wt::WTimer* timer;
    2.13      Worktime* worktime;
    2.14  
    2.15 +    std::string temp_dir;
    2.16      std::string tempfile_alignment;
    2.17      std::string tempfile_conformity;
    2.18      std::string tempfile_html;
    2.19 @@ -59,6 +61,7 @@
    2.20      void fileTooLarge();
    2.21      void try_to_run();
    2.22      void timeout();
    2.23 +    void drop_tempfiles();
    2.24  };
    2.25  
    2.26  #endif // MALAKITE_BLOCKS3D_WIDGET_H_
     3.1 --- a/blocks3d/wt/locales/blocks3d.xml	Thu Feb 17 00:34:55 2011 +0300
     3.2 +++ b/blocks3d/wt/locales/blocks3d.xml	Thu Feb 17 00:56:42 2011 +0300
     3.3 @@ -24,6 +24,9 @@
     3.4      </message>
     3.5      <message id='View'>View</message>
     3.6      <message id='Download'>Download</message>
     3.7 +    <message id='tempfiles_comments'>
     3.8 +        Files will be deleted when you close window or run new task.
     3.9 +    </message>
    3.10  
    3.11      <message id='file_too_large'>File too large</message>
    3.12      <message id='upload_finished'>Upload finished</message>