Given one format, one block id and, optionally, one moduleid, return the corresponding backup_xxx_block_task()
888
public static function get_backup_block_task($format, $blockid, $moduleid = null) {
        global $CFG, $DB;

        // Check blockid exists
        if (!$block = $DB->get_record('block_instances', array('id' => $blockid))) {
            throw new backup_task_exception('block_task_block_instance_not_found', $blockid);
        }

        // Set default block backup task
        $classname = 'backup_default_block_task';
        $testname  = 'backup_' . $block->blockname . '_block_task';
        // If the block has custom backup/restore task class (testname), use it
        if (class_exists($testname)) {
            $classname = $testname;
        }
        return new $classname($block->blockname, $blockid, $moduleid);
    }
519787
def get(self, block_alias, context):
        """"""
        contents = []

        dynamic_block_contents = self.get_contents_dynamic(block_alias, context)
        if dynamic_block_contents:
            contents.append(dynamic_block_contents)

        static_block_contents = self.get_contents_static(block_alias, context)
        if static_block_contents:
            contents.append(static_block_contents)

        if not contents:
            return ''

        return choice(contents)
77617
def getBufferedFiles(self, block_id):
        
            
        try:
            conn = self.dbi.connection()
            result = self.buflist.execute(conn, block_id)
            return result
        finally:
            if conn:
                conn.close()
293393
def get_lastblock(cls, impl, working_dir):
        
        if not cls.db_exists(impl, working_dir):
            return None

        con = cls.db_open(impl, working_dir)
        query = 'SELECT MAX(block_id) FROM snapshots;'
        
        rows = cls.db_query_execute(con, query, (), verbose=False)
        ret = None
        for r in rows:
            ret = r['MAX(block_id)']

        con.close()
        return ret
1353337
def get_backup_paths(cls, block_id, impl, working_dir):
        
        backup_dir = config.get_backups_directory(impl, working_dir)
        backup_paths = []
        for p in cls.get_state_paths(impl, working_dir):
            pbase = os.path.basename(p)
            backup_path = os.path.join( backup_dir, pbase + (".bak.%s" % block_id))
            backup_paths.append( backup_path )

        return backup_paths
280481
def _expand_block(cls, block):
        
        cls._parse_header(BlockHeader, block)
        if 'batches' in block:
            block['batches'] = [cls._expand_batch(b) for b in block['batches']]
        return block
1327795
def get(self, block_id):
        

        pool = current_app.config['bigchain_pool']

        with pool() as bigchain:
            block = bigchain.get_block(block_id=block_id)

        if not block:
            return make_error(404)

        return block
1050871
def get_scheduling_block(sub_array_id, block_id):
    """"""
    block_ids = DB.get_sub_array_sbi_ids(sub_array_id)
    if block_id in block_ids:
        block = DB.get_block_details([block_id]).__next__()
        return block, HTTPStatus.OK

    return dict(error="unknown id"), HTTPStatus.NOT_FOUND
753598
def generate_scheduling_block_id(num_blocks, project='test'):
    """"""
    _date = strftime("%Y%m%d", gmtime())
    _project = project
    for i in range(num_blocks):
        yield '{}-{}-sbi{:03d}'.format(_date, _project, i)
345741
def get_block(self, config_only=False):
        """"""

        mib = TBBlock()

        for cid, config in self.configs.items():
            mib.add_config(cid, config)

        if not config_only:
            for key, val in self.commands.items():
                mib.add_command(key, val)

            if not self.valid:
                self._validate_information()

            mib.set_api_version(*self.variables["APIVersion"])
            mib.set_module_version(*self.variables["ModuleVersion"])
            mib.set_name(self.variables["ModuleName"])

        return mib
488200
public function getBlock(Tree $tree, int $block_id, string $ctype = '', array $cfg = []): string
    {
        $show_other      = $this->getBlockSetting($block_id, 'show_other', self::DEFAULT_SHOW_OTHER);
        $show_unassigned = $this->getBlockSetting($block_id, 'show_unassigned', self::DEFAULT_SHOW_UNASSIGNED);
        $show_future     = $this->getBlockSetting($block_id, 'show_future', self::DEFAULT_SHOW_FUTURE);

        extract($cfg, EXTR_OVERWRITE);

        $end_jd      = $show_future ? Carbon::maxValue()->julianDay() : Carbon::now()->julianDay();
        $individuals = $this->individualsWithTasks($tree, $end_jd);
        $families    = $this->familiesWithTasks($tree, $end_jd);

        /** @var GedcomRecord[] $records */
        $records = $individuals->merge($families);

        $tasks = [];

        foreach ($records as $record) {
            foreach ($record->facts(['_TODO']) as $task) {
                $user_name = $task->attribute('_WT_USER');

                if ($user_name === Auth::user()->userName() || empty($user_name) && $show_unassigned || !empty($user_name) && $show_other) {
                    $tasks[] = $task;
                }
            }
        }

        if (empty($records)) {
            $content = '<p>' . I18N::translate('There are no research tasks in this family tree.') . '</p>';
        } else {
            $content = view('modules/todo/research-tasks', ['tasks' => $tasks]);
        }

        if ($ctype !== '') {
            if ($ctype === 'gedcom' && Auth::isManager($tree)) {
                $config_url = route('tree-page-block-edit', [
                    'block_id' => $block_id,
                    'ged'      => $tree->name(),
                ]);
            } elseif ($ctype === 'user' && Auth::check()) {
                $config_url = route('user-page-block-edit', [
                    'block_id' => $block_id,
                    'ged'      => $tree->name(),
                ]);
            } else {
                $config_url = '';
            }

            return view('modules/block-template', [
                'block'      => Str::kebab($this->name()),
                'id'         => $block_id,
                'config_url' => $config_url,
                'title'      => $this->title(),
                'content'    => $content,
            ]);
        }

        return $content;
    }
412333
def build_block(self):
        
        header_bytes = self.block_header.SerializeToString()
        block = Block(header=header_bytes,
                      header_signature=self._header_signature)
        block.batches.extend(self.batches)
        return block
1075034
def get_valid_consensus_hashes( self, block_id ):
        
        first_block_to_check = block_id - self.impl.get_valid_transaction_window()

        query = 'SELECT consensus_hash FROM snapshots WHERE block_id >= ? AND block_id <= ?;'
        args = (first_block_to_check,block_id)

        valid_consensus_hashes = []
        
        con = self.db_open(self.impl, self.working_dir)
        rows = self.db_query_execute(con, query, args, verbose=False)

        for r in rows:
            assert r['consensus_hash'] is not None
            assert isinstance(r['consensus_hash'], (str,unicode))

            valid_consensus_hashes.append(str(r['consensus_hash']))

        con.close()
        return valid_consensus_hashes
238965
static void getNumDataBytesAndNumECBytesForBlockID(int numTotalBytes,
                                                     int numDataBytes,
                                                     int numRSBlocks,
                                                     int blockID,
                                                     int[] numDataBytesInBlock,
                                                     int[] numECBytesInBlock) throws WriterException {
    if (blockID >= numRSBlocks) {
      throw new WriterException("Block ID too large");
    }
    // numRsBlocksInGroup2 = 196 % 5 = 1
    int numRsBlocksInGroup2 = numTotalBytes % numRSBlocks;
    // numRsBlocksInGroup1 = 5 - 1 = 4
    int numRsBlocksInGroup1 = numRSBlocks - numRsBlocksInGroup2;
    // numTotalBytesInGroup1 = 196 / 5 = 39
    int numTotalBytesInGroup1 = numTotalBytes / numRSBlocks;
    // numTotalBytesInGroup2 = 39 + 1 = 40
    int numTotalBytesInGroup2 = numTotalBytesInGroup1 + 1;
    // numDataBytesInGroup1 = 66 / 5 = 13
    int numDataBytesInGroup1 = numDataBytes / numRSBlocks;
    // numDataBytesInGroup2 = 13 + 1 = 14
    int numDataBytesInGroup2 = numDataBytesInGroup1 + 1;
    // numEcBytesInGroup1 = 39 - 13 = 26
    int numEcBytesInGroup1 = numTotalBytesInGroup1 - numDataBytesInGroup1;
    // numEcBytesInGroup2 = 40 - 14 = 26
    int numEcBytesInGroup2 = numTotalBytesInGroup2 - numDataBytesInGroup2;
    // Sanity checks.
    // 26 = 26
    if (numEcBytesInGroup1 != numEcBytesInGroup2) {
      throw new WriterException("EC bytes mismatch");
    }
    // 5 = 4 + 1.
    if (numRSBlocks != numRsBlocksInGroup1 + numRsBlocksInGroup2) {
      throw new WriterException("RS blocks mismatch");
    }
    // 196 = (13 + 26) * 4 + (14 + 26) * 1
    if (numTotalBytes !=
        ((numDataBytesInGroup1 + numEcBytesInGroup1) *
            numRsBlocksInGroup1) +
            ((numDataBytesInGroup2 + numEcBytesInGroup2) *
                numRsBlocksInGroup2)) {
      throw new WriterException("Total bytes mismatch");
    }

    if (blockID < numRsBlocksInGroup1) {
      numDataBytesInBlock[0] = numDataBytesInGroup1;
      numECBytesInBlock[0] = numEcBytesInGroup1;
    } else {
      numDataBytesInBlock[0] = numDataBytesInGroup2;
      numECBytesInBlock[0] = numEcBytesInGroup2;
    }
  }
920501
private int getBlockInfo(String[] argv, int i) throws IOException {
  	long blockId = Long.valueOf(argv[i++]);
  	LocatedBlockWithFileName locatedBlock = 
  			getDFS().getClient().getBlockInfo(blockId);
  
  	if (null == locatedBlock) {
  		System.err.println("Could not find the block with id : " + blockId);
  		return -1;
  	}
  	
  	StringBuilder sb = new StringBuilder();
  	sb.append("block: ")
  				.append(locatedBlock.getBlock()).append("\n")
  				.append("filename: ")
  				.append(locatedBlock.getFileName()).append("\n")
  				.append("locations: ");
  	
  	DatanodeInfo[] locs = locatedBlock.getLocations();
  	for (int k=0; k<locs.length; k++) {
  		if (k > 0) {
  			sb.append(" , ");
  		}
  		sb.append(locs[k].getHostName());
  	}
  				
  	System.out.println(sb.toString());  	
  	return 0;
  }
1014357
def dumpBlock(self, block_name):
        
        if '%' in block_name or '*' in block_name:
            msg = "No wildcard is allowed in block_name for dumpBlock API"
            dbsExceptionHandler('dbsException-invalid-input', msg, self.logger.exception)

        conn = self.dbi.connection()
        try :
            #block name is unique
            block1 = self.blocklist.execute(conn, block_name=block_name)
            block = []
            for b1 in block1:
		if not b1:
		    return {}
		else:
		    block = b1
            #a block only has one dataset and one primary dataset
            #in order to reduce the number of dao objects, we will not write
            #a special migration one. However, we will have to remove the
            #extras
            #block1 is a generator. When it is empty, it will skip the for loop above. why? 
            #we cannot test on b1 to decide if the generator is empty or not.
            #so have to do below:
            if not block: return {}
            dataset1 = self.datasetlist.execute(conn,
                      dataset=block["dataset"], dataset_access_type="")
	    dataset = []
            for d in dataset1:
		if d:
		    dataset = d
		    dconfig_list = self.outputCoflist.execute(conn, dataset=dataset['dataset'])
                else: return {}
            #get block parentage
            bparent = self.blockparentlist.execute(conn, block['block_name'])
            #get dataset parentage
            dsparent = self.dsparentlist.execute(conn, dataset['dataset'])
            for p in dsparent:
                del p['parent_dataset_id']
                if 'dataset'in p:
                    del p['dataset']
                elif 'this_dataset' in p:
                    del p['this_dataset']
                else:
                    pass

            fparent_list = self.fplist.execute(conn,
                                               block_id=block['block_id'])
	    fparent_list2 = [] 	
	    for fp in fparent_list:
		fparent_list2.append(fp)	
	    #print "---YG file Parent List--"
	    #print fparent_list2	
            fconfig_list = self.outputCoflist.execute(conn,
                                                block_id=block['block_id'])
            acqEra = {}
            prsEra = {}
            if dataset["acquisition_era_name"] not in ( "", None):
                acqEra = self.aelist.execute(conn,
                        acquisitionEra=dataset["acquisition_era_name"])[0]
            if dataset["processing_version"] not in ("", None):
                prsEra = self.pelist.execute(conn,
                        processingV=dataset["processing_version"])[0]
            primds = self.primdslist.execute(conn,
                        primary_ds_name=dataset["primary_ds_name"])[0]
            del dataset["primary_ds_name"], dataset['primary_ds_type']
            files = self.filelist.execute(conn, block_name=block_name)
            for f in files:
                #There are a trade off between json sorting and db query.
                #We keep lumi sec in a file, but the file parentage seperate
                #from file
		file_lumi_list = []
                for item in self.fllist.execute(conn, logical_file_name=f['logical_file_name'], migration=True):
		    file_lumi_list.append(item)
		#print "---YG file lumi list---"	
		f.update(file_lumi_list = file_lumi_list)
		del file_lumi_list #YG 09/2015
                del f['branch_hash_id']
            del dataset["acquisition_era_name"], dataset["processing_version"]
            del block["dataset"]
            result = dict(block=block, dataset=dataset, primds=primds,
                          files=files, block_parent_list=bparent,
                          ds_parent_list=dsparent, file_conf_list=fconfig_list,
                          file_parent_list=fparent_list2, dataset_conf_list=dconfig_list)
            if acqEra:
                result["acquisition_era"] = acqEra
            if prsEra:
                result["processing_era"] = prsEra
            return result
        finally:
            if conn:
                conn.close()
174116
def deserialize_block(value):
        
        # Block id strings are stored under batch/txn ids for reference.
        # Only Blocks, not ids or Nones, should be returned by _get_block.
        block = Block()
        block.ParseFromString(value)
        return BlockWrapper(
            block=block)