if value is None:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>model = Setting.get_model_for_value(value)<EOL>obj = super(SettingQuerySet, model.objects.all()).create(name=name, value=value)<EOL>return obj<EOL>

Creates and returns an object of the appropriate type for ``value``.


if not hasattr(cls, '<STR_LIT>'):<EOL><INDENT>raise NotImplementedError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>return isinstance(value, cls.value_type)<EOL>

Returns ``True`` if this model should be used to store ``value``.

Checks if ``value`` is an instance of ``value_type``. Override this
method if you need more advanced behaviour. For example, to distinguish
between single and multi-line text.


settings = SettingDict(queryset=self, default=default)<EOL>return settings<EOL>

Returns a ``SettingDict`` object for this queryset.


def on_message(self, websocket, message):

waiter = self._waiter<EOL>self._waiter = None<EOL>encoded = json.loads(message)<EOL>event = encoded.get('<STR_LIT>')<EOL>channel = encoded.get('<STR_LIT>')<EOL>data = json.loads(encoded.get('<STR_LIT:data>'))<EOL>try:<EOL><INDENT>if event == PUSHER_ERROR:<EOL><INDENT>raise PusherError(data['<STR_LIT:message>'], data['<STR_LIT:code>'])<EOL><DEDENT>elif event == PUSHER_CONNECTION:<EOL><INDENT>self.socket_id = data.get('<STR_LIT>')<EOL>self.logger.info('<STR_LIT>',<EOL>self.socket_id)<EOL>waiter.set_result(self.socket_id)<EOL><DEDENT>elif event == PUSHER_SUBSCRIBED:<EOL><INDENT>self.logger.info('<STR_LIT>',<EOL>encoded.get('<STR_LIT>'))<EOL><DEDENT>elif channel:<EOL><INDENT>self[channel]._event(event, data)<EOL><DEDENT><DEDENT>except Exception as exc:<EOL><INDENT>if waiter:<EOL><INDENT>waiter.set_exception(exc)<EOL><DEDENT>else:<EOL><INDENT>self.logger.exception('<STR_LIT>')<EOL><DEDENT><DEDENT>


if not self._consumer:<EOL><INDENT>waiter = self._waiter = asyncio.Future()<EOL>try:<EOL><INDENT>address = self._websocket_host()<EOL>self.logger.info('<STR_LIT>', address)<EOL>self._consumer = await self.http.get(address)<EOL>if self._consumer.status_code != <NUM_LIT>:<EOL><INDENT>raise PusherError("<STR_LIT>")<EOL><DEDENT><DEDENT>except Exception as exc:<EOL><INDENT>waiter.set_exception(exc)<EOL>raise<EOL><DEDENT>else:<EOL><INDENT>await waiter<EOL><DEDENT><DEDENT>return self._consumer<EOL>


return self.endpoint.http_session<EOL>


dirname = os.path.dirname(filename or __file__)<EOL>git_show = sh('<STR_LIT>',<EOL>cwd=dirname)<EOL>timestamp = git_show.partition('<STR_LIT:\n>')[<NUM_LIT:0>]<EOL>try:<EOL><INDENT>timestamp = datetime.datetime.utcfromtimestamp(int(timestamp))<EOL><DEDENT>except ValueError:<EOL><INDENT>return None<EOL><DEDENT>return timestamp.strftime('<STR_LIT>')<EOL>

Returns a numeric identifier of the latest git changeset.

    The result is the UTC timestamp of the changeset in YYYYMMDDHHMMSS format.
    This value isn't guaranteed to be unique, but collisions are very unlikely,
    so it's sufficient for generating the development version numbers.


async def upload_file(self, bucket, file, uploadpath=None, key=None,<EOL>ContentType=None, **kw):

is_filename = False<EOL>if hasattr(file, '<STR_LIT>'):<EOL><INDENT>if hasattr(file, '<STR_LIT>'):<EOL><INDENT>file.seek(<NUM_LIT:0>)<EOL><DEDENT>file = file.read()<EOL>size = len(file)<EOL><DEDENT>elif key:<EOL><INDENT>size = len(file)<EOL><DEDENT>else:<EOL><INDENT>is_filename = True<EOL>size = os.stat(file).st_size<EOL>key = os.path.basename(file)<EOL><DEDENT>assert key, '<STR_LIT>'<EOL>if not ContentType:<EOL><INDENT>ContentType, _ = mimetypes.guess_type(key)<EOL><DEDENT>if uploadpath:<EOL><INDENT>if not uploadpath.endswith('<STR_LIT:/>'):<EOL><INDENT>uploadpath = '<STR_LIT>' % uploadpath<EOL><DEDENT>key = '<STR_LIT>' % (uploadpath, key)<EOL><DEDENT>params = dict(Bucket=bucket, Key=key)<EOL>if not ContentType:<EOL><INDENT>ContentType = '<STR_LIT>'<EOL><DEDENT>params['<STR_LIT>'] = ContentType<EOL>if size > MULTI_PART_SIZE and is_filename:<EOL><INDENT>resp = await _multipart(self, file, params)<EOL><DEDENT>elif is_filename:<EOL><INDENT>with open(file, '<STR_LIT:rb>') as fp:<EOL><INDENT>params['<STR_LIT>'] = fp.read()<EOL><DEDENT>resp = await self.put_object(**params)<EOL><DEDENT>else:<EOL><INDENT>params['<STR_LIT>'] = file<EOL>resp = await self.put_object(**params)<EOL><DEDENT>if '<STR_LIT>' not in resp:<EOL><INDENT>resp['<STR_LIT>'] = key<EOL><DEDENT>if '<STR_LIT>' not in resp:<EOL><INDENT>resp['<STR_LIT>'] = bucket<EOL><DEDENT>return resp<EOL>

Upload a file to S3 possibly using the multi-part uploader
        Return the key uploaded


def upload_folder(self, bucket, folder, key=None, skip=None,<EOL>content_types=None):

uploader = FolderUploader(self, bucket, folder, key, skip,<EOL>content_types)<EOL>return uploader.start()<EOL>

Recursively upload a ``folder`` into a backet.

        :param bucket: bucket where to upload the folder to
        :param folder: the folder location in the local file system
        :param key: Optional key where the folder is uploaded
        :param skip: Optional list of files to skip
        :param content_types: Optional dictionary mapping suffixes to
            content types
        :return: a coroutine


async def copy_storage_object(self, source_bucket, source_key,<EOL>bucket, key):

info = await self.head_object(Bucket=source_bucket, Key=source_key)<EOL>size = info['<STR_LIT>']<EOL>if size > MULTI_PART_SIZE:<EOL><INDENT>result = await _multipart_copy(self, source_bucket, source_key,<EOL>bucket, key, size)<EOL><DEDENT>else:<EOL><INDENT>result = await self.copy_object(<EOL>Bucket=bucket, Key=key,<EOL>CopySource=_source_string(source_bucket, source_key)<EOL>)<EOL><DEDENT>return result<EOL>

Copy a file from one bucket into another


if not self.can_paginate(operation_name):<EOL><INDENT>raise OperationNotPageableError(operation_name=operation_name)<EOL><DEDENT>else:<EOL><INDENT>actual_operation_name = self._PY_TO_OP_NAME[operation_name]<EOL>Paginator.PAGE_ITERATOR_CLS = AsyncPageIterator<EOL>paginator = Paginator(<EOL>getattr(self, operation_name),<EOL>self._cache['<STR_LIT>'][actual_operation_name])<EOL>return paginator<EOL><DEDENT>

Create a paginator for an operation.
        :type operation_name: string
        :param operation_name: The operation name.  This is the same name
            as the method name on the client.  For example, if the
            method name is ``create_foo``, and you'd normally invoke the
            operation as ``client.create_foo(**kwargs)``, if the
            ``create_foo`` operation can be paginated, you can use the
            call ``client.get_paginator("create_foo")``.
        :raise OperationNotPageableError: Raised if the operation is not
            pageable.  You can use the ``client.can_paginate`` method to
            check if an operation is pageable.
        :rtype: L{botocore.paginate.Paginator}
        :return: A paginator object.


def cache_set(key, value):<EOL><INDENT>cache.set(key, value, AVATAR_CACHE_TIMEOUT)<EOL>return value<EOL><DEDENT>def cached_func(user, size):<EOL><INDENT>prefix = func.__name__<EOL>cached_funcs.add(prefix)<EOL>key = get_cache_key(user, size, prefix=prefix)<EOL>return cache.get(key) or cache_set(key, func(user, size))<EOL><DEDENT>return cached_func<EOL>

Decorator to cache the result of functions that take a ``user`` and a
``size`` value.


while len(self.senders) >= self.window:<EOL><INDENT>pass<EOL><DEDENT>self.senders[self.new_seq_no] = self.Sender(<EOL>self.write,<EOL>self.send_lock,<EOL>data,<EOL>self.new_seq_no,<EOL>timeout=self.sending_timeout,<EOL>callback=self.send_callback,<EOL>)<EOL>self.senders[self.new_seq_no].start()<EOL>self.new_seq_no = (self.new_seq_no + <NUM_LIT:1>) % HDLController.MAX_SEQ_NO<EOL>

Sends a new data frame.

This method will block until a new room is available for
a new sender. This limit is determined by the size of the window.


if not hasattr(callback, '<STR_LIT>'):<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>self.send_callback = callback<EOL>

Sets the send callback function.

If the HDLC controller has already been started, the new
callback function will be taken into account for the next
data frames to be sent.


return len(self.senders)<EOL>


if sending_timeout >= HDLController.MIN_SENDING_TIMEOUT:<EOL><INDENT>self.sending_timeout = sending_timeout<EOL><DEDENT>


if not hasattr(callback, '<STR_LIT>'):<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>self.receive_callback = callback<EOL>

Sets the receive callback function.

This method has to be called before starting the
HDLC controller.


def get_result(self, errors=STRICT, **params):

service_url = self.create_session(**params)<EOL>return self.poll(service_url, errors=errors)<EOL>

Get all results, no filtering,
etc. by creating and polling the session.


def make_request(self, url, method='<STR_LIT>', headers=None, data=None,<EOL>callback=None, errors=STRICT, verify=False, timeout=None, **params):

error_modes = (STRICT, GRACEFUL, IGNORE)<EOL>error_mode = errors or GRACEFUL<EOL>if error_mode.lower() not in error_modes:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'<EOL>% '<STR_LIT:U+002C>'.join(error_modes))<EOL><DEDENT>if callback is None:<EOL><INDENT>callback = self._default_resp_callback<EOL><DEDENT>request = getattr(requests, method.lower())<EOL>log.debug('<STR_LIT>' % url)<EOL>log.debug('<STR_LIT>' % method)<EOL>log.debug('<STR_LIT>' % params)<EOL>log.debug('<STR_LIT>' % headers)<EOL>log.debug('<STR_LIT>' % timeout)<EOL>r = request(<EOL>url, headers=headers, data=data, verify=verify, timeout=timeout, params=params)<EOL>log.debug('<STR_LIT>' % r.url)<EOL>try:<EOL><INDENT>r.raise_for_status()<EOL>return callback(r)<EOL><DEDENT>except Exception as e:<EOL><INDENT>return self._with_error_handling(r, e,<EOL>error_mode, self.response_format)<EOL><DEDENT>

Reusable method for performing requests.
:param url - URL to request
:param method - request method, default is 'get'
:param headers - request headers
:param data - post data
:param callback - callback to be applied to response,
                  default callback will parse response as json object.
:param errors - specifies communication errors handling mode, possible
                values are:
                 * strict (default) - throw an error as soon as one
                    occurred
                 * graceful - ignore certain errors, e.g. EmptyResponse
                 * ignore - ignore all errors and return a result in
                            any case.
                            NOTE that it DOES NOT mean that no
                            exceptions can be
                            raised from this method, it mostly ignores
                            communication
                            related errors.
                 * None or empty string equals to default
:param verify - whether or not to verify SSL cert, default to False
:param timeout - the timeout of the request in second, default to None
:param params - additional query parameters for request


if version == "<STR_LIT>":<EOL><INDENT>return sizeof(DescriptorTableDenali)<EOL><DEDENT>elif version == "<STR_LIT>":<EOL><INDENT>return sizeof(DescriptorTableSpec20)<EOL><DEDENT>elif version == "<STR_LIT>":<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>raise RuntimeError("<STR_LIT>")<EOL><DEDENT>


cmd = ["<STR_LIT>", path]<EOL>status, stdout, _ = cij.ssh.command(cmd, shell=True, echo=True)<EOL>if status:<EOL><INDENT>raise RuntimeError("<STR_LIT>" % path)<EOL><DEDENT>return stdout.strip()<EOL>


if env():<EOL><INDENT>cij.err("<STR_LIT>")<EOL>return <NUM_LIT:1><EOL><DEDENT>nvme = cij.env_to_dict(PREFIX, EXPORTED + REQUIRED)<EOL>cmd = ["<STR_LIT>", "<STR_LIT>", nvme["<STR_LIT>"], "<STR_LIT>"]<EOL>rcode, _, _ = cij.ssh.command(cmd, shell=True, echo=False)<EOL>if rcode:<EOL><INDENT>return False<EOL><DEDENT>return True<EOL>

Verify that the ENV defined NVMe device exists


def comp_meta(file_bef, file_aft, mode="<STR_LIT>"):

if env():<EOL><INDENT>cij.err("<STR_LIT>")<EOL>return <NUM_LIT:1><EOL><DEDENT>nvme = cij.env_to_dict(PREFIX, EXPORTED + REQUIRED)<EOL>num_chk = int(nvme["<STR_LIT>"])<EOL>meta_bef = cij.bin.Buffer(types=get_descriptor_table(nvme['<STR_LIT>']), length=num_chk)<EOL>meta_aft = cij.bin.Buffer(types=get_descriptor_table(nvme['<STR_LIT>']), length=num_chk)<EOL>meta_bef.read(file_bef)<EOL>meta_aft.read(file_aft)<EOL>for chk in range(num_chk):<EOL><INDENT>ignore = ["<STR_LIT>", "<STR_LIT>"]<EOL>if mode == "<STR_LIT>" and meta_bef[chk].CS == <NUM_LIT:4>:<EOL><INDENT>ignore.append("<STR_LIT>")<EOL><DEDENT>if meta_bef.compare(meta_aft, chk, ignore=ignore):<EOL><INDENT>cij.warn("<STR_LIT>" % chk)<EOL>meta_bef.dump(chk)<EOL>cij.warn("<STR_LIT>" % chk)<EOL>meta_aft.dump(chk)<EOL>cij.err("<STR_LIT>" % chk)<EOL>return <NUM_LIT:1><EOL><DEDENT><DEDENT>return <NUM_LIT:0><EOL>

Compare chunk meta, mode=[pfail, power, reboot]


def dev_get_rprt(dev_name, pugrp=None, punit=None):

cmd = ["<STR_LIT>", "<STR_LIT>", dev_name]<EOL>if not (pugrp is None and punit is None):<EOL><INDENT>cmd = ["<STR_LIT>", "<STR_LIT>", dev_name, str(pugrp), str(punit)]<EOL><DEDENT>_, _, _, struct = cij.test.command_to_struct(cmd)<EOL>if not struct:<EOL><INDENT>return None<EOL><DEDENT>return struct["<STR_LIT>"]<EOL>

Get-log-page chunk information

If the pugrp and punit is set, then provide report only for that pugrp/punit

@returns the first chunk in the given state if one exists, None otherwise


def s20_to_gen(self, pugrp, punit, chunk, sectr):

cmd = ["<STR_LIT>", self.envs,<EOL>"<STR_LIT>" % (pugrp, punit, chunk, sectr)]<EOL>status, stdout, _ = cij.ssh.command(cmd, shell=True)<EOL>if status:<EOL><INDENT>raise RuntimeError("<STR_LIT>")<EOL><DEDENT>return int(re.findall(r"<STR_LIT>", stdout)[<NUM_LIT:0>], <NUM_LIT:16>)<EOL>


cmd = ["<STR_LIT>", self.envs, "<STR_LIT>".format(address)]<EOL>status, stdout, _ = cij.ssh.command(cmd, shell=True)<EOL>if status:<EOL><INDENT>raise RuntimeError("<STR_LIT>")<EOL><DEDENT>return int(re.findall(r"<STR_LIT>", stdout)[<NUM_LIT:0>], <NUM_LIT:16>)<EOL>


cs = self.get_chunk_status(chk)<EOL>if cs & <NUM_LIT> != <NUM_LIT:0>:<EOL><INDENT>return True<EOL><DEDENT>return False<EOL>


def slc_erase(self, address, BE_ID=<NUM_LIT>, PMODE=<NUM_LIT>):

cmd = ["<STR_LIT>" % BE_ID, "<STR_LIT>" % PMODE, "<STR_LIT>", self.envs, "<STR_LIT>" % address]<EOL>status, _, _ = cij.ssh.command(cmd, shell=True)<EOL>return status<EOL>


def get_chunk_information(self, chk, lun, chunk_name):

cmd = ["<STR_LIT>", self.envs,<EOL>"<STR_LIT>" % (chk, lun, chunk_name)]<EOL>status, _, _ = cij.ssh.command(cmd, shell=True)<EOL>return status<EOL>


def vblk_write(self, address, file_name=None):

cmd = ["<STR_LIT>", self.envs, "<STR_LIT>" % address]<EOL>if file_name:<EOL><INDENT>cmd += ["<STR_LIT>".format(file_name)]<EOL><DEDENT>status, _, _ = cij.ssh.command(cmd, shell=True)<EOL>return status<EOL>


cmd = ["<STR_LIT>", self.envs, "<STR_LIT>" % address]<EOL>status, _, _ = cij.ssh.command(cmd, shell=True)<EOL>return status<EOL>


def scalar_read(self, address, block_count, data_file, meta_file):

cmd = ["<STR_LIT>", "<STR_LIT>", self.envs, "<STR_LIT>".format(address),<EOL>"<STR_LIT>".format(block_count - <NUM_LIT:1>), "<STR_LIT>".format(data_file),<EOL>"<STR_LIT>".format(meta_file),<EOL>"<STR_LIT>".format(block_count * self.get_env("<STR_LIT>", "<STR_LIT>")),<EOL>"<STR_LIT>".format(block_count * self.get_env("<STR_LIT>", "<STR_LIT>"))]<EOL>status, _, _ = cij.ssh.command(cmd, shell=True)<EOL>return status<EOL>


cmd = ["<STR_LIT>", self.envs["<STR_LIT>"], "<STR_LIT>".format(address)]<EOL>status, stdout, _ = cij.ssh.command(cmd, shell=True)<EOL>if status:<EOL><INDENT>raise RuntimeError("<STR_LIT>")<EOL><DEDENT>return int(re.findall(r"<STR_LIT>", stdout)[<NUM_LIT:0>], <NUM_LIT:16>)<EOL>


def vblk_read(self, address, meta=False):

cmd = list()<EOL>if meta:<EOL><INDENT>cmd.append("<STR_LIT>")<EOL><DEDENT>cmd += ["<STR_LIT>", self.envs["<STR_LIT>"], "<STR_LIT>" % address]<EOL>status, _, _ = cij.ssh.command(cmd, shell=True)<EOL>return status<EOL>


def is_free_chunk(self, chunk_meta, grp, pug, chk):

meta = self.get_chunk_meta_item(chunk_meta, grp, pug, chk)<EOL>if meta.CS & <NUM_LIT> != <NUM_LIT:0>:<EOL><INDENT>return True<EOL><DEDENT>return False<EOL>


chunks = self.envs["<STR_LIT>"]<EOL>if cij.nvme.get_meta(<NUM_LIT:0>, chunks * self.envs["<STR_LIT>"], meta_file):<EOL><INDENT>raise RuntimeError("<STR_LIT>")<EOL><DEDENT>chunk_meta = cij.bin.Buffer(types=self.envs["<STR_LIT>"], length=chunks)<EOL>chunk_meta.read(meta_file)<EOL>return chunk_meta<EOL>


def scalar_write(self, address, block_count, data_file, meta_file):

cmd = ["<STR_LIT>", "<STR_LIT>", self.envs["<STR_LIT>"], "<STR_LIT>".format(address),<EOL>"<STR_LIT>".format(block_count-<NUM_LIT:1>), "<STR_LIT>".format(data_file), "<STR_LIT>".format(meta_file),<EOL>"<STR_LIT>".format(block_count * self.envs["<STR_LIT>"]),<EOL>"<STR_LIT>".format(block_count * self.envs["<STR_LIT>"])]<EOL>status, _, _ = cij.ssh.command(cmd, shell=True)<EOL>return status<EOL>


return self.envs[key]<EOL>


cmd = ["<STR_LIT>", "<STR_LIT>", self.envs["<STR_LIT>"], "<STR_LIT>".format(address),<EOL>"<STR_LIT>".format(block_count - <NUM_LIT:1>), "<STR_LIT>".format(data_file),<EOL>"<STR_LIT>".format(meta_file),<EOL>"<STR_LIT>".format(block_count * self.envs["<STR_LIT>"]),<EOL>"<STR_LIT>".format(block_count * self.envs["<STR_LIT>"])]<EOL>status, _, _ = cij.ssh.command(cmd, shell=True)<EOL>return status<EOL>


here = os.path.abspath(os.path.dirname(__file__))<EOL>with codecs.open(os.path.join(here, *parts), '<STR_LIT:r>') as pfp:<EOL><INDENT>return pfp.read()<EOL><DEDENT>

Read parts to use a e.g. long_description


find = re.findall(pattern, content)<EOL>if not find:<EOL><INDENT>cij.err("<STR_LIT>" % pattern)<EOL>cij.err("<STR_LIT>" % content)<EOL>return '<STR_LIT>'<EOL><DEDENT>if len(find) >= <NUM_LIT:2>:<EOL><INDENT>cij.err("<STR_LIT>" % pattern)<EOL>cij.err("<STR_LIT>" % content)<EOL>return '<STR_LIT>'<EOL><DEDENT>return find[<NUM_LIT:0>]<EOL>


if cij.ssh.env():<EOL><INDENT>cij.err("<STR_LIT>")<EOL>return <NUM_LIT:1><EOL><DEDENT>board = cij.env_to_dict(PREFIX, REQUIRED)   <EOL>if board is None:<EOL><INDENT>cij.err("<STR_LIT>")<EOL>return <NUM_LIT:1><EOL><DEDENT>board["<STR_LIT>"] = "<STR_LIT:_>".join([board[r] for r in REQUIRED[:-<NUM_LIT:1>]])<EOL>board["<STR_LIT>"] = "<STR_LIT:->".join([board["<STR_LIT>"], board["<STR_LIT>"]])<EOL>cij.env_export(PREFIX, EXPORTED, board)     <EOL>return <NUM_LIT:0><EOL>

Verify BOARD variables and construct exported variables


def generate_steady_rt_pic(process_data, para_meter, scale, steady_time):

pic_path_steady = para_meter['<STR_LIT:filename>'] + '<STR_LIT>'<EOL>plt.figure(figsize=(<NUM_LIT:4> * scale, <NUM_LIT> * scale))<EOL>for key in process_data.keys():<EOL><INDENT>if len(process_data[key]) < steady_time:<EOL><INDENT>steady_time = len(process_data[key])<EOL><DEDENT>plt.scatter(process_data[key][-<NUM_LIT:1> * steady_time:, <NUM_LIT:0>],<EOL>process_data[key][-<NUM_LIT:1> * steady_time:, <NUM_LIT:1>], label=str(key), s=<NUM_LIT:10>)<EOL>steady_value = np.mean(process_data[key][-<NUM_LIT:1> * steady_time:, <NUM_LIT:1>])<EOL>steady_value_5 = steady_value * (<NUM_LIT:1> + <NUM_LIT>)<EOL>steady_value_10 = steady_value * (<NUM_LIT:1> + <NUM_LIT:0.1>)<EOL>steady_value_ng_5 = steady_value * (<NUM_LIT:1> - <NUM_LIT>)<EOL>steady_value_ng_10 = steady_value * (<NUM_LIT:1> - <NUM_LIT:0.1>)<EOL>plt.plot(process_data[key][-<NUM_LIT:1> * steady_time:, <NUM_LIT:0>], [steady_value] * steady_time, '<STR_LIT:b>')<EOL>plt.plot(process_data[key][-<NUM_LIT:1> * steady_time:, <NUM_LIT:0>], [steady_value_5] * steady_time, '<STR_LIT:g>')<EOL>plt.plot(process_data[key][-<NUM_LIT:1> * steady_time:, <NUM_LIT:0>],<EOL>[steady_value_ng_5] * steady_time, '<STR_LIT:g>')<EOL>plt.plot(process_data[key][-<NUM_LIT:1> * steady_time:, <NUM_LIT:0>], [steady_value_10] * steady_time, '<STR_LIT:r>')<EOL>plt.plot(process_data[key][-<NUM_LIT:1> * steady_time:, <NUM_LIT:0>],<EOL>[steady_value_ng_10] * steady_time, '<STR_LIT:r>')<EOL><DEDENT>plt.title(para_meter['<STR_LIT:title>'] + '<STR_LIT>')<EOL>plt.xlabel(para_meter['<STR_LIT>'] + '<STR_LIT>')<EOL>plt.ylabel(para_meter['<STR_LIT>'] + '<STR_LIT>')<EOL>plt.legend(loc='<STR_LIT>')<EOL>plt.savefig(pic_path_steady)<EOL>return pic_path_steady<EOL>


def import_source(self, sheet, source, delimiter="<STR_LIT:U+002C>"):

<EOL>if '<STR_LIT:U+0020>' in sheet:<EOL><INDENT>raise RuntimeError("<STR_LIT>" % sheet)<EOL><DEDENT>if not source.endswith("<STR_LIT>") and not source.endswith("<STR_LIT>"):<EOL><INDENT>raise RuntimeError("<STR_LIT>" % source)<EOL><DEDENT>self.source_sheet = sheet<EOL>source_data = np.loadtxt(source, dtype=str, delimiter=delimiter)<EOL>self.source_data = {"<STR_LIT:title>": source_data[<NUM_LIT:0>].tolist(),<EOL>"<STR_LIT:data>": source_data[<NUM_LIT:1>:]}<EOL>cell_format_title = self.workbook.add_format({'<STR_LIT>': True,<EOL>'<STR_LIT>': u'<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': <NUM_LIT>})<EOL>cell_format = self.workbook.add_format({'<STR_LIT>': False,<EOL>'<STR_LIT>': u'<STR_LIT>',<EOL>'<STR_LIT>': <NUM_LIT:0>})<EOL>worksheet = self.workbook.add_worksheet(sheet)<EOL>worksheet.write_row('<STR_LIT>', self.source_data['<STR_LIT:title>'], cell_format_title)<EOL>_, col_num = self.source_data['<STR_LIT:data>'].shape<EOL>for i in range(col_num):<EOL><INDENT>try:<EOL><INDENT>data_array = self.source_data['<STR_LIT:data>'][:, i].astype(float)<EOL><DEDENT>except ValueError:<EOL><INDENT>data_array = self.source_data['<STR_LIT:data>'][:, i]<EOL><DEDENT>worksheet.write_column(<NUM_LIT:1>, i, data_array.tolist(), cell_format)<EOL><DEDENT>

Function:
    Save original data into specific sheet, and try to translate data to float type
Input:
    sheet: Must be a non exists sheet
    source: File path of source


def gen_data_sheet(self, datafile, para_meter, scale=<NUM_LIT>, steady_time=<NUM_LIT>):

filename = os.path.splitext(os.path.split(datafile)[<NUM_LIT:1>])[<NUM_LIT:0>][:-<NUM_LIT:5>]<EOL>para_meter['<STR_LIT:filename>'] = filename<EOL>source_data = np.loadtxt(datafile, dtype=int, delimiter='<STR_LIT:U+002C>')[:, :<NUM_LIT:3>]<EOL>is_bw = '<STR_LIT>'in para_meter['<STR_LIT:title>'].lower()<EOL>file_data = process_rt_data(source_data, is_bw)<EOL>pic_path = generate_rt_pic(file_data, para_meter, scale)<EOL>pic_path_steady = generate_steady_rt_pic(file_data, para_meter, scale, steady_time)<EOL>if para_meter['<STR_LIT>'] in self.sheetname_dict.keys():<EOL><INDENT>self.sheetname_dict[para_meter['<STR_LIT>']] =self.sheetname_dict[para_meter['<STR_LIT>']] + <NUM_LIT:1><EOL>chart_sheet = self.workbook.get_worksheet_by_name(para_meter['<STR_LIT>'])<EOL><DEDENT>else:<EOL><INDENT>self.sheetname_dict[para_meter['<STR_LIT>']] = <NUM_LIT:1><EOL>chart_sheet = self.workbook.add_worksheet(para_meter['<STR_LIT>'])<EOL><DEDENT>chart_sheet.insert_image('<STR_LIT>' %<EOL>(<NUM_LIT:5> + (self.sheetname_dict[para_meter['<STR_LIT>']] - <NUM_LIT:1>) * <NUM_LIT:30>),<EOL>pic_path)<EOL>chart_sheet.insert_image('<STR_LIT>' %<EOL>(<NUM_LIT:5> + (self.sheetname_dict[para_meter['<STR_LIT>']] - <NUM_LIT:1>) * <NUM_LIT:30>),<EOL>pic_path_steady)<EOL>self.__insert_value(chart_sheet, file_data,<EOL><NUM_LIT:5> + (self.sheetname_dict[para_meter['<STR_LIT>']] - <NUM_LIT:1>) * <NUM_LIT:30>,<EOL>steady_time)<EOL>self.pic_list.append(pic_path)<EOL>self.pic_list.append(pic_path_steady)<EOL>

datafile, sheetname, x_axis_name, y_axis_name, title,
Function:
    Turn realtime bw data into picture, and save into specific sheet
Input:
    sheetname: If already exists, new chart will be added continuely.
               Otherwise, it would create new sheet;
    x_axis_name: x_axis name;
    y_axis_name: y_axis name;
    title: picure name;
    scale； size of picture.


self.workbook.close()<EOL>


for index in range(len(filter_data) - <NUM_LIT:1>):<EOL><INDENT>if filter_data[index][<NUM_LIT:0>] > filter_data[index + <NUM_LIT:1>][<NUM_LIT:0>]:<EOL><INDENT>max_index = index + <NUM_LIT:1><EOL>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>max_index = len(filter_data)<EOL><DEDENT>print("<STR_LIT>", max_index + <NUM_LIT:1>)<EOL>num_jobs = int(round(len(filter_data) * <NUM_LIT:1.0> / max_index))<EOL>print("<STR_LIT>", num_jobs)<EOL>dict_time = Counter(filter_data[:, <NUM_LIT:0>])<EOL>list_sum = []<EOL>for time_index in range(<NUM_LIT:1>, max_index + <NUM_LIT:1>):<EOL><INDENT>if dict_time.get(time_index * <NUM_LIT:1000>, <NUM_LIT:0>) != num_jobs:<EOL><INDENT>print("<STR_LIT>" % (<EOL>time_index * <NUM_LIT:1000>, dict_time.get(time_index * <NUM_LIT:1000>, <NUM_LIT:0>), num_jobs<EOL>))<EOL>continue<EOL><DEDENT>filter_mask = (filter_data[:, <NUM_LIT:0>] == time_index * <NUM_LIT:1000>)<EOL>sum_rst = np.sum(filter_data[filter_mask][:, <NUM_LIT:1>])<EOL>if is_bw:<EOL><INDENT>sum_rst = sum_rst / <NUM_LIT><EOL><DEDENT>list_sum.append([time_index, sum_rst])<EOL><DEDENT>return np.array(list_sum)<EOL>


def generate_rt_pic(process_data, para_meter, scale):

pic_path = para_meter['<STR_LIT:filename>'] + '<STR_LIT>'<EOL>plt.figure(figsize=(<NUM_LIT> * scale, <NUM_LIT> * scale))<EOL>for key in process_data.keys():<EOL><INDENT>plt.plot(process_data[key][:, <NUM_LIT:0>], process_data[key][:, <NUM_LIT:1>], label=str(key))<EOL><DEDENT>plt.title(para_meter['<STR_LIT:title>'])<EOL>plt.xlabel(para_meter['<STR_LIT>'])<EOL>plt.ylabel(para_meter['<STR_LIT>'])<EOL>plt.legend(loc='<STR_LIT>')<EOL>plt.savefig(pic_path)<EOL>return pic_path<EOL>


<EOL>if not {'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'}.issubset(set(properties.keys())):<EOL><INDENT>raise RuntimeError("<STR_LIT>" % properties.keys())<EOL><DEDENT>mask = self.__filter_data(properties['<STR_LIT>'])<EOL>chart = self.__generate_chart(mask, properties)<EOL>sheet = properties['<STR_LIT>']<EOL>if sheet in self.sheet_dict.keys():<EOL><INDENT>self.sheet_dict[sheet] += <NUM_LIT:1><EOL>worksheet = self.workbook.get_worksheet_by_name(sheet)<EOL><DEDENT>else:<EOL><INDENT>self.sheet_dict[sheet] = <NUM_LIT:1><EOL>worksheet = self.workbook.add_worksheet(sheet)<EOL><DEDENT>worksheet.insert_chart('<STR_LIT>' % (<NUM_LIT:5> + (self.sheet_dict[sheet] - <NUM_LIT:1>) * <NUM_LIT>), chart)<EOL>

Function:
    Generate and save chart to specific sheet.
Input:
    sheet: If already exists, new chart will be added below.
           Otherwise, it would create a new sheet;
    x_axis: Specify x axis;
    y_axis: Specify y axis;
    series: Specify series;
    filters: dict type, use to filter useful data from original data;
    title: if None, the chart will create without title;
    x_axis_name: if None, use x_axis instead;
    y_axis_name: if None, use y_axis instead;


for index, _ in enumerate(filter_data):<EOL><INDENT>filter_data[index][<NUM_LIT:0>] = round(filter_data[index][<NUM_LIT:0>] / <NUM_LIT>) * <NUM_LIT><EOL><DEDENT>return filter_data<EOL>


<EOL>tsuite["<STR_LIT>"] = runlogs_to_html(tsuite["<STR_LIT>"])<EOL>tsuite["<STR_LIT>"] = aux_listing(tsuite["<STR_LIT>"])<EOL>tsuite["<STR_LIT>"] = extract_hook_names(tsuite)<EOL>return True<EOL>

Goes through the tsuite and processes "*.log


if not os.path.exists(fpath):<EOL><INDENT>return "<STR_LIT>" % fpath<EOL><DEDENT>return open(fpath, "<STR_LIT:r>").read()<EOL>

Returns content of the given 'fpath' with HTML annotations for syntax
highlighting


plog = []<EOL>plog.append(("<STR_LIT>", process_trun(trun)))<EOL>for tsuite in trun["<STR_LIT>"]:<EOL><INDENT>plog.append(("<STR_LIT>", process_tsuite(tsuite)))<EOL>for tcase in tsuite["<STR_LIT>"]:<EOL><INDENT>plog.append(("<STR_LIT>", process_tcase(tcase)))<EOL><DEDENT><DEDENT>for task, success in plog:<EOL><INDENT>if not success:<EOL><INDENT>cij.err("<STR_LIT>" % task)<EOL><DEDENT><DEDENT>return sum((success for task, success in plog))<EOL>

Perform postprocessing of the given test run


descr_short = "<STR_LIT>"<EOL>descr_long = "<STR_LIT>"<EOL>try:<EOL><INDENT>comment = tcase_comment(tcase)<EOL><DEDENT>except (IOError, OSError, ValueError) as exc:<EOL><INDENT>comment = []<EOL>cij.err("<STR_LIT>" % (exc, tcase))<EOL><DEDENT>comment = [l for l in comment if l.strip()]     <EOL>for line_number, line in enumerate(comment):<EOL><INDENT>if line.startswith("<STR_LIT:#>"):<EOL><INDENT>comment[line_number] = line[<NUM_LIT:1>:]<EOL><DEDENT><DEDENT>if comment:<EOL><INDENT>descr_short = comment[<NUM_LIT:0>]<EOL><DEDENT>if len(comment) > <NUM_LIT:1>:<EOL><INDENT>descr_long = "<STR_LIT:\n>".join(comment[<NUM_LIT:1>:])<EOL><DEDENT>return descr_short, descr_long<EOL>

Parse descriptions from the the given tcase


def stamp_to_datetime(stamp):<EOL><INDENT>"""<STR_LIT>"""<EOL>return datetime.datetime.fromtimestamp(int(stamp))<EOL><DEDENT>def strftime(dtime, fmt):<EOL><INDENT>"""<STR_LIT>"""<EOL>return dtime.strftime(fmt)<EOL><DEDENT>def ansi_to_html(ansi):<EOL><INDENT>"""<STR_LIT>"""<EOL>conv = ansi2html.Ansi2HTMLConverter(<EOL>scheme="<STR_LIT>",<EOL>inline=True<EOL>)<EOL>html = conv.convert(ansi, full=False)<EOL>with open("<STR_LIT>", "<STR_LIT:w>") as html_file:<EOL><INDENT>html_file.write(html)<EOL><DEDENT>return html<EOL><DEDENT>tmpl_dpath = os.path.dirname(tmpl_fpath)<EOL>tmpl_fname = os.path.basename(tmpl_fpath)<EOL>env = jinja2.Environment(<EOL>autoescape=True,<EOL>loader=jinja2.FileSystemLoader(tmpl_dpath)<EOL>)<EOL>env.filters['<STR_LIT>'] = stamp_to_datetime<EOL>env.filters['<STR_LIT>'] = strftime<EOL>env.filters['<STR_LIT>'] = ansi_to_html<EOL>tmpl = env.get_template(tmpl_fname)<EOL>return tmpl.render(dset=dset)<EOL>

@returns A HTML representation of the given 'dset' using the template at
'tmpl_fpath'


listing = []<EOL>for root, _, fnames in os.walk(aux_root):<EOL><INDENT>count = len(aux_root.split(os.sep))<EOL>prefix = root.split(os.sep)[count:]<EOL>for fname in fnames:<EOL><INDENT>listing.append(os.sep.join(prefix + [fname]))<EOL><DEDENT><DEDENT>return listing<EOL>


hnames = []<EOL>for hook in ent["<STR_LIT>"]["<STR_LIT>"] + ent["<STR_LIT>"]["<STR_LIT>"]:<EOL><INDENT>hname = os.path.basename(hook["<STR_LIT>"])<EOL>hname = os.path.splitext(hname)[<NUM_LIT:0>]<EOL>hname = hname.strip()<EOL>hname = hname.replace("<STR_LIT>", "<STR_LIT>")<EOL>hname = hname.replace("<STR_LIT>", "<STR_LIT>")<EOL>if hname in hnames:<EOL><INDENT>continue<EOL><DEDENT>hnames.append(hname)<EOL><DEDENT>hnames.sort()<EOL>return hnames<EOL>

Extract hook names from the given entity


variables = {}<EOL>for req in REQS:<EOL><INDENT>prefix = req.upper()<EOL>variables[prefix] = cij.env_to_dict(<EOL>prefix, getattr(cij, req).REQUIRED + getattr(cij, req).EXPORTED<EOL>)<EOL><DEDENT>return variables<EOL>

Return variables defined by modules required by test


spath = spath if spath else os.environ.get("<STR_LIT>", None)<EOL>if spath is None:<EOL><INDENT>return None<EOL><DEDENT>tests = []                          <EOL>for root, _, files in os.walk(spath):<EOL><INDENT>if root != spath:<EOL><INDENT>continue<EOL><DEDENT>tests += [f for f in files if f[-<NUM_LIT:3>:] in ["<STR_LIT>", "<STR_LIT>"]]<EOL><DEDENT>return tests<EOL>

Lists tindex in CIJ_TESTCASES

@Returns On success, a list of filenames is returned. On error, None is
returned


msg = "<STR_LIT>" % msg if msg else "<STR_LIT>"<EOL>if rcode:<EOL><INDENT>cij.err("<STR_LIT>" % msg)<EOL><DEDENT>else:<EOL><INDENT>cij.good("<STR_LIT>" % msg)<EOL><DEDENT>sys.exit(rcode)<EOL>


if env():<EOL><INDENT>cij.err("<STR_LIT>")<EOL>return <NUM_LIT:1><EOL><DEDENT>lnvm = cij.env_to_dict(PREFIX, EXPORTED + REQUIRED)<EOL>cij.emph("<STR_LIT>" % lnvm["<STR_LIT>"])<EOL>cmd = ["<STR_LIT>" % (lnvm["<STR_LIT>"])]<EOL>rcode, _, _ = cij.ssh.command(cmd, shell=True)<EOL>if rcode:<EOL><INDENT>cij.err("<STR_LIT>")<EOL>return <NUM_LIT:1><EOL><DEDENT>return <NUM_LIT:0><EOL>


if env():<EOL><INDENT>cij.err("<STR_LIT>")<EOL>return <NUM_LIT:1><EOL><DEDENT>nvme = cij.env_to_dict("<STR_LIT>", ["<STR_LIT>"])<EOL>lnvm = cij.env_to_dict(PREFIX, EXPORTED + REQUIRED)<EOL>cij.emph("<STR_LIT>" % lnvm["<STR_LIT>"])<EOL>cmd = ["<STR_LIT>" % (<EOL>nvme["<STR_LIT>"], lnvm["<STR_LIT>"], lnvm["<STR_LIT>"], lnvm["<STR_LIT>"], lnvm["<STR_LIT>"])]<EOL>rcode, _, _ = cij.ssh.command(cmd, shell=True)<EOL>if rcode:<EOL><INDENT>cij.err("<STR_LIT>")<EOL>return <NUM_LIT:1><EOL><DEDENT>return <NUM_LIT:0><EOL>


self.__thread = Thread(target=self.__run, args=(True, False))<EOL>self.__thread.setDaemon(True)<EOL>self.__thread.start()<EOL>


if self.__thread:<EOL><INDENT>cmd = ["<STR_LIT>"]<EOL>status, output, _ = cij.util.execute(cmd, shell=True, echo=True)<EOL>if status:<EOL><INDENT>cij.warn("<STR_LIT>")<EOL>return <NUM_LIT:1><EOL><DEDENT>tty = output.split()[<NUM_LIT:1>]<EOL>cmd = ["<STR_LIT>".format("<STR_LIT:U+0020>".join(self.__prefix), tty)]<EOL>status, _, _ = cij.util.execute(cmd, shell=True, echo=True)<EOL>if status:<EOL><INDENT>cij.warn("<STR_LIT>")<EOL>return <NUM_LIT:1><EOL><DEDENT>self.__thread.join()<EOL>self.__thread = None<EOL><DEDENT>return <NUM_LIT:0><EOL>


if ext is None:<EOL><INDENT>ext = "<STR_LIT>"<EOL><DEDENT>fnames = set([])<EOL>for _, _, files in os.walk(search_path):<EOL><INDENT>for fname in files:<EOL><INDENT>if os.path.splitext(fname)[-<NUM_LIT:1>] in EXTS[ext]:<EOL><INDENT>fnames.add(fname)<EOL><DEDENT><DEDENT><DEDENT>return fnames<EOL>

@returns a set of filenames with extension 'ext' in 'search_path


for exp in exported:<EOL><INDENT>ENV["<STR_LIT:_>".join([prefix, exp])] = env[exp]<EOL><DEDENT>

Define the list of 'exported' variables with 'prefix' with values from 'env'


def expand_path(path):<EOL><INDENT>"""<STR_LIT>"""<EOL>return os.path.abspath(os.path.expanduser(os.path.expandvars(path)))<EOL><DEDENT>if prefix is None:<EOL><INDENT>prefix = "<STR_LIT>"<EOL><DEDENT>if names is None:<EOL><INDENT>names = [<EOL>"<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>"<EOL>]<EOL><DEDENT>conf = {v: os.environ.get("<STR_LIT:_>".join([prefix, v])) for v in names}<EOL>for env in (e for e in conf.keys() if e[:len(prefix)] in names and conf[e]):<EOL><INDENT>conf[env] = expand_path(conf[env])<EOL>if not os.path.exists(conf[env]):<EOL><INDENT>err("<STR_LIT>" % (prefix, env, conf[env]))<EOL><DEDENT><DEDENT>return conf<EOL>

Construct dict of paths from environment variables


return self.m_len<EOL>


return self.m_types<EOL>


def compare(self, buf, offset=<NUM_LIT:0>, length=<NUM_LIT:1>, ignore="<STR_LIT>"):

for i in range(offset, offset + length):<EOL><INDENT>if isinstance(self.m_types, (type(Union), type(Structure))):<EOL><INDENT>if compare(self.m_buf[i], buf[i], ignore=ignore):<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT><DEDENT>elif self.m_buf[i] != buf[i]:<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT><DEDENT>return <NUM_LIT:0><EOL>


def dump(buf, indent=<NUM_LIT:0>, skip="<STR_LIT>"):

if not isinstance(type(buf), (type(Union), type(Structure))):<EOL><INDENT>raise RuntimeError("<STR_LIT>" % type(buf))<EOL><DEDENT>for field in getattr(buf, '<STR_LIT>'):<EOL><INDENT>name, types = field[<NUM_LIT:0>], field[<NUM_LIT:1>]<EOL>if name in skip:<EOL><INDENT>return<EOL><DEDENT>value = getattr(buf, name)<EOL>if isinstance(types, (type(Union), type(Structure))):<EOL><INDENT>cij.info("<STR_LIT>" % ("<STR_LIT:U+0020>" * indent, name))<EOL>dump(value, indent+<NUM_LIT:2>, skip)<EOL><DEDENT>elif isinstance(types, type(Array)):<EOL><INDENT>for i, item in enumerate(value):<EOL><INDENT>name_index = "<STR_LIT>" % (name, i)<EOL>if isinstance(types, (type(Union), type(Structure))):<EOL><INDENT>cij.info("<STR_LIT>" % ("<STR_LIT:U+0020>" * indent, name_index))<EOL>dump(item, indent + <NUM_LIT:2>, skip)<EOL><DEDENT>else:<EOL><INDENT>cij.info("<STR_LIT>" % ("<STR_LIT:U+0020>" * indent, name_index, item))<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>cij.info("<STR_LIT>" % ("<STR_LIT:U+0020>" * indent, name, value))<EOL><DEDENT><DEDENT>


with open(path, "<STR_LIT:rb>") as fout:<EOL><INDENT>memmove(self.m_buf, fout.read(self.m_size), self.m_size)<EOL><DEDENT>


if self.__power_off_port is None:<EOL><INDENT>cij.err("<STR_LIT>")<EOL>return <NUM_LIT:1><EOL><DEDENT>return self.__press(self.__power_off_port, interval=interval)<EOL>


def run(self, shell=True, cmdline=False, echo=True):

if env():<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT>cmd = ["<STR_LIT>"] + self.__parse_parms()<EOL>if cmdline:<EOL><INDENT>cij.emph("<STR_LIT>" % (shell, cmd))<EOL><DEDENT>return cij.ssh.command(cmd, shell, echo)<EOL>


if env():<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT>cmd = ["<STR_LIT>"]<EOL>status, _, _ = cij.ssh.command(cmd, shell=True, echo=False)<EOL>if not status:<EOL><INDENT>status, _, _ = cij.ssh.command(["<STR_LIT>"], shell=True)<EOL>if status:<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT><DEDENT>return <NUM_LIT:0><EOL>


if key in self.__parm.keys():<EOL><INDENT>return self.__parm[key]<EOL><DEDENT>return None<EOL>


args = list()<EOL>for key, val in self.__parm.items():<EOL><INDENT>key = key.replace("<STR_LIT>", "<STR_LIT>").lower()<EOL>if key == "<STR_LIT>":<EOL><INDENT>args.append("<STR_LIT>")<EOL><DEDENT>if val is None:<EOL><INDENT>args.append("<STR_LIT>" % key)<EOL><DEDENT>else:<EOL><INDENT>args.append("<STR_LIT>" % (key, val))<EOL><DEDENT><DEDENT>return args<EOL>


return self.output<EOL>


self.output = self.target(*self.args)<EOL>


ipmi = cij.env_to_dict(PREFIX, REQUIRED)<EOL>if ipmi is None:<EOL><INDENT>ipmi["<STR_LIT>"] = "<STR_LIT>"<EOL>ipmi["<STR_LIT>"] = "<STR_LIT>"<EOL>ipmi["<STR_LIT>"] = "<STR_LIT:localhost>"<EOL>ipmi["<STR_LIT>"] = "<STR_LIT>"<EOL>cij.info("<STR_LIT>" % (<EOL>ipmi["<STR_LIT>"], ipmi["<STR_LIT>"], ipmi["<STR_LIT>"], ipmi["<STR_LIT>"]<EOL>))<EOL><DEDENT>cij.env_export(PREFIX, EXPORTED, ipmi)<EOL>return <NUM_LIT:0><EOL>


def tcase_setup(trun, parent, tcase_fname):

<EOL>case = copy.deepcopy(TESTCASE)<EOL>case["<STR_LIT>"] = tcase_fname<EOL>case["<STR_LIT>"] = os.sep.join([trun["<STR_LIT>"]["<STR_LIT>"], case["<STR_LIT>"]])<EOL>if not os.path.exists(case["<STR_LIT>"]):<EOL><INDENT>cij.err('<STR_LIT>' % case["<STR_LIT>"])<EOL>return None<EOL><DEDENT>case["<STR_LIT:name>"] = os.path.splitext(case["<STR_LIT>"])[<NUM_LIT:0>]<EOL>case["<STR_LIT>"] = "<STR_LIT:/>".join([parent["<STR_LIT>"], case["<STR_LIT>"]])<EOL>case["<STR_LIT>"] = os.sep.join([parent["<STR_LIT>"], case["<STR_LIT>"]])<EOL>case["<STR_LIT>"] = os.sep.join([case["<STR_LIT>"], "<STR_LIT>"])<EOL>case["<STR_LIT>"] = os.sep.join([case["<STR_LIT>"], "<STR_LIT>"])<EOL>case["<STR_LIT>"] = os.sep.join([case["<STR_LIT>"], case["<STR_LIT>"]])<EOL>case["<STR_LIT>"].update(copy.deepcopy(parent["<STR_LIT>"]))<EOL>os.makedirs(case["<STR_LIT>"])                       <EOL>os.makedirs(case["<STR_LIT>"])<EOL>shutil.copyfile(case["<STR_LIT>"], case["<STR_LIT>"])  <EOL>case["<STR_LIT>"] = hooks_setup(trun, case, parent.get("<STR_LIT>"))<EOL>return case<EOL>


return os.sep.join([output_path, "<STR_LIT>"])<EOL>


suite = copy.deepcopy(TESTSUITE)  <EOL>suite["<STR_LIT:name>"] = declr.get("<STR_LIT:name>")<EOL>if suite["<STR_LIT:name>"] is None:<EOL><INDENT>cij.err("<STR_LIT>")<EOL>return None<EOL><DEDENT>suite["<STR_LIT>"] = declr.get("<STR_LIT>")<EOL>suite["<STR_LIT>"] = "<STR_LIT>" % (suite["<STR_LIT:name>"], enum)<EOL>suite["<STR_LIT>"] = os.sep.join([trun["<STR_LIT>"]["<STR_LIT>"], suite["<STR_LIT>"]])<EOL>suite["<STR_LIT>"] = os.sep.join([suite["<STR_LIT>"], "<STR_LIT>"])<EOL>suite["<STR_LIT>"].update(copy.deepcopy(trun["<STR_LIT>"]))<EOL>suite["<STR_LIT>"].update(copy.deepcopy(declr.get("<STR_LIT>", {})))<EOL>os.makedirs(suite["<STR_LIT>"])<EOL>os.makedirs(suite["<STR_LIT>"])<EOL>suite["<STR_LIT>"] = hooks_setup(trun, suite, declr.get("<STR_LIT>"))<EOL>suite["<STR_LIT>"] = declr.get("<STR_LIT>", [])<EOL>suite["<STR_LIT>"] = "<STR_LIT>" % suite["<STR_LIT:name>"]<EOL>suite["<STR_LIT>"] = os.sep.join([trun["<STR_LIT>"]["<STR_LIT>"], suite["<STR_LIT>"]])<EOL>tcase_fpaths = []                               <EOL>if os.path.exists(suite["<STR_LIT>"]):              <EOL><INDENT>suite_lines = (<EOL>l.strip() for l in open(suite["<STR_LIT>"]).read().splitlines()<EOL>)<EOL>tcase_fpaths.extend(<EOL>(l for l in suite_lines if len(l) > <NUM_LIT:1> and l[<NUM_LIT:0>] != "<STR_LIT:#>")<EOL>)<EOL><DEDENT>else:                                           <EOL><INDENT>tcase_fpaths.extend(declr.get("<STR_LIT>", []))<EOL><DEDENT>if len(set(tcase_fpaths)) != len(tcase_fpaths):<EOL><INDENT>cij.err("<STR_LIT>")<EOL>return None<EOL><DEDENT>for tcase_fname in tcase_fpaths:                <EOL><INDENT>tcase = tcase_setup(trun, suite, tcase_fname)<EOL>if not tcase:<EOL><INDENT>cij.err("<STR_LIT>")<EOL>return None<EOL><DEDENT>suite["<STR_LIT>"].append(tcase)<EOL><DEDENT>return suite<EOL>

Creates and initialized a TESTSUITE struct and site-effects such as creating
output directories and forwarding initialization of testcases


if trun["<STR_LIT>"]["<STR_LIT>"]:<EOL><INDENT>cij.emph("<STR_LIT>" % tsuite["<STR_LIT:name>"])<EOL><DEDENT>rcode = <NUM_LIT:0><EOL>for hook in tsuite["<STR_LIT>"]["<STR_LIT>"]:     <EOL><INDENT>rcode = script_run(trun, hook)<EOL>if rcode:<EOL><INDENT>break<EOL><DEDENT><DEDENT>if trun["<STR_LIT>"]["<STR_LIT>"]:<EOL><INDENT>cij.emph("<STR_LIT>" % rcode, rcode)<EOL><DEDENT>return rcode<EOL>

Triggers when entering the given testsuite


fpath = yml_fpath(conf["<STR_LIT>"])<EOL>if os.path.exists(fpath):   <EOL><INDENT>cij.err("<STR_LIT>" % fpath)<EOL>return <NUM_LIT:1><EOL><DEDENT>trun = trun_setup(conf)         <EOL>if not trun:<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT>trun_to_file(trun)              <EOL>trun_emph(trun)                 <EOL>tr_err = <NUM_LIT:0><EOL>tr_ent_err = trun_enter(trun)<EOL>for tsuite in (ts for ts in trun["<STR_LIT>"] if not tr_ent_err):<EOL><INDENT>ts_err = <NUM_LIT:0><EOL>ts_ent_err = tsuite_enter(trun, tsuite)<EOL>for tcase in (tc for tc in tsuite["<STR_LIT>"] if not ts_ent_err):<EOL><INDENT>tc_err = tcase_enter(trun, tsuite, tcase)<EOL>if not tc_err:<EOL><INDENT>tc_err += script_run(trun, tcase)<EOL>tc_err += tcase_exit(trun, tsuite, tcase)<EOL><DEDENT>tcase["<STR_LIT:status>"] = "<STR_LIT>" if tc_err else "<STR_LIT>"<EOL>trun["<STR_LIT>"][tcase["<STR_LIT:status>"]] += <NUM_LIT:1>  <EOL>trun["<STR_LIT>"]["<STR_LIT>"] -= <NUM_LIT:1><EOL>ts_err += tc_err                        <EOL>trun_to_file(trun)                      <EOL><DEDENT>if not ts_ent_err:<EOL><INDENT>ts_err += tsuite_exit(trun, tsuite)<EOL><DEDENT>ts_err += ts_ent_err                        <EOL>tr_err += ts_err<EOL>tsuite["<STR_LIT:status>"] = "<STR_LIT>" if ts_err else "<STR_LIT>"<EOL>cij.emph("<STR_LIT>" % tsuite["<STR_LIT:status>"], tsuite["<STR_LIT:status>"] != "<STR_LIT>")<EOL><DEDENT>if not tr_ent_err:<EOL><INDENT>trun_exit(trun)<EOL><DEDENT>tr_err += tr_ent_err<EOL>trun["<STR_LIT:status>"] = "<STR_LIT>" if tr_err else "<STR_LIT>"<EOL>trun["<STR_LIT>"]["<STR_LIT:end>"] = int(time.time()) + <NUM_LIT:1>         <EOL>trun_to_file(trun)                                  <EOL>cij.emph("<STR_LIT>" % trun["<STR_LIT>"])<EOL>cij.emph("<STR_LIT>" % trun["<STR_LIT:status>"], trun["<STR_LIT:status>"] != "<STR_LIT>")<EOL>return trun["<STR_LIT>"]["<STR_LIT>"] + trun["<STR_LIT>"]["<STR_LIT>"]<EOL>


hook = copy.deepcopy(HOOK)<EOL>hook["<STR_LIT:name>"] = os.path.splitext(os.path.basename(hook_fpath))[<NUM_LIT:0>]<EOL>hook["<STR_LIT:name>"] = hook["<STR_LIT:name>"].replace("<STR_LIT>", "<STR_LIT>").replace("<STR_LIT>", "<STR_LIT>")<EOL>hook["<STR_LIT>"] = parent["<STR_LIT>"]<EOL>hook["<STR_LIT>"] = hook_fpath<EOL>hook["<STR_LIT>"] = "<STR_LIT>" % os.path.basename(hook["<STR_LIT>"])<EOL>hook["<STR_LIT>"] = os.sep.join([hook["<STR_LIT>"], hook["<STR_LIT>"]])<EOL>hook["<STR_LIT>"] = os.sep.join([<EOL>hook["<STR_LIT>"],<EOL>"<STR_LIT>" % hook["<STR_LIT>"]<EOL>])<EOL>hook["<STR_LIT>"].update(copy.deepcopy(parent["<STR_LIT>"]))<EOL>shutil.copyfile(hook["<STR_LIT>"], hook["<STR_LIT>"])<EOL>return hook<EOL>


<EOL>if trun["<STR_LIT>"]["<STR_LIT>"]:<EOL><INDENT>cij.emph("<STR_LIT>" % tcase["<STR_LIT>"])<EOL><DEDENT>rcode = <NUM_LIT:0><EOL>for hook in reversed(tcase["<STR_LIT>"]["<STR_LIT>"]):    <EOL><INDENT>rcode = script_run(trun, hook)<EOL>if rcode:<EOL><INDENT>break<EOL><DEDENT><DEDENT>if trun["<STR_LIT>"]["<STR_LIT>"]:<EOL><INDENT>cij.emph("<STR_LIT>" % rcode, rcode)<EOL><DEDENT>return rcode<EOL>


if env():<EOL><INDENT>cij.err("<STR_LIT>")<EOL>return <NUM_LIT:1><EOL><DEDENT>args = []<EOL>if cij.ENV.get("<STR_LIT>"):<EOL><INDENT>args.append("<STR_LIT>")<EOL>args.append(cij.ENV.get("<STR_LIT>"))<EOL><DEDENT>if cij.ENV.get("<STR_LIT>"):<EOL><INDENT>args.append("<STR_LIT>")<EOL>args.append(cij.ENV.get("<STR_LIT>"))<EOL><DEDENT>if folder:<EOL><INDENT>args.append("<STR_LIT>")<EOL><DEDENT>target = "<STR_LIT>" % ("<STR_LIT:@>".join([cij.ENV.get("<STR_LIT>"), cij.ENV.get("<STR_LIT>")]), src)<EOL>wrapped = ["<STR_LIT>", "<STR_LIT:U+0020>".join(args), target, dst]<EOL>return cij.util.execute(wrapped, shell=True, echo=True)<EOL>


if env():<EOL><INDENT>cij.err("<STR_LIT>")<EOL>return <NUM_LIT:1><EOL><DEDENT>args = []<EOL>if cij.ENV.get("<STR_LIT>"):<EOL><INDENT>args.append("<STR_LIT>")<EOL>args.append(cij.ENV.get("<STR_LIT>"))<EOL><DEDENT>if cij.ENV.get("<STR_LIT>"):<EOL><INDENT>args.append("<STR_LIT>")<EOL>args.append(cij.ENV.get("<STR_LIT>"))<EOL><DEDENT>if folder:<EOL><INDENT>args.append("<STR_LIT>")<EOL><DEDENT>target = "<STR_LIT>" % ("<STR_LIT:@>".join([cij.ENV.get("<STR_LIT>"), cij.ENV.get("<STR_LIT>")]), dst)<EOL>wrapped = ["<STR_LIT>", "<STR_LIT:U+0020>".join(args), src, target]<EOL>return cij.util.execute(wrapped, shell=True, echo=True)<EOL>


def command(cmd, shell=True, echo=True, suffix=None):

if env():<EOL><INDENT>cij.err("<STR_LIT>")<EOL>return <NUM_LIT:1><EOL><DEDENT>prefix = []<EOL>if cij.ENV.get("<STR_LIT>") == "<STR_LIT:1>":<EOL><INDENT>prefix.append("<STR_LIT>")<EOL><DEDENT>if cij.ENV.get("<STR_LIT>"):<EOL><INDENT>prefix.append("<STR_LIT>")<EOL>prefix.append(cij.ENV.get("<STR_LIT>"))<EOL><DEDENT>prefix.append("<STR_LIT>")<EOL>args = []<EOL>if cij.ENV.get("<STR_LIT>"):<EOL><INDENT>args.append("<STR_LIT>")<EOL>args.append(cij.ENV.get("<STR_LIT>"))<EOL><DEDENT>if cij.ENV.get("<STR_LIT>"):<EOL><INDENT>args.append("<STR_LIT>")<EOL>args.append(cij.ENV.get("<STR_LIT>"))<EOL><DEDENT>args.append("<STR_LIT:@>".join([cij.ENV.get("<STR_LIT>"), cij.ENV.get("<STR_LIT>")]))<EOL>wrapped = prefix + args + ["<STR_LIT>" % "<STR_LIT:U+0020>".join(cmd)]<EOL>if suffix:<EOL><INDENT>wrapped += suffix<EOL><DEDENT>return cij.util.execute(wrapped, shell, echo)<EOL>

SSH: Run the given command over SSH as defined in environment


ssh = cij.env_to_dict(PREFIX, REQUIRED)<EOL>if "<STR_LIT>" in ssh:<EOL><INDENT>ssh["<STR_LIT>"] = cij.util.expand_path(ssh["<STR_LIT>"])<EOL><DEDENT>if cij.ENV.get("<STR_LIT>") is None:<EOL><INDENT>cij.ENV["<STR_LIT>"] = "<STR_LIT>"<EOL>cij.warn("<STR_LIT>" % (<EOL>cij.ENV.get("<STR_LIT>")<EOL>))<EOL><DEDENT>if cij.ENV.get("<STR_LIT>") is None:<EOL><INDENT>cij.ENV["<STR_LIT>"] = "<STR_LIT:1>"<EOL>cij.warn("<STR_LIT>" % (<EOL>cij.ENV.get("<STR_LIT>")<EOL>))<EOL><DEDENT>return <NUM_LIT:0><EOL>

Verify SSH variables and construct exported variables


field_path = field_name.split('<STR_LIT:.>')<EOL>if field_path[<NUM_LIT:0>] == '<STR_LIT>':<EOL><INDENT>context_index = <NUM_LIT:0><EOL>field_path.pop(<NUM_LIT:0>)<EOL><DEDENT>else:<EOL><INDENT>context_index = -<NUM_LIT:1><EOL>while field_path[<NUM_LIT:0>] == '<STR_LIT>':<EOL><INDENT>context_index -= <NUM_LIT:1><EOL>field_path.pop(<NUM_LIT:0>)<EOL><DEDENT><DEDENT>try:<EOL><INDENT>field_value = context_list[context_index]<EOL>while len(field_path):<EOL><INDENT>field = field_path.pop(<NUM_LIT:0>)<EOL>if isinstance(field_value, (list, tuple, ListModel)):<EOL><INDENT>if field.isdigit():<EOL><INDENT>field = int(field)<EOL><DEDENT>field_value = field_value[field]<EOL><DEDENT>elif isinstance(field_value, dict):<EOL><INDENT>try:<EOL><INDENT>field_value = field_value[field]<EOL><DEDENT>except KeyError:<EOL><INDENT>if field.isdigit():<EOL><INDENT>field = int(field)<EOL>field_value = field_value[field]<EOL><DEDENT>else:<EOL><INDENT>field_value = None<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>field_value = getattr(field_value, field)<EOL><DEDENT><DEDENT>return field_value<EOL><DEDENT>except (IndexError, AttributeError, KeyError, TypeError):<EOL><INDENT>return None<EOL><DEDENT>

Helper to get field value from string path.
String '<context>' is used to go up on context stack. It just
can be used at the beginning of path: <context>.<context>.field_name_1
On the other hand, '<root>' is used to start lookup from first item on context.


def __init__(self, comp_value=None, *args, **kwargs):

super(NotEqualTo, self).__init__(*args, **kwargs)<EOL>self.comp_value = comp_value<EOL>self.message_values.update({'<STR_LIT>': self.comp_value})<EOL>

:param comp_value: Static value to use on check


def error(self, error_code, value, **kwargs):

code = self.error_code_map.get(error_code, error_code)<EOL>try:<EOL><INDENT>message = Template(self.error_messages[code])<EOL><DEDENT>except KeyError:<EOL><INDENT>message = Template(self.error_messages[error_code])<EOL><DEDENT>placeholders = {"<STR_LIT:value>": self.hidden_value if self.hidden else value}<EOL>placeholders.update(kwargs)<EOL>placeholders.update(self.message_values)<EOL>self.messages[code] = message.safe_substitute(placeholders)<EOL>

Helper to add error to messages field. It fills placeholder with extra call parameters
or values from message_value map.

:param error_code: Error code to use
:rparam error_code: str
:param value: Value checked
:param kwargs: Map of values to use in placeholders


@wraps(func)<EOL>def wrapped(request, *args, **kwargs):<EOL><INDENT>if '<STR_LIT:date>' in request.GET and request.GET['<STR_LIT:date>'] == '<STR_LIT>':<EOL><INDENT>raise Http404("<STR_LIT>")<EOL><DEDENT>elif '<STR_LIT:date>' not in request.GET:<EOL><INDENT>date = datetime.today()<EOL>return func(request, date)<EOL><DEDENT>else:<EOL><INDENT>date = tuple(int(intValue) for intValue in request.GET['<STR_LIT:date>'].split('<STR_LIT:->'))<EOL>if len(date) == <NUM_LIT:3>:<EOL><INDENT>date = datetime(*date)<EOL><DEDENT>elif len(date) == <NUM_LIT:2>:<EOL><INDENT>date = datetime(*date, day = <NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>date = datetime(*date, month = <NUM_LIT:1>, day = <NUM_LIT:1>)<EOL><DEDENT>return func(request, date)<EOL><DEDENT><DEDENT>return wrapped<EOL>

An decorator checking whether date parameter is passing in or not. If not, default date value is all PTT data.
            Else, return PTT data with right date.
    Args:
            func: function you want to decorate.
            request: WSGI request parameter getten from django.

    Returns:
            date:
                    a datetime variable, you can only give year, year + month or year + month + day, three type.
                    The missing part would be assigned default value 1 (for month is Jan, for day is 1).


def _dec(function):<EOL><INDENT>@wraps(function)<EOL>def _wrap(request, *args, **kwargs):<EOL><INDENT>for i in strList:<EOL><INDENT>if i not in request.GET:<EOL><INDENT>raise Http404("<STR_LIT>")<EOL><DEDENT><DEDENT>return function(request, *args, **kwargs)<EOL><DEDENT>return _wrap<EOL><DEDENT>return _dec<EOL>

An decorator checking whether queryString key is valid or not
    Args:
            str: allowed queryString key

    Returns:
            if contains invalid queryString key, it will raise exception.


fields = self._all_fields()<EOL>ctx = UnpackContext(self, fields, buffer)<EOL>for field in fields:<EOL><INDENT>try:<EOL><INDENT>if field.unpack_if.deref(ctx):<EOL><INDENT>for prev_field in field.unpack_after:<EOL><INDENT>prev_field.unpack_value_ref.deref(ctx)<EOL><DEDENT>field.unpack_value_ref.deref(ctx)<EOL><DEDENT>else:<EOL><INDENT>setattr(self, field.attr_name(), None)<EOL><DEDENT><DEDENT>except:<EOL><INDENT>raise chain_exceptions(InstructBufferError("<STR_LIT>", ctx, type(self), field.attr_name()))<EOL><DEDENT><DEDENT>return self.calc_byte_size(ctx)<EOL>

Unpacks the object's fields from buffer.


fields = self._all_fields()<EOL>ctx = PackContext(self, fields)<EOL>for field in fields:<EOL><INDENT>if field.pack_if.deref(ctx):<EOL><INDENT>try:<EOL><INDENT>ctx.output_buffer.set(field.pack_ref.deref(ctx), field.pack_absolute_position_ref.deref(ctx))<EOL><DEDENT>except:<EOL><INDENT>raise chain_exceptions(InstructBufferError("<STR_LIT>", ctx, type(self),<EOL>field.attr_name()))<EOL><DEDENT><DEDENT><DEDENT>result = bytearray(ctx.output_buffer.get())<EOL>static_byte_size = type(self).byte_size<EOL>if static_byte_size:<EOL><INDENT>static_byte_size = int(math.ceil(static_byte_size))<EOL>assert len(result) <= static_byte_size,("<STR_LIT>" +<EOL>"<STR_LIT>").format(type(self), len(result),<EOL>static_byte_size)<EOL>if len(result) < static_byte_size:<EOL><INDENT>result += bytearray(static_byte_size - len(result))<EOL><DEDENT><DEDENT>return result<EOL>

Packs the object and returns a buffer representing the packed object.


return slice(self.start, self.stop, <NUM_LIT:1>)<EOL>

:returns: a slice object from start to stop
:rtype: slice


remaining_bytes = bytes<EOL>for r in self:<EOL><INDENT>if r.is_open() or r.byte_length() >= remaining_bytes:<EOL><INDENT>return r.start + remaining_bytes<EOL><DEDENT>else:<EOL><INDENT>remaining_bytes -= r.byte_length()<EOL><DEDENT><DEDENT>assert False, "<STR_LIT>".format(bytes, self)<EOL>

Maps `bytes` length to a sequence's offset. For example, if we do byte_offset(5) and our list of sequences is
[(0, 2), (10, 11), (40, 45)] then the returned value will be 42.
Note that `bytes` must be <= byte_length().
:returns: actual offset in one of the sequences in the range for request byte length.
:rtype: int or float


return self.start <= point and (self.stop is None or self.stop > point)<EOL>

:param point: point to check if contained in range
:type point: int or float
:returns: True if the range contains `point`
:rtype: bool


m = <NUM_LIT:0><EOL>for r in self:<EOL><INDENT>if r.is_open():<EOL><INDENT>return None<EOL><DEDENT>m = max(m, r.stop)<EOL><DEDENT>return m<EOL>

:returns: maximum stop in list or None if there's at least one open range
:type: int, float or None


def create_from_string(self, string, context=EMPTY_CONTEXT, *args, **kwargs):

if not PY2 and not isinstance(string, bytes):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>io = StringIO(string)<EOL>instance = self.create_from_stream(io, context, *args, **kwargs)<EOL>io.close()<EOL>return instance<EOL>

Deserializes a new instance from a string.
This is a convenience method that creates a StringIO object and calls create_instance_from_stream().


try:<EOL><INDENT>obj_repr = repr(obj)<EOL><DEDENT>except:<EOL><INDENT>obj_repr = "<STR_LIT>".format(type(obj), id(obj))<EOL><DEDENT>return obj_repr<EOL>

Returns a repr of an object and falls back to a minimal representation of type and ID if the call to repr raised
    an error.

    :param obj: object to safe repr
    :returns: repr string or '(type<id> repr error)' string
    :rtype: str


def keep_kwargs_partial(func, *args, **keywords):

def newfunc(*fargs, **fkeywords):<EOL><INDENT>newkeywords = fkeywords.copy()<EOL>newkeywords.update(keywords)<EOL>return func(*(args + fargs), **newkeywords)<EOL><DEDENT>newfunc.func = func<EOL>newfunc.args = args<EOL>newfunc.keywords = keywords<EOL>return newfunc<EOL>

Like functools.partial but instead of using the new kwargs, keeps the old ones.


try:<EOL><INDENT>im = _read_image(file_path)<EOL><DEDENT>except (IOError, IndexError, TypeError, AttributeError) as e:<EOL><INDENT>logger = logging.getLogger(__name__)<EOL>logger.error("<STR_LIT>", file_path, e)<EOL><DEDENT>else:<EOL><INDENT>width, height = im.size<EOL>return {<EOL>'<STR_LIT:width>': width,<EOL>'<STR_LIT>': height<EOL>}<EOL><DEDENT>


logger = logging.getLogger(__name__)<EOL>simple = {}<EOL>for tag in ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>if tag in data:<EOL><INDENT>if isinstance(data[tag], tuple):<EOL><INDENT>simple[tag] = data[tag][<NUM_LIT:0>].strip()<EOL><DEDENT>else:<EOL><INDENT>simple[tag] = data[tag].strip()<EOL><DEDENT><DEDENT><DEDENT>if '<STR_LIT>' in data:<EOL><INDENT>fnumber = data['<STR_LIT>']<EOL>try:<EOL><INDENT>simple['<STR_LIT>'] = float(fnumber[<NUM_LIT:0>]) / fnumber[<NUM_LIT:1>]<EOL><DEDENT>except Exception:<EOL><INDENT>logger.debug('<STR_LIT>', fnumber, exc_info=True)<EOL><DEDENT><DEDENT>if '<STR_LIT>' in data:<EOL><INDENT>focal = data['<STR_LIT>']<EOL>try:<EOL><INDENT>simple['<STR_LIT>'] = round(float(focal[<NUM_LIT:0>]) / focal[<NUM_LIT:1>])<EOL><DEDENT>except Exception:<EOL><INDENT>logger.debug('<STR_LIT>', focal,<EOL>exc_info=True)<EOL><DEDENT><DEDENT>if '<STR_LIT>' in data:<EOL><INDENT>exptime = data['<STR_LIT>']<EOL>if isinstance(exptime, tuple):<EOL><INDENT>try:<EOL><INDENT>simple['<STR_LIT>'] = str(fractions.Fraction(exptime[<NUM_LIT:0>],<EOL>exptime[<NUM_LIT:1>]))<EOL><DEDENT>except ZeroDivisionError:<EOL><INDENT>logger.info('<STR_LIT>', exptime)<EOL><DEDENT><DEDENT>elif isinstance(exptime, int):<EOL><INDENT>simple['<STR_LIT>'] = str(exptime)<EOL><DEDENT>else:<EOL><INDENT>logger.info('<STR_LIT>', exptime)<EOL><DEDENT><DEDENT>if data.get('<STR_LIT>'):<EOL><INDENT>simple['<STR_LIT>'] = data['<STR_LIT>']<EOL><DEDENT>if '<STR_LIT>' in data:<EOL><INDENT>date = data['<STR_LIT>'].rsplit('<STR_LIT:\x00>')[<NUM_LIT:0>]<EOL>try:<EOL><INDENT>simple['<STR_LIT>'] = datetime.strptime(date, '<STR_LIT>')<EOL>simple['<STR_LIT>'] = simple['<STR_LIT>'].strftime(datetime_format)<EOL><DEDENT>except (ValueError, TypeError) as e:<EOL><INDENT>logger.info('<STR_LIT>', e)<EOL><DEDENT><DEDENT>if '<STR_LIT>' in data:<EOL><INDENT>info = data['<STR_LIT>']<EOL>lat_info = info.get('<STR_LIT>')<EOL>lon_info = info.get('<STR_LIT>')<EOL>lat_ref_info = info.get('<STR_LIT>')<EOL>lon_ref_info = info.get('<STR_LIT>')<EOL>if lat_info and lon_info and lat_ref_info and lon_ref_info:<EOL><INDENT>try:<EOL><INDENT>lat = dms_to_degrees(lat_info)<EOL>lon = dms_to_degrees(lon_info)<EOL><DEDENT>except (ZeroDivisionError, ValueError, TypeError):<EOL><INDENT>logger.info('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>simple['<STR_LIT>'] = {<EOL>'<STR_LIT>': - lat if lat_ref_info != '<STR_LIT:N>' else lat,<EOL>'<STR_LIT>': - lon if lon_ref_info != '<STR_LIT:E>' else lon,<EOL>}<EOL><DEDENT><DEDENT><DEDENT>return simple<EOL>

Make a simplified version with common tags from raw EXIF data.


logger = logging.getLogger(__name__)<EOL>img = _read_image(filename)<EOL>try:<EOL><INDENT>exif = img._getexif() or {}<EOL><DEDENT>except ZeroDivisionError:<EOL><INDENT>logger.warning('<STR_LIT>')<EOL>return None<EOL><DEDENT>data = {TAGS.get(tag, tag): value for tag, value in exif.items()}<EOL>if '<STR_LIT>' in data:<EOL><INDENT>try:<EOL><INDENT>data['<STR_LIT>'] = {GPSTAGS.get(tag, tag): value<EOL>for tag, value in data['<STR_LIT>'].items()}<EOL><DEDENT>except AttributeError:<EOL><INDENT>logger = logging.getLogger(__name__)<EOL>logger.info('<STR_LIT>')<EOL>del data['<STR_LIT>']<EOL><DEDENT><DEDENT>return data<EOL>


logger = logging.getLogger(name)<EOL>logger.setLevel(level)<EOL>try:<EOL><INDENT>if os.isatty(sys.stdout.fileno()) andnot sys.platform.startswith('<STR_LIT>'):<EOL><INDENT>formatter = ColoredFormatter()<EOL><DEDENT>elif level == logging.DEBUG:<EOL><INDENT>formatter = Formatter('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>formatter = Formatter('<STR_LIT>')<EOL><DEDENT><DEDENT>except Exception:<EOL><INDENT>formatter = Formatter('<STR_LIT>')<EOL><DEDENT>handler = logging.StreamHandler()<EOL>handler.setFormatter(formatter)<EOL>logger.addHandler(handler)<EOL>

Logging config

    Set the level and create a more detailed formatter for debug mode.


if not hasattr(album.gallery, "<STR_LIT>"):<EOL><INDENT>_restore_cache(album.gallery)<EOL><DEDENT>cache = album.gallery.exifCache<EOL>for media in album.medias:<EOL><INDENT>if media.type == "<STR_LIT:image>":<EOL><INDENT>key = os.path.join(media.path, media.filename)<EOL>if key in cache:<EOL><INDENT>media.exif = cache[key]<EOL><DEDENT><DEDENT><DEDENT>

Loads the exif data of all images in an album from cache


nomediapath = os.path.join(album.src_path, "<STR_LIT>")<EOL>if os.path.isfile(nomediapath):<EOL><INDENT>if os.path.getsize(nomediapath) == <NUM_LIT:0>:<EOL><INDENT>logger.info("<STR_LIT>"<EOL>"<STR_LIT>", album.name)<EOL>_remove_albums_with_subdirs(album.gallery.albums, [album.path])<EOL>try:<EOL><INDENT>os.rmdir(album.dst_path)<EOL><DEDENT>except OSError as e:<EOL><INDENT>pass<EOL><DEDENT>album.subdirs = []<EOL>album.medias = []<EOL><DEDENT>else:<EOL><INDENT>with open(nomediapath, "<STR_LIT:r>") as nomediaFile:<EOL><INDENT>logger.info("<STR_LIT>"<EOL>"<STR_LIT>", album.name)<EOL>ignored = nomediaFile.read().split("<STR_LIT:\n>")<EOL>album.medias = [media for media in album.medias<EOL>if media.src_filename not in ignored]<EOL>album.subdirs = [dirname for dirname in album.subdirs<EOL>if dirname not in ignored]<EOL>_remove_albums_with_subdirs(album.gallery.albums,<EOL>ignored, album.path + os.path.sep)<EOL><DEDENT><DEDENT><DEDENT>

Removes all filtered Media and subdirs from an Album


assert opacity >= <NUM_LIT:0> and opacity <= <NUM_LIT:1><EOL>if im.mode != '<STR_LIT>':<EOL><INDENT>im = im.convert('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>im = im.copy()<EOL><DEDENT>alpha = im.split()[<NUM_LIT:3>]<EOL>alpha = ImageEnhance.Brightness(alpha).enhance(opacity)<EOL>im.putalpha(alpha)<EOL>return im<EOL>


@main.command()<EOL>@argument('<STR_LIT>', default='<STR_LIT>')<EOL>@option('<STR_LIT>', '<STR_LIT>', help="<STR_LIT>", default=<NUM_LIT>)<EOL>@option('<STR_LIT:-c>', '<STR_LIT>', default=_DEFAULT_CONFIG_FILE,<EOL>show_default=True, help='<STR_LIT>')<EOL>def serve(destination, port, config):

if os.path.exists(destination):<EOL><INDENT>pass<EOL><DEDENT>elif os.path.exists(config):<EOL><INDENT>settings = read_settings(config)<EOL>destination = settings.get('<STR_LIT>')<EOL>if not os.path.exists(destination):<EOL><INDENT>sys.stderr.write("<STR_LIT>"<EOL>"<STR_LIT>".format(destination))<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>sys.stderr.write("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>.format(destination=destination, config=config))<EOL>sys.exit(<NUM_LIT:2>)<EOL><DEDENT>print('<STR_LIT>'.format(destination))<EOL>os.chdir(destination)<EOL>Handler = server.SimpleHTTPRequestHandler<EOL>httpd = socketserver.TCPServer(("<STR_LIT>", port), Handler, False)<EOL>print("<STR_LIT>".format(port))<EOL>try:<EOL><INDENT>httpd.allow_reuse_address = True<EOL>httpd.server_bind()<EOL>httpd.server_activate()<EOL>httpd.serve_forever()<EOL><DEDENT>except KeyboardInterrupt:<EOL><INDENT>print('<STR_LIT>')<EOL><DEDENT>


settings = _DEFAULT_CONFIG.copy()<EOL>settings.update(kwargs)<EOL>return settings<EOL>

Create a new default setting copy and initialize it with kwargs.


logger = logging.getLogger(__name__)<EOL>logger.info("<STR_LIT>")<EOL>settings = _DEFAULT_CONFIG.copy()<EOL>if filename:<EOL><INDENT>logger.debug("<STR_LIT>", filename)<EOL>settings_path = os.path.dirname(filename)<EOL>tempdict = {}<EOL>with open(filename) as f:<EOL><INDENT>code = compile(f.read(), filename, '<STR_LIT>')<EOL>exec(code, tempdict)<EOL><DEDENT>settings.update((k, v) for k, v in tempdict.items()<EOL>if k not in ['<STR_LIT>'])<EOL>paths = ['<STR_LIT:source>', '<STR_LIT>', '<STR_LIT>']<EOL>if os.path.isdir(join(settings_path, settings['<STR_LIT>'])) andos.path.isdir(join(settings_path, settings['<STR_LIT>'],<EOL>'<STR_LIT>')):<EOL><INDENT>paths.append('<STR_LIT>')<EOL><DEDENT>for p in paths:<EOL><INDENT>path = settings[p]<EOL>if path and not isabs(path):<EOL><INDENT>settings[p] = abspath(normpath(join(settings_path, path)))<EOL>logger.debug("<STR_LIT>", p, path, settings[p])<EOL><DEDENT><DEDENT><DEDENT>for key in ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>w, h = settings[key]<EOL>if h > w:<EOL><INDENT>settings[key] = (h, w)<EOL>logger.warning("<STR_LIT>"<EOL>"<STR_LIT>", key)<EOL><DEDENT><DEDENT>if not settings['<STR_LIT>']:<EOL><INDENT>logger.info('<STR_LIT>')<EOL><DEDENT>logger.debug('<STR_LIT>', pformat(settings, width=<NUM_LIT>))<EOL>return settings<EOL>

Read settings from a config file in the source_dir root.


page = self.template.render(**self.generate_context(album))<EOL>output_file = os.path.join(album.dst_path, album.output_file)<EOL>with open(output_file, '<STR_LIT:w>', encoding='<STR_LIT:utf-8>') as f:<EOL><INDENT>f.write(page)<EOL><DEDENT>


from . import __url__ as sigal_link<EOL>self.logger.info("<STR_LIT>", album)<EOL>return {<EOL>'<STR_LIT>': album,<EOL>'<STR_LIT>': self.index_title,<EOL>'<STR_LIT>': self.settings,<EOL>'<STR_LIT>': sigal_link,<EOL>'<STR_LIT>': {'<STR_LIT:name>': os.path.basename(self.theme),<EOL>'<STR_LIT:url>': url_from_path(os.path.relpath(self.theme_path,<EOL>album.dst_path))},<EOL>}<EOL>

Generate the context dict for the given path.


if os.sep != '<STR_LIT:/>':<EOL><INDENT>path = '<STR_LIT:/>'.join(path.split(os.sep))<EOL><DEDENT>return quote(path)<EOL>

Transform path to url, converting backslashes to slashes if needed.


return ext in VIDEO_MIMES.keys()<EOL>

Checks if ext is a supported HTML5 video.


def check_subprocess(cmd, source, outname):

logger = logging.getLogger(__name__)<EOL>try:<EOL><INDENT>res = subprocess.run(cmd, stdout=subprocess.PIPE,<EOL>stderr=subprocess.PIPE)<EOL><DEDENT>except KeyboardInterrupt:<EOL><INDENT>logger.debug('<STR_LIT>', outname)<EOL>if os.path.isfile(outname):<EOL><INDENT>os.remove(outname)<EOL><DEDENT>raise<EOL><DEDENT>if res.returncode:<EOL><INDENT>logger.debug('<STR_LIT>', res.stdout.decode('<STR_LIT:utf8>'))<EOL>logger.debug('<STR_LIT>', res.stderr.decode('<STR_LIT:utf8>'))<EOL>if os.path.isfile(outname):<EOL><INDENT>logger.debug('<STR_LIT>', outname)<EOL>os.remove(outname)<EOL><DEDENT>raise SubprocessException('<STR_LIT>' + source)<EOL><DEDENT>

Run the command to resize the video and remove the output file if the
    processing fails.


res = subprocess.run([converter, '<STR_LIT>', source], stderr=subprocess.PIPE)<EOL>stderr = res.stderr.decode('<STR_LIT:utf8>')<EOL>pattern = re.compile(r'<STR_LIT>')<EOL>match = pattern.search(stderr)<EOL>rot_pattern = re.compile(r'<STR_LIT>')<EOL>rot_match = rot_pattern.search(stderr)<EOL>if match:<EOL><INDENT>x, y = int(match.groups()[<NUM_LIT:0>]), int(match.groups()[<NUM_LIT:1>])<EOL><DEDENT>else:<EOL><INDENT>x = y = <NUM_LIT:0><EOL><DEDENT>if rot_match:<EOL><INDENT>x, y = y, x<EOL><DEDENT>return x, y<EOL>


def generate_thumbnail(source, outname, box, delay, fit=True, options=None,<EOL>converter='<STR_LIT>'):

logger = logging.getLogger(__name__)<EOL>tmpfile = outname + "<STR_LIT>"<EOL>cmd = [converter, '<STR_LIT>', source, '<STR_LIT>', '<STR_LIT>', '<STR_LIT:1>',<EOL>'<STR_LIT>', delay, '<STR_LIT>', '<STR_LIT:1>', '<STR_LIT>', tmpfile]<EOL>logger.debug('<STR_LIT>', '<STR_LIT:U+0020>'.join(cmd))<EOL>check_subprocess(cmd, source, outname)<EOL>image.generate_thumbnail(tmpfile, outname, box, fit=fit, options=options)<EOL>os.unlink(tmpfile)<EOL>

Create a thumbnail image for the video source, based on ffmpeg.


for media in self.medias:<EOL><INDENT>if media.type == '<STR_LIT:image>':<EOL><INDENT>yield media<EOL><DEDENT><DEDENT>

List of images (:class:`~sigal.gallery.Image`).


for media in self.medias:<EOL><INDENT>if media.type == '<STR_LIT>':<EOL><INDENT>yield media<EOL><DEDENT><DEDENT>

List of videos (:class:`~sigal.gallery.Video`).


if self._thumbnail:<EOL><INDENT>return self._thumbnail<EOL><DEDENT>thumbnail = self.meta.get('<STR_LIT>', ['<STR_LIT>'])[<NUM_LIT:0>]<EOL>if thumbnail and isfile(join(self.src_path, thumbnail)):<EOL><INDENT>self._thumbnail = url_from_path(join(<EOL>self.name, get_thumb(self.settings, thumbnail)))<EOL>self.logger.debug("<STR_LIT>", self, self._thumbnail)<EOL>return self._thumbnail<EOL><DEDENT>else:<EOL><INDENT>for f in self.medias:<EOL><INDENT>ext = splitext(f.filename)[<NUM_LIT:1>]<EOL>if ext.lower() in self.settings['<STR_LIT>']:<EOL><INDENT>size = f.size<EOL>if size is None:<EOL><INDENT>size = get_size(f.src_path)<EOL><DEDENT>if size['<STR_LIT:width>'] > size['<STR_LIT>']:<EOL><INDENT>self._thumbnail = (url_quote(self.name) + '<STR_LIT:/>' +<EOL>f.thumbnail)<EOL>self.logger.debug(<EOL>"<STR_LIT>",<EOL>self, self._thumbnail)<EOL>return self._thumbnail<EOL><DEDENT><DEDENT><DEDENT>if not self._thumbnail and self.medias:<EOL><INDENT>for media in self.medias:<EOL><INDENT>if media.thumbnail is not None:<EOL><INDENT>self._thumbnail = (url_quote(self.name) + '<STR_LIT:/>' +<EOL>media.thumbnail)<EOL>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>self.logger.warning("<STR_LIT>", self)<EOL>return None<EOL><DEDENT>self.logger.debug("<STR_LIT>",<EOL>self, self._thumbnail)<EOL>return self._thumbnail<EOL><DEDENT>if not self._thumbnail:<EOL><INDENT>for path, album in self.gallery.get_albums(self.path):<EOL><INDENT>if album.thumbnail:<EOL><INDENT>self._thumbnail = (url_quote(self.name) + '<STR_LIT:/>' +<EOL>album.thumbnail)<EOL>self.logger.debug(<EOL>"<STR_LIT>",<EOL>self, self._thumbnail)<EOL>return self._thumbnail<EOL><DEDENT><DEDENT><DEDENT><DEDENT>self.logger.error('<STR_LIT>', self)<EOL>return None<EOL>


root_path = self.path if self.path != '<STR_LIT:.>' else '<STR_LIT>'<EOL>return [self.gallery.albums[join(root_path, path)]<EOL>for path in self.subdirs]<EOL>

List of :class:`~sigal.gallery.Album` objects for each
        sub-directory.


return any(image.has_location() for image in self.images)<EOL>

Check if we have at least one photo with GPS location in the album


self.description = '<STR_LIT>'<EOL>self.meta = {}<EOL>self.title = '<STR_LIT>'<EOL>descfile = splitext(self.src_path)[<NUM_LIT:0>] + '<STR_LIT>'<EOL>if isfile(descfile):<EOL><INDENT>meta = read_markdown(descfile)<EOL>for key, val in meta.items():<EOL><INDENT>setattr(self, key, val)<EOL><DEDENT><DEDENT>

Get image metadata from filename.md: title, description, meta.


if self.big is not None:<EOL><INDENT>return url_from_path(self.big)<EOL><DEDENT>


if self.path == '<STR_LIT:.>':<EOL><INDENT>return []<EOL><DEDENT>path = self.path<EOL>breadcrumb = [((self.url_ext or '<STR_LIT:.>'), self.title)]<EOL>while True:<EOL><INDENT>path = os.path.normpath(os.path.join(path, '<STR_LIT:..>'))<EOL>if path == '<STR_LIT:.>':<EOL><INDENT>break<EOL><DEDENT>url = (url_from_path(os.path.relpath(path, self.path)) + '<STR_LIT:/>' +<EOL>self.url_ext)<EOL>breadcrumb.append((url, self.gallery.albums[path].title))<EOL><DEDENT>breadcrumb.reverse()<EOL>return breadcrumb<EOL>

List of ``(url, title)`` tuples defining the current breadcrumb
        path.


if self.settings['<STR_LIT>']:<EOL><INDENT>s = self.settings<EOL>if s['<STR_LIT>']:<EOL><INDENT>return self.filename<EOL><DEDENT>orig_path = join(s['<STR_LIT>'], self.path, s['<STR_LIT>'])<EOL>check_or_create_dir(orig_path)<EOL>big_path = join(orig_path, self.src_filename)<EOL>if not isfile(big_path):<EOL><INDENT>copy(self.src_path, big_path, symlink=s['<STR_LIT>'],<EOL>rellink=self.settings['<STR_LIT>'])<EOL><DEDENT>return join(s['<STR_LIT>'], self.src_filename)<EOL><DEDENT>

Path to the original image, if ``keep_orig`` is set (relative to the
        album directory). Copy the file if needed.


def displayOutdated(modules, dependency_specs, use_colours):

if use_colours:<EOL><INDENT>DIM    = colorama.Style.DIM       <EOL>NORMAL = colorama.Style.NORMAL    <EOL>BRIGHT = colorama.Style.BRIGHT    <EOL>YELLOW = colorama.Fore.YELLOW     <EOL>RED    = colorama.Fore.RED        <EOL>GREEN  = colorama.Fore.GREEN      <EOL>RESET  = colorama.Style.RESET_ALL <EOL><DEDENT>else:<EOL><INDENT>DIM = BRIGHT = YELLOW = RED = GREEN = RESET = u'<STR_LIT>'<EOL><DEDENT>status = <NUM_LIT:0><EOL>from yotta.lib import access<EOL>from yotta.lib import access_common<EOL>from yotta.lib import sourceparse<EOL>for name, m in modules.items():<EOL><INDENT>if m.isTestDependency():<EOL><INDENT>continue<EOL><DEDENT>try:<EOL><INDENT>latest_v = access.latestSuitableVersion(name, '<STR_LIT:*>', registry='<STR_LIT>', quiet=True)<EOL><DEDENT>except access_common.Unavailable as e:<EOL><INDENT>latest_v = None<EOL><DEDENT>if not m:<EOL><INDENT>m_version = u'<STR_LIT:U+0020>' + RESET + BRIGHT + RED + u"<STR_LIT>" + RESET<EOL><DEDENT>else:<EOL><INDENT>m_version = DIM + u'<STR_LIT>' % (m.version)<EOL><DEDENT>if not latest_v:<EOL><INDENT>print(u'<STR_LIT>' % (RED, name, m_version, NORMAL, RESET))<EOL>status = <NUM_LIT:2><EOL>continue<EOL><DEDENT>elif not m or m.version < latest_v:<EOL><INDENT>update_prevented_by = '<STR_LIT>'<EOL>if m:<EOL><INDENT>specs_preventing_update = [<EOL>x for x in dependency_specs<EOL>if x.name == name and not<EOL>sourceparse.parseSourceURL(x.nonShrinkwrappedVersionReq()).semanticSpecMatches(latest_v)<EOL>]<EOL>shrinkwrap_prevents_update = [<EOL>x for x in dependency_specs<EOL>if x.name == name and x.isShrinkwrapped() and not<EOL>sourceparse.parseSourceURL(x.versionReq()).semanticSpecMatches(latest_v)<EOL>]<EOL>if len(specs_preventing_update):<EOL><INDENT>update_prevented_by = '<STR_LIT>' % (<EOL>'<STR_LIT:U+002CU+0020>'.join(['<STR_LIT>' % (x.version_req, x.specifying_module) for x in specs_preventing_update])<EOL>)<EOL><DEDENT>if len(shrinkwrap_prevents_update):<EOL><INDENT>update_prevented_by += '<STR_LIT>'<EOL><DEDENT>if m.version.major() < latest_v.major():<EOL><INDENT>colour = GREEN<EOL><DEDENT>elif m.version.minor() < latest_v.minor():<EOL><INDENT>colour = YELLOW<EOL><DEDENT>else:<EOL><INDENT>colour = RED<EOL><DEDENT><DEDENT>else:<EOL><INDENT>colour = RED<EOL><DEDENT>print(u'<STR_LIT>' % (name, m_version, RESET, colour, latest_v.version, update_prevented_by, RESET))<EOL>if not status:<EOL><INDENT>status = <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>return status<EOL>

print information about outdated modules,
        return 0 if there is nothing to be done and nonzero otherwise


try:<EOL><INDENT>parseSourceURL(spec_or_source_url)<EOL>return True<EOL><DEDENT>except InvalidVersionSpec:<EOL><INDENT>return False<EOL><DEDENT>

Check if the specified version source URL (or version spec), can be
        parsed successfully.


name, spec = _getNonRegistryRef(source_url)<EOL>if spec:<EOL><INDENT>return spec<EOL><DEDENT>try:<EOL><INDENT>url_is_spec = version.Spec(source_url)<EOL><DEDENT>except ValueError:<EOL><INDENT>url_is_spec = None<EOL><DEDENT>if url_is_spec is not None:<EOL><INDENT>return VersionSource('<STR_LIT>', '<STR_LIT>', source_url)<EOL><DEDENT>raise InvalidVersionSpec("<STR_LIT>" % (source_url))<EOL>

Parse the specified version source URL (or version spec), and return an
        instance of VersionSource


def __init__(self, version_string, url=None):

super(Version, self).__init__()<EOL>self.url = url<EOL>version_string = str(version_string.strip())<EOL>self.version = None<EOL>if version_string.startswith('<STR_LIT:v>') or version_string.startswith('<STR_LIT:=>'):<EOL><INDENT>self.version = semantic_version.Version(version_string[<NUM_LIT:1>:], partial=False)<EOL><DEDENT>elif not version_string:<EOL><INDENT>self.version = TipVersion()<EOL><DEDENT>else:<EOL><INDENT>self.version = semantic_version.Version(version_string, partial=False)<EOL><DEDENT>self.url = url<EOL>

Wrap the semantic_version Version class so that we can represent
            'tip' versions as well as specific versions, and store an optional
            URL that can represent the location from which we can retrieve this
            version.

            Also add some useful methods for manipulating versions.


<EOL>if os.path.split(program)[<NUM_LIT:0>]:<EOL><INDENT>if os.path.exists(program) and os.access(program, os.X_OK):<EOL><INDENT>return program<EOL><DEDENT><DEDENT>else:<EOL><INDENT>for path in os.environ['<STR_LIT>'].split(os.pathsep):<EOL><INDENT>progpath = os.path.join(path, program)<EOL>if os.path.exists(progpath) and os.access(progpath, os.X_OK):<EOL><INDENT>return progpath<EOL><DEDENT><DEDENT><DEDENT>return None<EOL>

look for "program" in PATH, and return the path to it, or None if it
        was not found


def wrapped_fn(*args, **kwargs):<EOL><INDENT>q = multiprocessing.Queue()<EOL>p = multiprocessing.Process(target=_dropPrivsReturnViaQueue, args=(q, fn, args, kwargs))<EOL>p.start()<EOL>r = None<EOL>e = None<EOL>while True:<EOL><INDENT>msg = q.get()<EOL>if msg[<NUM_LIT:0>] == '<STR_LIT>':<EOL><INDENT>r = msg[<NUM_LIT:1>]<EOL><DEDENT>if msg[<NUM_LIT:0>] == '<STR_LIT>':<EOL><INDENT>e = msg[<NUM_LIT:1>](msg[<NUM_LIT:2>])<EOL><DEDENT>if msg[<NUM_LIT:0>] == '<STR_LIT>':<EOL><INDENT>if e is not None:<EOL><INDENT>raise e <EOL><DEDENT>return r<EOL><DEDENT><DEDENT><DEDENT>return wrapped_fn<EOL>

decorator to drop su/sudo privilages before running a function on
        unix/linux.
        The *real* uid is modified, so privileges are permanently dropped for
        the process. (i.e. make sure you don't need to do

        If there is a SUDO_UID environment variable, then we drop to that,
        otherwise we drop to nobody.


def satisfyVersionByInstalling(name, version_required, working_directory, type='<STR_LIT>', inherit_shrinkwrap=None):

v = latestSuitableVersion(name, version_required, _registryNamespaceForType(type))<EOL>install_into = os.path.join(working_directory, name)<EOL>return _satisfyVersionByInstallingVersion(<EOL>name, version_required, install_into, v, type=type, inherit_shrinkwrap = inherit_shrinkwrap<EOL>)<EOL>

installs and returns a Component/Target for the specified name+version
        requirement, into a subdirectory of `working_directory'


def _satisfyVersionByInstallingVersion(name, version_required, working_directory, version, type='<STR_LIT>', inherit_shrinkwrap=None):

assert(version)<EOL>logger.info('<STR_LIT>', version)<EOL>version.unpackInto(working_directory)<EOL>r = _clsForType(type)(working_directory, inherit_shrinkwrap = inherit_shrinkwrap)<EOL>if not r:<EOL><INDENT>raise Exception(<EOL>'<STR_LIT>' % (name, version_required, type)<EOL>)<EOL><DEDENT>if name != r.getName():<EOL><INDENT>raise Exception('<STR_LIT>' % (<EOL>type, name, version_required, r.getName()<EOL>))<EOL><DEDENT>r.runScript('<STR_LIT>')<EOL>return r<EOL>

installs and returns a Component/Target for the specified version requirement into
        'working_directory' using the provided remote version object.
        This function is not normally called via `satisfyVersionByInstalling',
        which looks up a suitable remote version object.


def satisfyVersionFromSearchPaths(name, version_required, search_paths, update=False, type='<STR_LIT>', inherit_shrinkwrap=None):

<EOL>from yotta.lib import pack<EOL>v = None<EOL>try:<EOL><INDENT>sv = sourceparse.parseSourceURL(version_required)<EOL><DEDENT>except ValueError as e:<EOL><INDENT>logging.error(e)<EOL>return None<EOL><DEDENT>try:<EOL><INDENT>local_version = searchPathsFor(<EOL>name,<EOL>sv.semanticSpec(),<EOL>search_paths,<EOL>type,<EOL>inherit_shrinkwrap = inherit_shrinkwrap<EOL>)<EOL><DEDENT>except pack.InvalidDescription as e:<EOL><INDENT>logger.error(e)<EOL>return None<EOL><DEDENT>logger.debug("<STR_LIT>" % (('<STR_LIT>', '<STR_LIT>')[not local_version], name))<EOL>if local_version:<EOL><INDENT>if update and not local_version.installedLinked():<EOL><INDENT>v = latestSuitableVersion(name, version_required, registry=_registryNamespaceForType(type))<EOL>if local_version:<EOL><INDENT>local_version.setLatestAvailable(v)<EOL><DEDENT><DEDENT>if local_version.installedLinked() or not local_version.outdated():<EOL><INDENT>logger.debug("<STR_LIT>" % local_version.path)<EOL>if name != local_version.getName():<EOL><INDENT>raise Exception('<STR_LIT>' % (<EOL>local_version.getName(), name, local_version.path<EOL>))<EOL><DEDENT>return local_version<EOL><DEDENT>logger.info('<STR_LIT>' % (<EOL>name,<EOL>local_version.getVersion(),<EOL>v<EOL>))<EOL>fsutils.rmRf(local_version.path)<EOL>return _satisfyVersionByInstallingVersion(<EOL>name, version_required, local_version.path, v, type=type, inherit_shrinkwrap=inherit_shrinkwrap<EOL>)<EOL><DEDENT>return None<EOL>

returns a Component/Target for the specified version, if found in the
        list of search paths. If `update' is True, then also check for newer
        versions of the found component, and update it in-place (unless it was
        installed via a symlink).


registry = registry or Registry_Base_URL<EOL>url = '<STR_LIT>' % (<EOL>registry,<EOL>namespace,<EOL>name<EOL>)<EOL>request_headers = _headersForRegistry(registry)<EOL>response = requests.get(url, headers=request_headers)<EOL>if response.status_code == <NUM_LIT>:<EOL><INDENT>logger.error('<STR_LIT>' % (namespace[:-<NUM_LIT:1>], name))<EOL>return None<EOL><DEDENT>response.raise_for_status()<EOL>return ordered_json.loads(response.text)<EOL>

List the owners of a module or target (owners are the people with
        permission to publish versions and add/remove the owners).


registry = registry or Registry_Base_URL<EOL>pubkey_pem = None<EOL>if _isPublicRegistry(registry):<EOL><INDENT>pubkey_pem = settings.getProperty('<STR_LIT>', '<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>for s in _getSources():<EOL><INDENT>if _sourceMatches(s, registry):<EOL><INDENT>if '<STR_LIT>' in s and s['<STR_LIT>'] and '<STR_LIT>' in s['<STR_LIT>']:<EOL><INDENT>pubkey_pem = s['<STR_LIT>']['<STR_LIT>']<EOL>break<EOL><DEDENT><DEDENT><DEDENT><DEDENT>if not pubkey_pem:<EOL><INDENT>pubkey_pem, privatekey_pem = _generateAndSaveKeys()<EOL><DEDENT>else:<EOL><INDENT>pubkey_pem = pubkey_pem.encode('<STR_LIT:ascii>')<EOL><DEDENT>if b'<STR_LIT>' in pubkey_pem:<EOL><INDENT>pubkey = serialization.load_pem_public_key(pubkey_pem, default_backend())<EOL><DEDENT>else:<EOL><INDENT>pubkey_der = binascii.unhexlify(pubkey_pem)<EOL>pubkey = serialization.load_der_public_key(pubkey_der, default_backend())<EOL><DEDENT>return _pubkeyWireFormat(pubkey)<EOL>

Return the user's public key (generating and saving a new key pair if necessary)


return _listVersions(self.namespace, self.name)<EOL>

return a list of Version objects, each able to retrieve a tarball


@_swallowRequestExceptions(fail_return="<STR_LIT>")<EOL>@_retryConnectionErrors<EOL>@_friendlyAuthError<EOL>@_handleAuth<EOL>def publish(namespace, name, version, description_file, tar_file, readme_file,<EOL>readme_file_ext, registry=None):

registry = registry or Registry_Base_URL<EOL>url = '<STR_LIT>' % (<EOL>registry,<EOL>namespace,<EOL>name,<EOL>version<EOL>)<EOL>if readme_file_ext == '<STR_LIT>':<EOL><INDENT>readme_section_name = '<STR_LIT>'<EOL><DEDENT>elif readme_file_ext == '<STR_LIT>':<EOL><INDENT>readme_section_name = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>' % readme_file_ext)<EOL><DEDENT>body = OrderedDict([('<STR_LIT>', (None, description_file.read(),'<STR_LIT:application/json>')),<EOL>('<STR_LIT>',('<STR_LIT>', tar_file)),<EOL>(readme_section_name, (readme_section_name, readme_file))])<EOL>headers = _headersForRegistry(registry)<EOL>response = requests.put(url, headers=headers, files=body)<EOL>response.raise_for_status()<EOL>return None<EOL>

Publish a tarblob to the registry, if the request fails, an exception
        is raised, which either triggers re-authentication, or is turned into a
        return value by the decorators. (If successful, the decorated function
        returns None)


if (registry is None) or (registry == Registry_Base_URL):<EOL><INDENT>return<EOL><DEDENT>sources = _getSources()<EOL>source = None<EOL>for s in sources:<EOL><INDENT>if _sourceMatches(s, registry):<EOL><INDENT>source = s<EOL><DEDENT><DEDENT>if source is None:<EOL><INDENT>source = {<EOL>'<STR_LIT:type>':'<STR_LIT>',<EOL>'<STR_LIT:url>':registry,<EOL>}<EOL>sources.append(source)<EOL><DEDENT>source['<STR_LIT>'] = api_key<EOL>settings.set('<STR_LIT>', sources)<EOL>

Set the api key for accessing a registry. This is only necessary for
        development/test registries.


def __raiseUnavailableFor401(fn):<EOL><INDENT>def wrapped(*args, **kwargs):<EOL><INDENT>try:<EOL><INDENT>return fn(*args, **kwargs)<EOL><DEDENT>except requests.exceptions.HTTPError as e:<EOL><INDENT>if e.response.status_code == requests.codes.unauthorized:<EOL><INDENT>raise access_common.Unavailable(message)<EOL><DEDENT>else:<EOL><INDENT>raise<EOL><DEDENT><DEDENT><DEDENT>return wrapped<EOL><DEDENT>return __raiseUnavailableFor401<EOL>

Returns a decorator to swallow a requests exception for modules that
        are not accessible without logging in, and turn it into an Unavailable
        exception.


registry = registry or Registry_Base_URL<EOL>url = '<STR_LIT>' % (<EOL>registry,<EOL>namespace,<EOL>name,<EOL>owner<EOL>)<EOL>request_headers = _headersForRegistry(registry)<EOL>response = requests.put(url, headers=request_headers)<EOL>if response.status_code == <NUM_LIT>:<EOL><INDENT>logger.error('<STR_LIT>' % (namespace[:-<NUM_LIT:1>], name))<EOL>return<EOL><DEDENT>response.raise_for_status()<EOL>return True<EOL>

Add an owner for a module or target (owners are the people with
        permission to publish versions and add/remove the owners).


registry = registry or Registry_Base_URL<EOL>url = '<STR_LIT>' % (<EOL>registry,<EOL>namespace,<EOL>name,<EOL>version<EOL>)<EOL>headers = _headersForRegistry(registry)<EOL>response = requests.delete(url, headers=headers)<EOL>response.raise_for_status()<EOL>return None<EOL>

Try to unpublish a recently published version. Return any errors that
        occur.


@functools.wraps(fn)<EOL>def wrapped(*args, **kwargs):<EOL><INDENT>from yotta.lib import auth<EOL>interactive = globalconf.get('<STR_LIT>')<EOL>try:<EOL><INDENT>return fn(*args, **kwargs)<EOL><DEDENT>except requests.exceptions.HTTPError as e:<EOL><INDENT>if e.response.status_code == requests.codes.unauthorized: <EOL><INDENT>logger.debug('<STR_LIT>', fn)<EOL>auth.authorizeUser(provider=None, interactive=interactive)<EOL>if interactive:<EOL><INDENT>logger.debug('<STR_LIT>')<EOL>return fn(*args, **kwargs)<EOL><DEDENT><DEDENT>raise<EOL><DEDENT><DEDENT>return wrapped<EOL>

Decorator to re-try API calls after asking the user for authentication.


config_dicts = [self.additional_config, self.app_config] + [t.getConfig() for t in self.hierarchy]<EOL>config_blame = [<EOL>_mirrorStructure(self.additional_config, '<STR_LIT>'),<EOL>_mirrorStructure(self.app_config, '<STR_LIT>'),<EOL>] + [<EOL>_mirrorStructure(t.getConfig(), t.getName()) for t in self.hierarchy<EOL>]<EOL>self.config = _mergeDictionaries(*config_dicts)<EOL>self.config_blame = _mergeDictionaries(*config_blame)<EOL>

load the configuration information from the target hierarchy


for t in self.hierarchy:<EOL><INDENT>s = t.getScript(scriptname)<EOL>if s:<EOL><INDENT>return s<EOL><DEDENT><DEDENT>return None<EOL>

return the specified script if one exists (possibly inherited from
            a base target)


try:<EOL><INDENT>child = subprocess.Popen(cmd, cwd=builddir)<EOL>child.wait()<EOL><DEDENT>except OSError as e:<EOL><INDENT>if e.errno == errno.ENOENT:<EOL><INDENT>if cmd[<NUM_LIT:0>] == '<STR_LIT>':<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>return '<STR_LIT>' % (cmd[<NUM_LIT:0>])<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return '<STR_LIT>' % (cmd)<EOL><DEDENT><DEDENT>if child.returncode:<EOL><INDENT>return '<STR_LIT>' % (cmd)<EOL><DEDENT>

Execute the given command, returning an error message if an error occured
            or None if the command was succesful.


try:<EOL><INDENT>signal.signal(signal.SIGINT, _ignoreSignal);<EOL>if self.getScript('<STR_LIT>') is not None:<EOL><INDENT>return self._debugWithScript(builddir, program)<EOL><DEDENT>elif '<STR_LIT>' in self.description:<EOL><INDENT>logger.warning(<EOL>'<STR_LIT>'+<EOL>'<STR_LIT>', self.getName()<EOL>)<EOL>return self._debugDeprecated(builddir, program)<EOL><DEDENT>else:<EOL><INDENT>return "<STR_LIT>" % self<EOL><DEDENT><DEDENT>finally:<EOL><INDENT>signal.signal(signal.SIGINT, signal.SIG_DFL);<EOL><DEDENT>

Launch a debugger for the specified program. Uses the `debug`
            script if specified by the target, falls back to the `debug` and
            `debugServer` commands if not. `program` is inserted into the
            $program variable in commands.


def __init__(self, leaf_target, base_targets, app_config, additional_config):

<EOL>super(DerivedTarget, self).__init__(<EOL>path = leaf_target.path,<EOL>installed_linked = leaf_target.installed_linked,<EOL>latest_suitable_version = leaf_target.latest_suitable_version<EOL>)<EOL>self.hierarchy = [leaf_target] + base_targets[:]<EOL>self.config = None<EOL>self.config_blame = None<EOL>self.app_config = app_config<EOL>self.additional_config = additional_config or {}<EOL>

Initialise a DerivedTarget (representing an inheritance hierarchy of
            Targets.), given the most-derived Target description, and a set of
            available Targets to compose the rest of the lineage from.

            DerivedTarget provides build & debug commands, and access to the
            derived target config info (merged with the application config
            info from config.json, if any).

            It's possible to update the application config for an existing
            DerivedTarget instance.

            DerivedTarget can also be used as a stand-in for the most-derived
            (leaf) target in the inheritance hierarchy.


@fsutils.dropRootPrivs<EOL><INDENT>def build(self, builddir, component, args, release_build=False, build_args=None, targets=None,<EOL>release_no_debug_info_build=False):<DEDENT>

if build_args is None:<EOL><INDENT>build_args = []<EOL><DEDENT>if targets is None:<EOL><INDENT>targets = []<EOL><DEDENT>if release_no_debug_info_build:<EOL><INDENT>build_type = '<STR_LIT>'<EOL><DEDENT>elif release_build:<EOL><INDENT>build_type = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>build_type = '<STR_LIT>'<EOL><DEDENT>cmd = ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>' % build_type, '<STR_LIT>', args.cmake_generator, '<STR_LIT:.>']<EOL>res = self.exec_helper(cmd, builddir)<EOL>if res is not None:<EOL><INDENT>return res<EOL><DEDENT>from yotta.lib import cmake_fixups<EOL>cmake_fixups.applyFixupsForFenerator(args.cmake_generator, builddir, component)<EOL>build_command = self.overrideBuildCommand(args.cmake_generator, targets=targets)<EOL>if build_command:<EOL><INDENT>cmd = build_command + build_args<EOL><DEDENT>else:<EOL><INDENT>cmd = ['<STR_LIT>', '<STR_LIT>', builddir]<EOL>if len(targets):<EOL><INDENT>cmd += ['<STR_LIT>', targets[<NUM_LIT:0>]]<EOL><DEDENT>cmd += build_args<EOL><DEDENT>res = self.exec_helper(cmd, builddir)<EOL>if res is not None:<EOL><INDENT>return res<EOL><DEDENT>hint = self.hintForCMakeGenerator(args.cmake_generator, component)<EOL>if hint:<EOL><INDENT>logger.info(hint)<EOL><DEDENT>

Execute the commands necessary to build this component, and all of
            its dependencies.


return reversed([<EOL>os.path.join(t.path, include_file)<EOL>for t in self.hierarchy<EOL>for include_file in t.description.get('<STR_LIT>', [])<EOL>])<EOL>

Return the list of cmake files which are to be included by yotta in
            every module built. The list is returned in the order they should
            be included (most-derived last).


return [<EOL>GithubComponentVersion(<EOL>'<STR_LIT>', t[<NUM_LIT:0>], t[<NUM_LIT:1>], self.name, cache_key=_createCacheKey('<STR_LIT>', t[<NUM_LIT:0>], t[<NUM_LIT:1>], self.name)<EOL>) for t in self._getTags()<EOL>]<EOL>

return a list of GithubComponentVersion objects for all tags


@classmethod<EOL><INDENT>def createFromSource(cls, vs, name=None):<DEDENT>

return GithubComponent(vs.location, vs.spec, vs.semantic_spec, name)<EOL>

returns a github component for any github url (including
            git+ssh:// git+http:// etc. or None if this is not a Github URL.
            For all of these we use the github api to grab a tarball, because
            that's faster.

            Normally version will be empty, unless the original url was of the
            form: 'owner/repo @version' or 'url://...#version', which can be used
            to grab a particular tagged version.

            (Note that for github components we ignore the component name - it
             doesn't have to match the github module name)


return [<EOL>GithubComponentVersion(<EOL>'<STR_LIT>', b[<NUM_LIT:0>], b[<NUM_LIT:1>], self.name, cache_key=None<EOL>) for b in _getBranchHeads(self.repo).items()<EOL>]<EOL>

return a list of GithubComponentVersion objects for the tip of each branch


@_handleAuth<EOL>def _getTarball(url, into_directory, cache_key, origin_info=None):

try:<EOL><INDENT>access_common.unpackFromCache(cache_key, into_directory)<EOL><DEDENT>except KeyError as e:<EOL><INDENT>tok = settings.getProperty('<STR_LIT>', '<STR_LIT>')<EOL>headers = {}<EOL>if tok is not None:<EOL><INDENT>headers['<STR_LIT>'] = '<STR_LIT>' + str(tok)<EOL><DEDENT>logger.debug('<STR_LIT>', url)<EOL>response = requests.get(url, allow_redirects=True, stream=True, headers=headers)<EOL>response.raise_for_status()<EOL>logger.debug('<STR_LIT>', url)<EOL>logger.debug('<STR_LIT>', response.headers)<EOL>response.raise_for_status()<EOL>access_common.unpackTarballStream(<EOL>stream = response,<EOL>into_directory = into_directory,<EOL>hash = {},<EOL>cache_key = cache_key,<EOL>origin_info = origin_info<EOL>)<EOL><DEDENT>

unpack the specified tarball url into the specified directory


logger.debug('<STR_LIT>', repo)<EOL>g = Github(settings.getProperty('<STR_LIT>', '<STR_LIT>'))<EOL>repo = g.get_repo(repo)<EOL>tags = repo.get_tags()<EOL>logger.debug('<STR_LIT>', repo, [t.name for t in tags])<EOL>return {t.name: _ensureDomainPrefixed(t.tarball_url) for t in tags}<EOL>

return a dictionary of {tag: tarball_url}


@functools.wraps(fn)<EOL>def wrapped(*args, **kwargs):<EOL><INDENT>interactive = globalconf.get('<STR_LIT>')<EOL>def retryWithAuthOrRaise(original_exception):<EOL><INDENT>auth.authorizeUser(provider='<STR_LIT>', interactive=interactive)<EOL>if not interactive:<EOL><INDENT>raise original_exception<EOL><DEDENT>else:<EOL><INDENT>logger.debug('<STR_LIT>', settings.getProperty('<STR_LIT>', '<STR_LIT>'))<EOL>return fn(*args, **kwargs)<EOL><DEDENT><DEDENT>def handleRateLimitExceeded(original_exception):<EOL><INDENT>if not _userAuthedWithGithub():<EOL><INDENT>logger.warning('<STR_LIT>')<EOL>return retryWithAuthOrRaise(original_exception)<EOL><DEDENT>else:<EOL><INDENT>raise original_exception<EOL><DEDENT><DEDENT>try:<EOL><INDENT>return fn(*args, **kwargs)<EOL><DEDENT>except requests.exceptions.HTTPError as e:<EOL><INDENT>if e.response.status_code == <NUM_LIT>:<EOL><INDENT>return handleRateLimitExceeded(e)<EOL><DEDENT>if e.response.status_code == <NUM_LIT>:<EOL><INDENT>return retryWithAuthOrRaise(e)<EOL><DEDENT>raise<EOL><DEDENT>except github.BadCredentialsException as e:<EOL><INDENT>logger.debug("<STR_LIT>")<EOL>return retryWithAuthOrRaise(e)<EOL><DEDENT>except github.UnknownObjectException as e:<EOL><INDENT>logger.debug("<STR_LIT>")<EOL>if not _userAuthedWithGithub():<EOL><INDENT>logger.info('<STR_LIT>')<EOL>return retryWithAuthOrRaise(e)<EOL><DEDENT>raise<EOL><DEDENT>except github.RateLimitExceededException as e:<EOL><INDENT>return handleRateLimitExceeded(e)<EOL><DEDENT>except github.GithubException as e:<EOL><INDENT>if e.status == <NUM_LIT>:<EOL><INDENT>return handleRateLimitExceeded(e)<EOL><DEDENT>raise<EOL><DEDENT><DEDENT>return wrapped<EOL>


if '<STR_LIT>' in self.description:<EOL><INDENT>return [self.description['<STR_LIT>']]<EOL><DEDENT>else:<EOL><INDENT>return [x['<STR_LIT:type>'] for x in self.description['<STR_LIT>']]<EOL><DEDENT>

Return a list of licenses that apply to this module. (Strings,
            which may be SPDX identifiers)


if '<STR_LIT>' in self.description:<EOL><INDENT>return {os.path.normpath(self.description['<STR_LIT>']): self.getName()}<EOL><DEDENT>elif '<STR_LIT>' not in self.description and not explicit_only:<EOL><INDENT>return {'<STR_LIT:source>': self.getName()}<EOL><DEDENT>else:<EOL><INDENT>return {}<EOL><DEDENT>

Return a dictionary of libraries to compile: {"dirname":"libname"},
            this is used when automatically generating CMakeLists.

            If explicit_only is not set, then in the absence of both 'lib' and
            'bin' sections in the module.json file, the "source" directory
            will be returned.

            Note that currently modules may define only a single executable
            binary or library to be built by the automatic build system, by
            specifying `"bin": "dir-to-be-built-into-binary"`, or `"lib":
            "dir-to-be-built-into-library"`, and the bin/lib will always have
            the same name as the module. The default behaviour if nothing is
            specified is for the 'source' directory to be built into a library.

            The module.json syntax may allow for other combinations in the
            future (and callers of this function should not rely on it
            returning only a single item). For example, a "bin": {"dirname":
            "exename"} syntax might be supported, however currently more
            complex builds must be controlled by custom CMakeLists.


<EOL>if '<STR_LIT>' in self.description:<EOL><INDENT>return {os.path.normpath(self.description['<STR_LIT>']): self.getName()}<EOL><DEDENT>else:<EOL><INDENT>return {}<EOL><DEDENT>

Return a dictionary of binaries to compile: {"dirname":"exename"},
            this is used when automatically generating CMakeLists

            Note that currently modules may define only a single executable
            binary or library to be built by the automatic build system, by
            specifying `"bin": "dir-to-be-built-into-binary"`, or `"lib":
            "dir-to-be-built-into-library"`, and the bin/lib will always have
            the same name as the module. The default behaviour if nothing is
            specified is for the 'source' directory to be built into a library.

            The module.json syntax may allow for other combinations in the
            future (and callers of this function should not rely on it
            returning only a single item). For example, a "bin": {"dirname":
            "exename"} syntax might be supported, however currently more
            complex builds must be controlled by custom CMakeLists.


return bool(len(self.getBinaries()))<EOL>

Return true if this module is an application instead of a reusable
            library


return self.installed_dependencies<EOL>

Return true if satisfyDependencies has been called.

            Note that this is slightly different to when all of the
            dependencies are actually satisfied, but can be used as if it means
            that.


def getTarget(self, target_name_and_version, additional_config=None):

derived_target, errors = self.satisfyTarget(<EOL>target_name_and_version,<EOL>additional_config = additional_config,<EOL>install_missing = False<EOL>)<EOL>if len(errors):<EOL><INDENT>return None<EOL><DEDENT>else:<EOL><INDENT>return derived_target<EOL><DEDENT>

Return a derived target object representing the selected target: if
            the target is not installed, or is invalid then the returned object
            will test false in a boolean context.

            Returns derived_target

            Errors are not displayed.


def satisfyTarget(self, target_name_and_version, update_installed=False, additional_config=None, install_missing=True):

<EOL>from yotta.lib import target<EOL>application_dir = None<EOL>if self.isApplication():<EOL><INDENT>application_dir = self.path<EOL><DEDENT>return target.getDerivedTarget(<EOL>target_name_and_version,<EOL>self.targetsPath(),<EOL>install_missing = install_missing,<EOL>application_dir = application_dir,<EOL>update_installed = update_installed,<EOL>additional_config = additional_config,<EOL>shrinkwrap = self.getShrinkwrap()<EOL>)<EOL>

Ensure that the specified target name (and optionally version,
            github ref or URL) is installed in the targets directory of the
            current component

            returns (derived_target, errors)