def get_zipfile(self, cr, uid, ids, context=None): zfilecontent = '' if isinstance(ids, (int, long)): ids = [ids] product = self.browse(cr, uid, ids[0], context) zfilename = '%s_%s.zip' % (product.name, uuid.uuid4()) with cd(path.join(product.repository_id._parent_path, product.repository_id.relpath)): dirpath = path.join(os.getcwd(), product.name) if path.isdir(dirpath): with ZipFile(zfilename, 'w') as zfile: zipdir(path.relpath(dirpath), zfile) with open(zfilename, 'rb') as zfile: zfilecontent = zfile.read().encode('base64') product.write({'zipfile': zfilecontent, 'zipfilename': '%s.zip' % product.name}) return { 'name': _('Download zip'), 'type': 'ir.actions.act_window', 'view_type': 'form', 'view_mode': 'form', 'res_model': 'product.product', 'res_id': product.id, 'view_id': self.pool.get('ir.model.data').get_object_reference(cr, uid, 'smile_module_repository', 'view_product_product_form2')[1], 'target': 'new', 'context': context, }
def __enter__(self): self.savedPath = None while not self.savedPath: try: self.savedPath = os.getcwd() except OSError: os.chdir("..") os.chdir(self.newPath)
def call(cmd, directory=None): with cd(directory): command = cmd if isinstance(cmd, string_types) else ' '.join(cmd) try: result = '' if isinstance(cmd, list): cmd = ' '.join(cmd) for operator in (' ; ', ' && ', ' || '): if isinstance(cmd, string_types): cmd = cmd.split(operator) else: cmd = sum([item.split(operator) for item in cmd], []) for subcmd in cmd: subresult = '' for subcmd2 in subcmd.split(' & '): subresult = check_output_chain(subcmd2.split(' ')) result += subresult _logger.info('%s SUCCEEDED from %s' % (command, os.getcwd())) return result except subprocess.CalledProcessError as e: raise UserError( _('%s FAILED\nfrom %s (return code: %s)\n\n%s') % (command, os.getcwd(), e.returncode, e.output))
def cd(newPath): with _lock: newPath = newPath or '.' savedPath = None while not savedPath: try: savedPath = os.getcwd() except OSError: os.chdir("..") os.chdir(newPath) try: yield finally: os.chdir(savedPath)
def _call(cmd): command = cmd if isinstance(cmd, string_types) else ' '.join(cmd) _logger.debug('Calling command %s' % command) try: result = '' if isinstance(cmd, list): cmd = ' '.join(cmd) for operator in (' ; ', ' && ', ' || '): if isinstance(cmd, string_types): cmd = cmd.split(operator) else: cmd = sum([item.split(operator) for item in cmd], []) for subcmd in cmd: subresult = '' for subcmd2 in subcmd.split(' & '): subresult = check_output_chain(subcmd2.split(' ')) result += subresult _logger.info('%s SUCCEEDED from %s' % (command, os.getcwd())) return result except subprocess.CalledProcessError as e: msg = _('%s FAILED\nfrom %s\n\n(#%s) %s') % \ (command, os.getcwd(), e.returncode, e.output) raise UserError(msg)
def cd(newPath): with _lock: newPath = newPath or '.' savedPath = None while not savedPath: try: savedPath = os.getcwd() except OSError: os.chdir("..") _logger.debug('Changing working directory to %s' % newPath) os.chdir(newPath) try: yield finally: _logger.debug('Changing working directory to %s' % savedPath) os.chdir(savedPath)
def __enter__(self): self.savedPath = os.getcwd() os.chdir(self.newPath)
# In[11]: get_ipython().magic(u'load_ext autoreload') get_ipython().magic(u'autoreload 2') import warnings, sys warnings.filterwarnings('ignore') from leaparticulator.notebooks.StreamlinedDataAnalysisGhmm import analyze_log_file_in_phases_by_condition from leaparticulator import constants #, GHmmWrapper, gc from itertools import product from subprocess import Popen, PIPE, os, STDOUT from ProfileStreamlineNugget import do_it files = files files_n_units = product(files, [constants.XY, constants.AMP_AND_FREQ, constants.AMP_AND_MEL], [2]) files_n_units = [f for f in files_n_units] dd = os.getcwd() error = [] warning = [] output = [] # skip = [11,14, 17] # skip = lrange(115,226) skip = [] # 11 is a problem, again # skip = range(207) # return p = None from datetime import datetime log_file = open("logs/StreamlineLog-OrangeSquares.%s.log" % datetime.now(), 'w', 0) for i, (f, unit, phase) in enumerate(files_n_units): if i + 1 <= 1: