예제 #1
0
def biomaj_remove(options, config):
    '''
    Remove a bank
    '''
    if not options.bank:
        return (False, "Bank name is missing")

    if options.remove and not options.release:
        return (False, "Bank release is missing")

    no_log = True
    if not options.proxy:
        no_log = False
    # If removeall, do not set logs as log dir will be deleted
    if options.removeall:
        no_log = True
    bmaj = Bank(options.bank, options=options, no_log=no_log)
    if bmaj.is_locked():
        return (False, 'Bank is locked due to an other action')

    res = True
    if options.removeall:
        if not options.proxy:
            res = bmaj.removeAll(options.force)
            return (res, '')
        res = biomaj_remove_request(options, config)
    else:
        if not options.proxy:
            res = bmaj.remove(options.release)
            Notify.notifyBankAction(bmaj)
            return (res, '')
        res = biomaj_remove_request(options, config)
    if not res:
        return (False, 'Failed to send removal request')
    return (True, 'Bank removal request sent')
예제 #2
0
 def test_directhttp_release(self):
     b = Bank('directhttp')
     res = b.update()
     self.assertTrue(b.session.get('update'))
     self.assertTrue(
         os.path.exists(b.session.get_full_release_directory() +
                        '/flat/debian/README.html'))
예제 #3
0
 def test_update_hardlinks(self):
   """
   Update a bank twice with hard links^. Files copied from previous release
   must be links.
   """
   b = Bank('local')
   b.config.set('keep.old.version', '3')
   b.config.set('use_hardlinks', '1')
   # First update
   b.update()
   self.assertTrue(b.session.get('update'))
   old_release = b.session.get_full_release_directory()
   # Update test.fasta to force update (not that this file is modified in the
   # source tree)
   remote_file = b.session.config.get('remote.dir') + 'test.fasta.gz'
   stat = os.stat(remote_file)
   one_day = 3600 * 24
   os.utime(remote_file, (stat.st_atime + one_day, stat.st_atime + one_day))
   # Second update
   b.update()
   self.assertTrue(b.session.get('update'))
   new_release = b.session.get_full_release_directory()
   # Test that test2.fasta in both release are the same file (we can't use
   # test.fasta because it is uncompressed and then not the same file)
   file_old_release = os.path.join(old_release, 'flat', 'test2.fasta')
   file_new_release = os.path.join(new_release, 'flat', 'test2.fasta')
   try:
       self.assertTrue(os.path.samefile(file_old_release, file_new_release))
   except AssertionError:
       msg = "In %s: copy worked but hardlinks were not used." % self.id()
       logging.info(msg)
   # Restore date (otherwise repeated tests fail)
   os.utime(remote_file, (stat.st_atime, stat.st_atime))
예제 #4
0
 def test_computed_ref_release(self):
   b = Bank('computed2')
   res = b.update(True)
   self.assertTrue(b.session.get('update'))
   b2 = Bank('computed2')
   res = b2.update(True)
   self.assertFalse(b2.session.get('update'))
예제 #5
0
def biomaj_bank_update(options):
    '''
    Update a bank
    '''
    if not options.bank:
        return (False, "Bank name is missing")
    banks = options.bank.split(',')
    gres = True
    msg = ''
    for bank in banks:
        options.bank = bank
        bmaj = Bank(bank, options=options, no_log=True)
        if bmaj.is_locked():
            return (False, 'Bank is locked due to an other action')
        check_status = bmaj.check()
        if not check_status:
            msg += 'Skip bank ' + options.bank + ': wrong config\n'
            gres = False
            continue
        else:
            msg += 'Bank update request sent for ' + options.bank + '\n'
            if not options.proxy:
                res = bmaj.update(depends=True)
                return (res, '')
            res = biomaj_bank_update_request(options)
            if not res:
                msg += 'Failed to send update request for ' + options.bank + '\n'

    if not gres:
        return (False, msg)
    return (True, msg)
예제 #6
0
def biomaj_bank_repair(options, config):
    '''
    Repair a bank
    '''
    if not options.bank:
        return (False, "Bank name is missing")
    banks = options.bank.split(',')
    gres = True
    msg = ''
    for bank in banks:
        options.bank = bank
        no_log = True
        if not options.proxy:
            no_log = False
        # logging.debug('Options: '+str(options.__dict__))
        bmaj = Bank(bank, options=options, no_log=no_log)
        check_status = bmaj.check()
        if not check_status:
            msg += 'Skip bank ' + options.bank + ': wrong config\n'
            gres = False
            continue
        else:
            msg += 'Bank repair request sent for ' + options.bank + '\n'
            if not options.proxy:
                res = bmaj.repair()
                Notify.notifyBankAction(bmaj)
            else:
                res = biomaj_bank_repair_request(options, config)
            if not res:
                msg += 'Failed to send repair request for ' + options.bank + '\n'
                gres = False

    if not gres:
        return (False, msg)
    return (True, msg)
예제 #7
0
def biomaj_remove(options):
    '''
    Remove a bank
    '''
    if not options.bank:
        return (False, "Bank name is missing")

    if options.remove and not options.release:
        return (False, "Bank release is missing")

    bmaj = Bank(options.bank, options=options, no_log=True)
    if bmaj.is_locked():
        return (False, 'Bank is locked due to an other action')

    res = True
    if options.removeall:
        if not options.proxy:
            res = bmaj.removeAll(options.force)
            return (res, '')
        res = biomaj_remove_request(options)
    else:
        if not options.proxy:
            res = bmaj.remove(options.release)
            return (res, '')
        res = biomaj_remove_request(options)
    if not res:
        return (False, 'Failed to send removal request')
    return (True, 'Bank removal request sent')
예제 #8
0
 def test_extract_release_from_file_content(self):
     b = Bank("local")
     b.load_session(UpdateWorkflow.FLOW)
     b.session.config.set("release.file", "test_100\.txt")
     b.session.config.set("release.regexp", "Release\s*(\d+)")
     w = UpdateWorkflow(b)
     w.wf_release()
     self.assertTrue(b.session.get("release") == "103")
예제 #9
0
 def test_new_session(self):
     """
 Checks an empty session is created
 """
     b = Bank("alu")
     b.load_session(UpdateWorkflow.FLOW)
     for key in b.session._session["status"].keys():
         self.assertFalse(b.session.get_status(key))
예제 #10
0
 def test_extract_release_from_file_content(self):
     b = Bank('local')
     b.load_session(UpdateWorkflow.FLOW)
     b.session.config.set('release.file', 'test_100\.txt')
     b.session.config.set('release.regexp', 'Release\s*(\d+)')
     w = UpdateWorkflow(b)
     w.wf_release()
     self.assertTrue(b.session.get('release') == '103')
예제 #11
0
def bank_status(request):
  bank = Bank(request.matchdict['id'], no_log=True)
  if not can_read_bank(request, bank.bank):
    return HTTPForbidden('Not authorized to access this resource')

  if 'status' not in bank.bank:
    return HTTPNotFound('no current status')
  return bank.get_status()
예제 #12
0
 def test_new_session(self):
   '''
   Checks an empty session is created
   '''
   b = Bank('alu')
   b.load_session(UpdateWorkflow.FLOW)
   for key in b.session._session['status'].keys():
     self.assertFalse(b.session.get_status(key))
예제 #13
0
 def test_new_session(self):
     '''
 Checks an empty session is created
 '''
     b = Bank('alu')
     b.load_session(UpdateWorkflow.FLOW)
     for key in b.session._session['status'].keys():
         self.assertFalse(b.session.get_status(key))
예제 #14
0
 def test_computed_nofile(self):
   b = Bank('computed2')
   b.load_session(UpdateWorkflow.FLOW)
   b.session.config.set('protocol', 'none')
   b.session.config.set('sub1.files.move', 'flat/test_.*')
   res = b.update(True)
   self.assertTrue(res)
   self.assertTrue(os.path.exists(b.session.get_full_release_directory()+'/sub1/flat/test_100.txt'))
예제 #15
0
 def test_computed_ref_release(self):
   b = Bank('computed2')
   res = b.update(True)
   b2 = Bank('sub1')
   b2release = b2.bank['production'][len(b2.bank['production'])-1]['release']
   brelease = b.bank['production'][len(b.bank['production'])-1]['release']
   self.assertTrue(res)
   self.assertTrue(brelease == b2release)
예제 #16
0
 def test_computed_ref_release(self):
     b = Bank("computed2")
     res = b.update(True)
     b2 = Bank("sub1")
     b2release = b2.bank["production"][len(b2.bank["production"]) - 1]["release"]
     brelease = b.bank["production"][len(b.bank["production"]) - 1]["release"]
     self.assertTrue(res)
     self.assertTrue(brelease == b2release)
예제 #17
0
 def test_extract_release_from_file_content(self):
   b = Bank('local')
   b.load_session(UpdateWorkflow.FLOW)
   b.session.config.set('release.file', 'test_100\.txt')
   b.session.config.set('release.regexp', 'Release\s*(\d+)')
   w = UpdateWorkflow(b)
   w.wf_release()
   self.assertTrue(b.session.get('release') == '103')
예제 #18
0
 def test_remoterelease_check(self):
     b = Bank('local')
     b.load_session(ReleaseCheckWorkflow.FLOW)
     b.session.config.set('release.file', 'test_(\d+)\.txt')
     b.session.config.set('release.regexp', '')
     workflow = ReleaseCheckWorkflow(b)
     res = workflow.start()
     remoterelease = b.session.get('remoterelease')
     self.assertTrue(remoterelease == '100')
예제 #19
0
 def test_stats(self):
     b = Bank("local")
     b.update()
     rel = b.session.get("release")
     stats = Bank.get_banks_disk_usage()
     self.assertTrue(stats[0]["size"] > 0)
     for release in stats[0]["releases"]:
         if release["name"] == rel:
             self.assertTrue(release["size"] > 0)
예제 #20
0
 def test_stats(self):
     b = Bank('local')
     b.update()
     rel = b.session.get('release')
     stats = Bank.get_banks_disk_usage()
     self.assertTrue(stats[0]['size'] > 0)
     for release in stats[0]['releases']:
         if release['name'] == rel:
             self.assertTrue(release['size'] > 0)
예제 #21
0
 def test_remoterelease_check(self):
     b = Bank('local')
     b.load_session(ReleaseCheckWorkflow.FLOW)
     b.session.config.set('release.file', 'test_(\d+)\.txt')
     b.session.config.set('release.regexp', '')
     workflow = ReleaseCheckWorkflow(b)
     res = workflow.start()
     remoterelease = b.session.get('remoterelease')
     self.assertTrue(remoterelease == '100')
예제 #22
0
def biomaj_owner(options):
    '''
    Bank ownership management
    '''
    if not options.bank:
        return (False, "Bank option is missing")
    bank = Bank(options.bank, options=options, no_log=True)
    bank.set_owner(options.owner)
    return (True, None)
예제 #23
0
 def test_stats(self):
   b = Bank('local')
   b.update()
   rel = b.session.get('release')
   stats = Bank.get_banks_disk_usage()
   self.assertTrue(stats[0]['size']>0)
   for release in stats[0]['releases']:
     if release['name'] == rel:
       self.assertTrue(release['size']>0)
예제 #24
0
def bank_locked(request):
  bank = Bank(request.matchdict['id'], no_log=True)
  if not can_read_bank(request, bank.bank):
    return HTTPForbidden('Not authorized to access this resource')

  if bank.is_locked():
    return {'status': 1}
  else:
    return {'status': 0}
예제 #25
0
def biomaj_check(options):
    '''
    Check bank properties
    '''
    if not options.bank:
        return (False, "Bank name is missing")

    bank = Bank(options.bank, options=options, no_log=True)
    msg = options.bank + " check: " + str(bank.check()) + "\n"
    return (True, msg)
예제 #26
0
 def test_computed(self):
   b = Bank('computed')
   res = b.update(True)
   self.assertTrue(res)
   self.assertTrue(os.path.exists(b.session.get_full_release_directory()+'/sub1/flat/test_100.txt'))
   self.assertTrue(b.session.get('update'))
   # Check that, with depends non updated, bank is not updated itself
   nextb = Bank('computed')
   res = nextb.update(True)
   self.assertFalse(nextb.session.get('update'))
예제 #27
0
 def test_reupdate_from_task_wrong_release(self):
   b = Bank('local')
   b.options.stop_after = 'download'
   b.update()
   self.assertFalse(b.session.get_status('postprocess'))
   b2 = Bank('local')
   b2.options.from_task = 'postprocess'
   b2.options.release = 'wrongrelease'
   res = b2.update()
   self.assertFalse(res)
예제 #28
0
 def test_reupdate_from_task_error(self):
   b = Bank('local')
   b.options.stop_after = 'check'
   b.update()
   self.assertFalse(b.session.get_status('postprocess'))
   b2 = Bank('local')
   b2.options.from_task = 'postprocess'
   b2.options.release = b.session.get('release')
   res = b2.update()
   self.assertFalse(res)
예제 #29
0
 def test_get_release(self):
     '''
 Get release
 '''
     b = Bank('alu')
     b.load_session(UpdateWorkflow.FLOW)
     res = b.update()
     self.assertTrue(b.session.get('update'))
     self.assertTrue(res)
     self.assertTrue(b.session._session['release'] is not None)
예제 #30
0
 def test_no_update(self):
     '''
     Try updating twice, at second time, bank should not be updated
     '''
     b = Bank('local')
     b.update()
     self.assertTrue(b.session.get('update'))
     b.update()
     self.assertFalse(b.session.get('update'))
     self.assertFalse(b.session.get_status(Workflow.FLOW_POSTPROCESS))
예제 #31
0
 def test_reupdate_from_task_wrong_release(self):
     b = Bank("local")
     b.options.stop_after = "download"
     b.update()
     self.assertFalse(b.session.get_status("postprocess"))
     b2 = Bank("local")
     b2.options.from_task = "postprocess"
     b2.options.release = "wrongrelease"
     res = b2.update()
     self.assertFalse(res)
예제 #32
0
 def test_get_release(self):
   '''
   Get release
   '''
   b = Bank('alu')
   b.load_session(UpdateWorkflow.FLOW)
   res = b.update()
   self.assertTrue(b.session.get('update'))
   self.assertTrue(res)
   self.assertTrue(b.session._session['release'] is not None)
예제 #33
0
 def test_no_update(self):
     """
   Try updating twice, at second time, bank should not be updated
   """
     b = Bank("local")
     b.update()
     self.assertTrue(b.session.get("update"))
     b.update()
     self.assertFalse(b.session.get("update"))
     self.assertFalse(b.session.get_status(Workflow.FLOW_POSTPROCESS))
예제 #34
0
 def test_computed_ref_release(self):
     b = Bank('computed2')
     res = b.update(True)
     b2 = Bank('sub1')
     b2release = b2.bank['production'][len(b2.bank['production']) -
                                       1]['release']
     brelease = b.bank['production'][len(b.bank['production']) -
                                     1]['release']
     self.assertTrue(res)
     self.assertTrue(brelease == b2release)
예제 #35
0
 def test_computed_nofile(self):
     b = Bank('computed2')
     b.load_session(UpdateWorkflow.FLOW)
     b.session.config.set('protocol', 'none')
     b.session.config.set('sub1.files.move', 'flat/test_.*')
     res = b.update(True)
     self.assertTrue(res)
     self.assertTrue(
         os.path.exists(b.session.get_full_release_directory() +
                        '/sub1/flat/test_100.txt'))
예제 #36
0
 def test_get_release(self):
     """
 Get release
 """
     b = Bank("alu")
     b.load_session(UpdateWorkflow.FLOW)
     res = b.update()
     self.assertTrue(b.session.get("update"))
     self.assertTrue(res)
     self.assertTrue(b.session._session["release"] is not None)
예제 #37
0
 def test_reupdate_from_task_error(self):
     b = Bank("local")
     b.options.stop_after = "check"
     b.update()
     self.assertFalse(b.session.get_status("postprocess"))
     b2 = Bank("local")
     b2.options.from_task = "postprocess"
     b2.options.release = b.session.get("release")
     res = b2.update()
     self.assertFalse(res)
예제 #38
0
 def test_postprocesses_restart_from_proc(self):
   b = Bank('localprocess')
   b.update()
   proc1file = os.path.join(b.session.get_full_release_directory(),'proc1.txt')
   proc2file = os.path.join(b.session.get_full_release_directory(),'proc2.txt')
   self.assertTrue(os.path.exists(proc1file))
   self.assertTrue(os.path.exists(proc2file))
   os.remove(proc1file)
   os.remove(proc2file)
   # Restart from postprocess, reexecute all processes
   b2 = Bank('localprocess')
   b2.options.from_task = 'postprocess'
   b2.options.release = b.session.get('release')
   b2.update()
   self.assertTrue(os.path.exists(proc1file))
   self.assertTrue(os.path.exists(proc2file))
   os.remove(proc1file)
   os.remove(proc2file)
   # Restart from postprocess, but at process PROC2 and following
   b3 = Bank('localprocess')
   b3.options.from_task = 'postprocess'
   b3.options.process = 'PROC2'
   b3.options.release = b.session.get('release')
   b3.update()
   #self.assertFalse(os.path.exists(proc1file))
   self.assertTrue(os.path.exists(proc2file))
예제 #39
0
    def execute(self, options):
        '''
        List remote content
        '''
        start_time = datetime.datetime.now()
        start_time = time.mktime(start_time.timetuple())

        error = None
        try:
            options.no_log = False
            if options.update:
                bmaj = Bank(options.bank, options)
                self.logger.debug('Log file: ' + bmaj.config.log_file)
                error = bmaj.update(depends=True)
                Notify.notifyBankAction(bmaj)
            elif options.remove or options.removeall:
                if options.removeall:
                    bmaj = Bank(options.bank, options, no_log=True)
                    print('Log file: ' + bmaj.config.log_file)
                    error = bmaj.removeAll(options.force)
                else:
                    bmaj = Bank(options.bank, options)
                    self.logger.debug('Log file: ' + bmaj.config.log_file)
                    error = bmaj.remove(options.release)
                    Notify.notifyBankAction(bmaj)
        except Exception as e:
            self.logger.exception('Exception: ' + str(e))
            error = True

        end_time = datetime.datetime.now()
        end_time = time.mktime(end_time.timetuple())

        execution_time = end_time - start_time
        return {'error': error, 'execution_time': execution_time}
예제 #40
0
def biomaj_status(options):
    '''
    Get bank status information
    '''
    msg = ''
    if options.bank:
        bank = Bank(options.bank, options=options, no_log=True)
        if bank.bank['properties']['visibility'] != 'public' and not bank.is_owner():
            return (False, 'Access forbidden')
        info = bank.get_bank_release_info(full=True)
        msg += tabulate(info['info'], headers='firstrow', tablefmt='psql') + '\n'
        msg += tabulate(info['prod'], headers='firstrow', tablefmt='psql') + '\n'
        # do we have some pending release(s)
        if 'pend' in info and len(info['pend']) > 1:
            msg += tabulate(info['pend'], headers='firstrow', tablefmt='psql') + '\n'
    else:
        banks = Bank.list()
        # Headers of output table
        banks_list = [["Name", "Type(s)", "Release", "Visibility", "Last update"]]
        for bank in sorted(banks, key=lambda k: k['name']):
            bank = Bank(bank['name'], options=options, no_log=True)
            if bank.bank['properties']['visibility'] == 'public' or bank.is_owner():
                banks_list.append(bank.get_bank_release_info()['info'])
        msg += tabulate(banks_list, headers="firstrow", tablefmt="psql") + '\n'
    return (True, msg)
예제 #41
0
 def test_multi(self):
   b = Bank('multi')
   res = b.update()
   with open(os.path.join(b.session.get_full_release_directory(),'flat/test1.json'), 'r') as content_file:
     content = content_file.read()
     my_json = json.loads(content)
     self.assertTrue(my_json['args']['key1'] == 'value1')
   with open(os.path.join(b.session.get_full_release_directory(),'flat/test2.json'), 'r') as content_file:
     content = content_file.read()
     my_json = json.loads(content)
     self.assertTrue(my_json['form']['key1'] == 'value1')
예제 #42
0
 def test_multi(self):
     b = Bank("multi")
     res = b.update()
     with open(os.path.join(b.session.get_full_release_directory(), "flat/test1.json"), "r") as content_file:
         content = content_file.read()
         my_json = json.loads(content)
         self.assertTrue(my_json["args"]["key1"] == "value1")
     with open(os.path.join(b.session.get_full_release_directory(), "flat/test2.json"), "r") as content_file:
         content = content_file.read()
         my_json = json.loads(content)
         self.assertTrue(my_json["form"]["key1"] == "value1")
예제 #43
0
 def test_publish(self):
     """
 Update a bank, then publish it
 """
     b = Bank("local")
     b.update()
     current_link = os.path.join(b.config.get("data.dir"), b.config.get("dir.version"), "current")
     self.assertFalse(os.path.exists(current_link))
     self.assertTrue(b.bank["current"] is None)
     b.publish()
     self.assertTrue(os.path.exists(current_link))
     self.assertTrue(b.bank["current"] == b.session._session["id"])
예제 #44
0
 def test_fromscratch_update(self):
     """
   Try updating twice, at second time, bank should  be updated (force with fromscratc)
   """
     b = Bank("local")
     b.update()
     self.assertTrue(b.session.get("update"))
     sess = b.session.get("release")
     b.options.fromscratch = True
     b.update()
     self.assertTrue(b.session.get("update"))
     self.assertEqual(b.session.get("release"), sess + "__1")
예제 #45
0
def biomaj_daemon_bank_isowner(bank):
    '''
    Checks that logged user is admin or owner of the bank
    '''
    (http_code, options, error) = daemon_api_auth(request)
    if error:
        abort(http_code, error)
    bank_log = Bank(bank, options=options, no_log=True)
    if bank_log.is_owner():
        return jsonify({'is_admin_or_owner': True})
    else:
        return jsonify({'is_admin_or_owner': False})
예제 #46
0
def biomaj_visibility(options):
    '''
    Bank visibility management
    '''
    if not options.bank:
        return (False, "Bank option is missing")
    if options.visibility not in ['public', 'private']:
        return (False, "Valid values are public|private")

    bank = Bank(options.bank, options=options, no_log=True)
    bank.set_visibility(options.visibility)
    return (True, "Do not forget to update accordingly the visibility.default parameter in the configuration file")
예제 #47
0
 def test_fromscratch_update(self):
     '''
     Try updating twice, at second time, bank should  be updated (force with fromscratc)
     '''
     b = Bank('local')
     b.update()
     self.assertTrue(b.session.get('update'))
     sess = b.session.get('release')
     b.options.fromscratch = True
     b.update()
     self.assertTrue(b.session.get('update'))
     self.assertEqual(b.session.get('release'), sess+'__1')
예제 #48
0
def biomaj_show(options, config):
    '''
    show bank details
    '''
    if not options.bank:
        return (False, "Bank option is required")

    bank = Bank(options.bank, options=options, no_log=True)
    results = []
    headers = ["Name", "Release", "Format(s)", "Type(s)", "Tag(s)", "File(s)"]
    if not options.json:
        results.append(headers)
    current = None
    fformat = None
    if 'current' in bank.bank and bank.bank['current']:
        current = bank.bank['current']
    for prod in bank.bank['production']:
        include = True
        release = prod['release']
        if current == prod['session']:
            release += ' (current)'
        if options.release and (prod['release'] != options.release
                                and prod['prod_dir'] != options.release):
            include = False
        if include:
            session = bank.get_session_from_release(prod['release'])
            formats = session['formats']
            afiles = []
            atags = []
            atypes = []
            for fformat in list(formats.keys()):
                for elt in formats[fformat]:
                    if options.json:
                        atypes.append(elt['types'])
                    else:
                        atypes.append(','.join(elt['types']))
                    for tag in list(elt['tags'].keys()):
                        atags.append(elt['tags'][tag])
                    for eltfile in elt['files']:
                        afiles.append(eltfile)
            if options.json:
                results.append([
                    bank.bank['name'], release, fformat, atypes, atags, afiles
                ])
                msg = {'details': results, 'headers': headers}
            else:
                results.append([
                    bank.bank['name'], release, fformat, ','.join(atypes),
                    ','.join(atags), ','.join(afiles)
                ])
                msg = tabulate(results, headers="firstrow", tablefmt="grid")
    return (True, msg)
예제 #49
0
 def test_postprocess_wrong_process_name(self):
   """If a wrong process name is given, update returns False and prints an error message"""
   b = Bank('local')
   b.options.stop_after = 'download'
   b.update()
   self.assertFalse(b.session.get_status('postprocess'))
   b2 = Bank('local')
   b2.options.from_task = 'postprocess'
   b2.options.release = b.session.get('release')
   b2.options.process = 'fake'
   self.assertFalse(b2.update())
   self.assertFalse(b2.session.get_status('postprocess'))
   self.assertEqual(b.session.get_full_release_directory(), b2.session.get_full_release_directory())
예제 #50
0
def biomaj_freeze(options):
    '''
    freeze a bank
    '''
    if not options.bank:
        return (False, "Bank name is missing")
    if not options.release:
        return (False, "Bank release is missing")
    bmaj = Bank(options.bank, options=options)
    res = bmaj.freeze(options.release)
    if not res:
        return (False, 'Failed to freeze the bank release')
    return (True, None)
예제 #51
0
 def test_mix_stop_from_task4(self):
     '''
   Get a first release, then fromscratch --stop-after, then restart from-task
   '''
     b = Bank('local')
     b.update()
     rel = b.session.get('release')
     b2 = Bank('local')
     b2.options.stop_before = 'download'
     b2.options.fromscratch = True
     res = b2.update()
     b3 = Bank('local')
     b3.options.from_task = 'postprocess'
     res = b3.update()
     self.assertFalse(res)
예제 #52
0
 def test_multi(self):
     b = Bank('multi')
     res = b.update()
     with open(
             os.path.join(b.session.get_full_release_directory(),
                          'flat/test1.json'), 'r') as content_file:
         content = content_file.read()
         my_json = json.loads(content)
         self.assertTrue(my_json['args']['key1'] == 'value1')
     with open(
             os.path.join(b.session.get_full_release_directory(),
                          'flat/test2.json'), 'r') as content_file:
         content = content_file.read()
         my_json = json.loads(content)
         self.assertTrue(my_json['form']['key1'] == 'value1')
예제 #53
0
 def test_mix_stop_from_task(self):
     '''
   Get a first release, then fromscratch --stop-after, then restart from-task
   '''
     b = Bank('local')
     b.update()
     rel = b.session.get('release')
     b2 = Bank('local')
     b2.options.stop_after = 'download'
     b2.options.fromscratch = True
     res = b2.update()
     self.assertTrue(b2.session.get('release') == rel + '__1')
     b3 = Bank('local')
     res = b3.update()
     self.assertTrue(b3.session.get('release') == rel + '__1')
     self.assertTrue(res)
예제 #54
0
 def test_download_from_list(self):
     """
   Use remote.list to define a list of files to download
   """
     b = Bank('local')
     fd, file_path = tempfile.mkstemp()
     try:
         b.config.set('remote.list', file_path)
         with os.fdopen(fd, 'w') as tmp:
             tmp.write('[{"name": "test_100.txt", "root": "' +
                       b.config.get('remote.dir') + '"}]')
         b.update()
         self.assertTrue(b.session.get('update'))
     finally:
         #os.remove(file_path)
         print(file_path)
예제 #55
0
def biomaj_remove_pending(options):
    '''
    Remove pending releases
    '''
    if not options.bank:
        return (False, "Bank name is missing")
    bmaj = Bank(options.bank, options=options, no_log=True)
    if bmaj.is_locked():
        return (False, 'Bank is locked due to an other action')
    if not options.proxy:
        res = bmaj.remove_pending(options.release)
        return (res, '')
    res = biomaj_remove_pending_request(options)
    if not res:
        return (False, 'Failed to send removal request')
    return (True, 'Request sent')
예제 #56
0
def biomaj_bank_log_tail(bank, tail=100):
    apikey = request.headers.get('Authorization')
    token = None

    if apikey:
        bearer = apikey.split()
        if bearer[0] == 'APIKEY':
            token = bearer[1]
    log_file = None
    try:
        user = None
        options_object = Options(OPTIONS_PARAMS)
        if token:
            proxy = Utils.get_service_endpoint(config, 'user')
            r = requests.get(proxy + '/api/user/info/apikey/' + token)
            if not r.status_code == 200:
                abort(404, {'message': 'Invalid API Key or connection issue'})
            user = r.json()['user']
            options_object = Options({'user': user['id']})

        bank_log = Bank(bank, options=options_object, no_log=True)
        if bank_log.bank['properties'][
                'visibility'] != 'public' and not bank_log.is_owner():
            abort(403, {'message': 'not authorized to access this bank'})
        if 'status' not in bank_log.bank or 'log_file' not in bank_log.bank[
                'status'] or not bank_log.bank['status']['log_file']['status']:
            return "No log file available"
        log_file = bank_log.bank['status']['log_file']['status']
    except Exception as e:
        logging.exception(e)
        return "Failed to access log file: " + str(e)
    if not log_file or not os.path.exists(log_file):
        return "Cannot access log file %s" % (str(log_file))

    def generate():
        with open(log_file) as fp:
            tail_l = int(tail)
            if tail_l == 0:
                for line in fp:
                    yield line
            else:
                dq = deque(fp, maxlen=tail_l)
                for line in dq:
                    yield line
        yield "##END_OF_LOG"

    return Response(generate(), mimetype='text/plain')
예제 #57
0
 def test_removeAll(self):
     b = Bank('local')
     b.update()
     b.removeAll()
     self.assertFalse(os.path.exists(b.get_data_dir()))
     bdb = b.banks.find_one({'name': b.name})
     self.assertTrue(bdb is None)
예제 #58
0
    def test_session_reload_notover(self):
        '''
    Checks a session is used if present
    '''
        b = Bank('alu')
        for i in range(1, 5):
            s = Session('alu', self.config, UpdateWorkflow.FLOW)
            s._session['status'][Workflow.FLOW_INIT] = True
            b.session = s
            b.save_session()

        b = Bank('alu')
        b.load_session(UpdateWorkflow.FLOW)
        self.assertTrue(b.session.get_status(Workflow.FLOW_INIT))
예제 #59
0
def biomaj_move_production_directories(options):
    '''
    Change bank production directories
    '''
    if not options.bank:
        return (False, "Bank option is missing")

    if not os.path.exists(options.newdir):
        return (False, "Destination directory does not exists")

    bank = Bank(options.bank, options=options, no_log=True)
    if not bank.bank['production']:
        return (False, "Nothing to move, no production directory")

    bank.load_session(Workflow.FLOW, None)
    w = Workflow(bank)
    res = w.wf_init()
    if not res:
        return (False, 'Bank initialization failure')

    for prod in bank.bank['production']:
        session = bank.get_session_from_release(prod['release'])
        bank.load_session(Workflow.FLOW, session)
        prod_path = bank.session.get_full_release_directory()
        if os.path.exists(prod_path):
            shutil.move(prod_path, options.newdir)
        prod['data_dir'] = options.newdir
    bank.banks.update({'name': options.bank}, {'$set': {'production': bank.bank['production']}})
    w.wf_over()
    return (True, "Bank production directories moved to " + options.newdir + "\nWARNING: do not forget to update accordingly the data.dir and dir.version properties")
예제 #60
0
 def test_search(self):
     b = Bank('localprocess')
     b.update()
     search_res = Bank.search(['blast'], [])
     self.assertTrue(len(search_res) == 1)
     search_res = Bank.search([], ['nucleic'])
     self.assertTrue(len(search_res) == 1)
     search_res = Bank.search(['blast'], ['nucleic'])
     self.assertTrue(len(search_res) == 1)
     search_res = Bank.search(['blast'], ['proteic'])
     self.assertTrue(len(search_res) == 0)