Пример #1
0
    def __init__(self, transmogrifier, name, options, previous):
        self.previous = previous
        self.transmogrifier = transmogrifier
        self.storage = IAnnotations(transmogrifier).get(ANNOTATION_KEY)

        # setup
        servername = safe_unicode(options.get('servername', ''))
        username = safe_unicode(options.get('username', ''))
        files_path = safe_unicode(options.get('server_files_path', ''))
        self.registry_filename = safe_unicode(options.get('registry_filename', ''))
        transfer_path = safe_unicode(options.get('transfer_path', '')) or u'/tmp'
        if not os.path.isabs(transfer_path):
            transfer_path = os.path.join(self.storage['wp'], transfer_path)
        if not os.path.exists(transfer_path):
            raise Exception("scp transfert path '{}' doesn't exist".format(transfer_path))
        if not servername or not username or not files_path or not self.registry_filename:
            logger.error('Missing server parameters or registry in csv_ssh_source section')
            raise Exception('Missing server parameters or registry in csv_ssh_source section')
        sshcmd = u'ssh {}@{} "{{}}"'.format(username, servername)
        scpcmd = u'scp {}@{}:{{}} {}'.format(username, servername, transfer_path)
        if not os.path.dirname(self.registry_filename):
            self.registry_filename = os.path.join(self.storage['wp'], self.registry_filename)
        self.storage['registry_filename'] = self.registry_filename
        self.registry = {}
        load_var(self.registry_filename, self.registry)
        self.storage['registry_dic'] = self.registry
        last_done = self.registry and max(self.registry) or ''

        # get files list
        (out, err, code) = runCommand(sshcmd.format(u'cd {}; ls'.format(files_path)))
        if code:
            logger.error("ERR:{}".format(''.join(err)))
            raise Exception('Cannot list server files')
        files = dict([(fil.strip('\n'), '') for fil in out])

        # take newer files
        to_do = []
        for dt in sorted([fil[:-4] for fil in files if fil.endswith('.txt')], reverse=True):
            if dt <= last_done:
                break
            to_do.insert(0, dt)

        # transfer files
        self.input_files = []
        for dt in to_do:
            rec = [dt, '', '', '']
            for i, typ in enumerate(MANAGED_TYPES, 1):
                filename = '{}_{}s.csv'.format(dt, typ)
                if filename in files:
                    cmd = scpcmd.format(os.path.join(files_path, filename))
                    (out, err, code) = runCommand(cmd)
                    if code:
                        logger.error("ERR:{}".format(''.join(err)))
                        raise Exception("Cannot run command '{}'".format(cmd))
                    rec[i] = os.path.join(transfer_path, filename)
            self.input_files.append(rec)
 def setUpZope(self, app, configurationContext):
     """Set up Zope."""
     # Load ZCML
     self.loadZCML(package=collective.documentgenerator,
                   name='testing.zcml')
     (stdout, stderr,
      st) = runCommand('%s/bin/soffice.sh restart' % os.getenv('PWD'))
Пример #3
0
 def tearDownZope(self, app):
     """Tear down Zope."""
     if HAS_PLONE_5_2:
         from plone.testing import zope
         zope.uninstallProduct(app, 'collective.documentgenerator')
     else:
         z2.uninstallProduct(app, 'collective.documentgenerator')
     (stdout, stderr,
      st) = runCommand('%s/bin/soffice.sh stop' % os.getenv('PWD'))
Пример #4
0
def generate(output_dir, domain):
    """ Generate taskjuggler report """
    verbose("Begin of taskjuggler report")
    records_nb = 0
    output_dir = output_dir.rstrip('/')
    DAY_DIR = os.path.join(output_dir, date.strftime(date.today(), "%Y-%m-%d"))
    rep_cmd = base_rep_cmd.replace('DAY_DIR', DAY_DIR)
    if not os.path.exists(DAY_DIR):
        os.makedirs(os.path.join(DAY_DIR, 'css'))
        os.symlink('%s/custom.css' % BUILD_PATH, '%s/css/custom.css' % DAY_DIR)
    outfiles['index']['file'] = os.path.join(output_dir,
                                             outfiles['index']['filename'])
    outfiles['error']['file'] = os.path.join(output_dir,
                                             outfiles['error']['filename'])
    report_err = [outfiles['error']['filename'], 0]
    verbose("Running command: %s" % rep_cmd)
    (cmd_out, cmd_err) = runCommand(rep_cmd)
    errors = [err for err in cmd_err if 'Error: ' in err]
    if errors:
        errors_str = '\n'.join(errors)
        error("error running command %s : %s" % (rep_cmd, errors_str))
        write_to(outfiles, 'error', errors_str)
        report_err[1] = len(errors)
    gen_err = ['generation_errors.html', 0]
    if os.path.exists(os.path.join(output_dir, gen_err[0])):
        lines = read_file(os.path.join(output_dir, gen_err[0]),
                          skip_empty=True)
        # Records number:
        for line in lines:
            # mo = records_pat.match(line)
            mo = tickets_pat.match(line)
            if mo:
                records_nb = mo.group(1)
                break
        if lines:
            gen_err[1] = len(lines) - 1
    olds = read_dir(output_dir, only_folders=True)
    template = env.get_template('index.html')
    rendered = template.render(report_err=report_err,
                               gen_err=gen_err,
                               olds=olds,
                               records_nb=records_nb,
                               domain=domain)
    write_to(outfiles, 'index', rendered.encode('utf8'))
    close_outfiles(outfiles)
    # delete wrong generated folder
    if report_err[1] and os.path.exists(DAY_DIR):
        shutil.rmtree(DAY_DIR, ignore_errors=True)
    verbose("End of taskjuggler report")
Пример #5
0
 def setUpZope(self, app, configurationContext):
     ztc.utils.setupCoreSessions(app)
     super(DmsmailLayer, self).setUpZope(app, configurationContext)
     from App.config import _config
     if not base_hasattr(_config, 'product_config'):
         _config.product_config = {
             'imio.zamqp.core': {
                 'ws_url': 'http://localhost:6543',
                 'ws_password': '******',
                 'ws_login': '******',
                 'routing_key': '019999',
                 'client_id': '019999'
             }
         }
     (stdout, stderr,
      st) = runCommand('%s/bin/soffice.sh restart' % os.getenv('PWD'))
Пример #6
0
def generate(output_dir, domain):
    """ Generate taskjuggler report """
    verbose("Begin of taskjuggler report")
    records_nb = 0
    output_dir = output_dir.rstrip('/')
    DAY_DIR = os.path.join(output_dir, date.strftime(date.today(), "%Y-%m-%d"))
    rep_cmd = base_rep_cmd.replace('DAY_DIR', DAY_DIR)
    if not os.path.exists(DAY_DIR):
        os.makedirs(os.path.join(DAY_DIR, 'css'))
        os.symlink('%s/custom.css' % BUILD_PATH, '%s/css/custom.css' % DAY_DIR)
    outfiles['index']['file'] = os.path.join(output_dir, outfiles['index']['filename'])
    outfiles['error']['file'] = os.path.join(output_dir, outfiles['error']['filename'])
    report_err = [outfiles['error']['filename'], 0]
    verbose("Running command: %s" % rep_cmd)
    (cmd_out, cmd_err) = runCommand(rep_cmd)
    errors = [err for err in cmd_err if 'Error: ' in err]
    if errors:
        errors_str = '\n'.join(errors)
        error("error running command %s : %s" % (rep_cmd, errors_str))
        write_to(outfiles, 'error', errors_str)
        report_err[1] = len(errors)
    gen_err = ['generation_errors.html', 0]
    if os.path.exists(os.path.join(output_dir, gen_err[0])):
        lines = read_file(os.path.join(output_dir, gen_err[0]), skip_empty=True)
        # Records number:
        for line in lines:
            # mo = records_pat.match(line)
            mo = tickets_pat.match(line)
            if mo:
                records_nb = mo.group(1)
                break
        if lines:
            gen_err[1] = len(lines)-1
    olds = read_dir(output_dir, only_folders=True)
    template = env.get_template('index.html')
    rendered = template.render(report_err=report_err, gen_err=gen_err, olds=olds, records_nb=records_nb, domain=domain)
    write_to(outfiles, 'index', rendered.encode('utf8'))
    close_outfiles(outfiles)
    # delete wrong generated folder
    if report_err[1] and os.path.exists(DAY_DIR):
        shutil.rmtree(DAY_DIR, ignore_errors=True)
    verbose("End of taskjuggler report")
Пример #7
0
 def tearDownZope(self, app):
     """Tear down Zope."""
     super(DmsmailLayer, self).tearDownZope(app)
     (stdout, stderr,
      st) = runCommand('%s/bin/soffice.sh stop' % os.getenv('PWD'))
Пример #8
0
 def tearDownZope(self, app):
     """Tear down Zope."""
     (stdout, stderr,
      st) = runCommand('%s/bin/soffice.sh stop' % os.getenv('PWD'))
Пример #9
0
 def setUpZope(self, app, configurationContext):
     ztc.utils.setupCoreSessions(app)
     super(PSTLayer, self).setUpZope(app, configurationContext)
     (stdout, stderr,
      st) = runCommand('%s/bin/soffice.sh restart' % os.getenv('PWD'))
 def tearDownZope(self, app):
     """Tear down Zope."""
     z2.uninstallProduct(app, 'collective.documentgenerator')
     (stdout, stderr,
      st) = runCommand('%s/bin/soffice.sh stop' % os.getenv('PWD'))
 def tearDownZope(self, app):
     """Tear down Zope."""
     z2.uninstallProduct(app, 'collective.documentgenerator')
     (stdout, stderr, st) = runCommand('%s/bin/soffice.sh stop' % os.getenv('PWD'))
 def setUpZope(self, app, configurationContext):
     """Set up Zope."""
     # Load ZCML
     self.loadZCML(package=collective.documentgenerator,
                   name='testing.zcml')
     (stdout, stderr, st) = runCommand('%s/bin/soffice.sh restart' % os.getenv('PWD'))