Commit 3889cb6b authored by Gerald Salin's avatar Gerald Salin
Browse files

#68 added md5sum un run.py > archive_files

parent ee8bc392
......@@ -25,6 +25,7 @@ __status__ = 'beta'
import os, uuid, logging, tempfile, re
import datetime, time
from subprocess import call
from subprocess import Popen, PIPE
from shutil import copyfile, rmtree
from configparser import ConfigParser, RawConfigParser
......@@ -97,16 +98,20 @@ class Run(object):
"""
nb_seq, full_size = 0, 0
for file in self.raw_files:
# Get nb_seq and full_size values
reader = seqio.SequenceReader(file)
for id, desc, seq, qualities in reader:
nb_seq += 1
full_size += len(seq)
try:
# Get nb_seq and full_size values
reader = seqio.SequenceReader(file)
for id, desc, seq, qualities in reader:
nb_seq += 1
full_size += len(seq)
except:
logging.getLogger("Run.sync").debug(file + " seems to not be a seq file")
self.set_nb_sequences(nb_seq)
self.set_full_size(full_size)
self.archive_files(self.raw_files, mode)
def archive_files(self, files, mode, archive_name="ng6_archive.tar", delete=False):
"""
Copy, archive and compress the files list to the run. Files can then be downloaded and gave back by
the script ng6run2ergatis.
......@@ -115,7 +120,7 @@ class Run(object):
@param archive_name: the archive name if tar is requested
@param delete: delete files
"""
list_files_md5 = ""
# create workdir if it does not exists
if not os.path.isdir(self.__get_work_directory()) :
os.makedirs(self.__get_work_directory(), 0o751)
......@@ -130,6 +135,7 @@ class Run(object):
for file in files:
if os.path.isfile(file):
copyfile(file, os.path.join(self.__get_work_directory(), os.path.basename(file)))
list_files_md5 += os.path.join(self.__get_work_directory(), os.path.basename(file)) + " "
# Finaly try to delete the original file if asked to do so
try:
if delete:
......@@ -140,18 +146,26 @@ class Run(object):
elif mode == "gz":
for file in files:
Utils.gzip(file, self.__get_work_directory(), delete)
list_files_md5 += os.path.join(self.__get_work_directory(), os.path.basename(file))+".gz" + " "
elif mode == "bz2":
for file in files:
Utils.bz2(file, self.__get_work_directory(), delete)
list_files_md5 += os.path.join(self.__get_work_directory(), os.path.basename(file))+".bz2" + " "
elif mode == "tar.gz":
Utils.tar_files(files, os.path.join(self.__get_work_directory(), archive_name), delete)
Utils.gzip(os.path.join(self.__get_work_directory(), archive_name), self.__get_work_directory(), True)
list_files_md5 += os.path.join(self.__get_work_directory(), archive_name) + ".gz" + " "
elif mode == "tar.bz2":
Utils.tar_files(files, os.path.join(self.__get_work_directory(), archive_name), delete)
Utils.bz2(os.path.join(self.__get_work_directory(), archive_name), self.__get_work_directory(), True)
list_files_md5 += os.path.join(self.__get_work_directory(), archive_name)+".bz2" + " "
logging.getLogger("Run").debug("archive_files. list_files_md5 = " + list_files_md5)
p = Popen("md5sum " + list_files_md5+"|awk -F/ {'print $1,$NF'} > "+os.path.join(self.__get_work_directory(), "md5sum.txt") ,shell=True,stdout=PIPE,stderr=PIPE,universal_newlines=True)
stdout,stderr = p.communicate()
logging.getLogger("Run").debug("archive_files. stdout = " + stdout)
def set_nb_sequences(self, nb_seqs):
"""
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment