Unnamed: 0 int64 0 389k | code stringlengths 26 79.6k | docstring stringlengths 1 46.9k |
|---|---|---|
5,200 | def _toggle_filming(self):
if self._filming:
self.log("Stopping operation")
self._filming = False
self.timer.stop()
else:
self.log("Starting operation")
self._filming = True
self.timer.start() | Toggles the camera system recording state |
5,201 | def reload(self):
self.load(self.api.get(self.objName, self.key)) | Function reload
Sync the full object |
5,202 | def move_tab(self, index_from, index_to):
client = self.clients.pop(index_from)
self.clients.insert(index_to, client) | Move tab. |
5,203 | def verify_registration(request):
user = process_verify_registration_data(request.data)
extra_data = None
if registration_settings.REGISTER_VERIFICATION_AUTO_LOGIN:
extra_data = perform_login(request, user)
return get_ok_response(, extra_data=extra_data) | Verify registration via signature. |
5,204 | def with_setup(setup=None, teardown=None):
def decorate(func, setup=setup, teardown=teardown):
if setup:
if hasattr(func, ):
_old_s = func.setup
def _s():
setup()
_old_s()
func.setup = _s
els... | Decorator to add setup and/or teardown methods to a test function::
@with_setup(setup, teardown)
def test_something():
" ... "
Note that `with_setup` is useful *only* for test functions, not for test
methods or inside of TestCase subclasses. |
5,205 | def _check_success(self):
cube_height = self.sim.data.body_xpos[self.cube_body_id][2]
table_height = self.table_full_size[2]
return cube_height > table_height + 0.10 | Returns True if task is successfully completed |
5,206 | def write_str(data, sidx, pnames):
start = time.time()
tmparrs = os.path.join(data.dirs.outfiles, "tmp-{}.h5".format(data.name))
with h5py.File(tmparrs, ) as io5:
snparr = io5["snparr"]
bisarr = io5["bisarr"]
bend = np.where(np.all(bisarr[:] == "", axis=0))[0]
... | Write STRUCTURE format for all SNPs and unlinked SNPs |
5,207 | def init(options, use_sigterm_handler=True):
global _AUTH, _OPTIONS
if isinstance(options, dict):
_OPTIONS = DEFAULT_OPTIONS.copy()
_OPTIONS.update(options)
else:
for optname, optvalue in DEFAULT_OPTIONS.iteritems():
if hasattr(options, optname):
... | Must be called just after registration, before anything else |
5,208 | def matches_filters(self, node):
visible = self.visible
if self.options["text"]:
if isregex(self.options["text"]):
regex = self.options["text"]
elif self.exact_text is True:
regex = re.compile(r"\A{}\Z".format(re.escape(self.options["tex... | Returns whether the given node matches all filters.
Args:
node (Element): The node to evaluate.
Returns:
bool: Whether the given node matches. |
5,209 | def create_LM_hashed_password_v1(passwd):
if re.match(r, passwd):
return binascii.unhexlify(passwd.split()[0])
passwd = passwd.upper()
lm_pw = passwd + * (14 - len(passwd))
lm_pw = passwd[0:14]
magic_str = b"KGS!@
res = b
dobj = des.DES(lm_pw[0:7])
res = ... | create LanManager hashed password |
5,210 | def get_pages_for_display(self):
all_pages = Page.objects.none()
if self.max_levels == 1:
return all_pages
for item in self.top_level_items:
if item.link_page_id:
page_depth = item.link_p... | Return all pages needed for rendering all sub-levels for the current
menu |
5,211 | def dot(self, other_tf):
if other_tf.to_frame != self.from_frame:
raise ValueError(.format(other_tf.to_frame, self.from_frame))
if not isinstance(other_tf, RigidTransform):
raise ValueError()
other_scale = 1.0
if isinstance(other_tf, SimilarityTransform)... | Compose this simliarity transform with another.
This transform is on the left-hand side of the composition.
Parameters
----------
other_tf : :obj:`SimilarityTransform`
The other SimilarityTransform to compose with this one.
Returns
-------
:obj:`Sim... |
5,212 | def event_text_key(self, event):
char = event.char
if not char or char not in string.ascii_letters:
return
converted_char = invert_shift(char)
log.debug("convert keycode %s - char %s to %s", event.keycode, repr(char), converted_char)
self.text.... | So a "invert shift" for user inputs:
Convert all lowercase letters to uppercase and vice versa. |
5,213 | def _to_dict(self):
_dict = {}
if hasattr(self, ) and self.key_as_string is not None:
_dict[] = datetime_to_string(self.key_as_string)
if hasattr(self, ) and self.key is not None:
_dict[] = self.key
if hasattr(self,
) and self.matching_... | Return a json dictionary representing this model. |
5,214 | def descend(self, include_me=True):
if include_me:
yield self
for child in self.child_list:
yield child
yield from child.descend() | Descend depth first into all child nodes |
5,215 | def anderson(*args, dist=):
from scipy.stats import anderson as ads
k = len(args)
from_dist = np.zeros(k, )
sig_level = np.zeros(k)
for j in range(k):
st, cr, sig = ads(args[j], dist=dist)
from_dist[j] = True if (st > cr).any() else False
sig_level[j] = sig[np.argmin(np.... | Anderson-Darling test of distribution.
Parameters
----------
sample1, sample2,... : array_like
Array of sample data. May be different lengths.
dist : string
Distribution ('norm', 'expon', 'logistic', 'gumbel')
Returns
-------
from_dist : boolean
True if data comes f... |
5,216 | def request(self, method, api_url, params={}, **kwargs):
LOG.debug("axapi_http: full url = %s", self.url_base + api_url)
LOG.debug("axapi_http: %s url = %s", method, api_url)
LOG.debug("axapi_http: params = %s", json.dumps(logutils.clean(params), indent=4))
if params:... | Generate the API call to the device. |
5,217 | def remove_port_channel(self, **kwargs):
port_int = kwargs.pop()
callback = kwargs.pop(, self._callback)
if re.search(, port_int) is None:
raise ValueError(
% repr(port_int))
port_channel = getattr(self._interface, )
port_chann... | Remove a port channel interface.
Args:
port_int (str): port-channel number (1, 2, 3, etc).
callback (function): A function executed upon completion of the
method. The only parameter passed to `callback` will be the
``ElementTree`` `config`.
Re... |
5,218 | def add_segmented_colorbar(da, colors, direction):
nbreak = len(colors)
if direction == :
linewidth = da.height/nbreak
verts = [None] * nbreak
x1, x2 = 0, da.width
for i, color in enumerate(colors):
y1 = i * linewidth
y2 = y1 + linewidth
v... | Add 'non-rastered' colorbar to DrawingArea |
5,219 | def unpublish(self, daap_server):
if daap_server not in self.daap_servers:
return
self.zeroconf.unregister_service(self.daap_servers[daap_server])
del self.daap_servers[daap_server] | Unpublish a given server.
If the server was not published, this method will not do anything.
:param DAAPServer daap_server: DAAP Server instance to publish. |
5,220 | def wc_dict2lha(wc, skip_redundant=True, skip_zero=True):
d = OrderedDict()
for name, (block, i) in WC_dict_0f.items():
if block not in d:
d[block] = defaultdict(list)
if wc[name] != 0:
d[block][].append([i, wc[name].real])
for name in definitions.WC_keys_2f:
... | Convert a a dictionary of Wilson coefficients into
a dictionary that pylha can convert into a DSixTools WC output file. |
5,221 | def dimension(self):
if self.dim > -1:
return self.dim
d = None
if self.dim != -1 and not self._estimated:
d = self.dim
elif self._estimated:
dim = len(self.eigenvalues)
if self.var_cutoff < 1.0:
dim = min(dim... | output dimension |
5,222 | def getInspectorActionById(self, identifier):
for action in self.inspectorActionGroup.actions():
if action.data() == identifier:
return action
raise KeyError("No action found with ID: {!r}".format(identifier)) | Sets the inspector and draw the contents
Triggers the corresponding action so that it is checked in the menus. |
5,223 | def suspend(self, instance_id):
nt_ks = self.compute_conn
response = nt_ks.servers.suspend(instance_id)
return True | Suspend a server |
5,224 | def createIndex(self, table, fields, where = , whereValues = []) :
versioTest = sq.sqlite_version_info[0] >= 3 and sq.sqlite_version_info[1] >= 8
if len(where) > 0 and not versioTest :
sys.stderr.write("WARNING: IGNORING THE \"WHERE\" CLAUSE in INDEX. Partial indexes where only implemented in sqlite 3.8... | Creates indexes for Raba Class a fields resulting in significantly faster SELECTs but potentially slower UPADTES/INSERTS and a bigger DBs
Fields can be a list of fields for Multi-Column Indices, or siply the name of one single field.
With the where close you can create a partial index by adding conditions
-----
... |
5,225 | def run(self, dag):
coupling_map = self._coupling_map
ordered_virtual_gates = list(dag.serial_layers())
if self.initial_layout is None:
if self.property_set["layout"]:
self.initial_layout = self.property_set["layout"]
else:
self.i... | Run one pass of the lookahead mapper on the provided DAG.
Args:
dag (DAGCircuit): the directed acyclic graph to be mapped
Returns:
DAGCircuit: A dag mapped to be compatible with the coupling_map in
the property_set.
Raises:
TranspilerError: if... |
5,226 | def configure(default=None, dev=None):
cache_loc = openaccess_epub.utils.cache_location()
config_loc = openaccess_epub.utils.config_location()
openaccess_epub.utils.mkdir_p(cache_loc)
defaults = {: time.asctime(),
: openaccess_epub.__version__,
: unix_path_coe... | The inner control loops for user interaction during quickstart
configuration. |
5,227 | def _is_path(s):
if isinstance(s, string_types):
try:
return op.exists(s)
except (OSError, ValueError):
return False
else:
return False | Return whether an object is a path. |
5,228 | def delete_message(self, chat_id, message_id):
return apihelper.delete_message(self.token, chat_id, message_id) | Use this method to delete message. Returns True on success.
:param chat_id: in which chat to delete
:param message_id: which message to delete
:return: API reply. |
5,229 | def _start(self):
if self.whoami is None:
me = self.get_me()
if me.get(, False):
self.whoami = me[]
else:
raise ValueError(
) | Requests bot information based on current api_key, and sets
self.whoami to dictionary with username, first_name, and id of the
configured bot. |
5,230 | def xross_listener(http_method=None, **xross_attrs):
handler = currentframe().f_back.f_locals[]._xross_handler
handler.set_attrs(**xross_attrs)
if http_method is not None:
handler.http_method = http_method
handler.dispatch() | Instructs xross to handle AJAX calls right from the moment it is called.
This should be placed in a view decorated with `@xross_view()`.
:param str http_method: GET or POST. To be used as a source of data for xross.
:param dict xross_attrs: xross handler attributes.
Those attributes will be avail... |
5,231 | def pvremove(devices, override=True):
if isinstance(devices, six.string_types):
devices = devices.split()
cmd = [, ]
for device in devices:
if pvdisplay(device):
cmd.append(device)
elif not override:
raise CommandExecutionError(.format(device))
if n... | Remove a physical device being used as an LVM physical volume
override
Skip devices, if they are already not used as LVM physical volumes
CLI Examples:
.. code-block:: bash
salt mymachine lvm.pvremove /dev/sdb1,/dev/sdb2 |
5,232 | def set_tags(name=None,
tags=None,
call=None,
location=None,
instance_id=None,
resource_id=None,
kwargs=None):
Other stuff
if kwargs is None:
kwargs = {}
if location is None:
location = get_location()
if in... | Set tags for a resource. Normally a VM name or instance_id is passed in,
but a resource_id may be passed instead. If both are passed in, the
instance_id will be used.
CLI Examples:
.. code-block:: bash
salt-cloud -a set_tags mymachine tag1=somestuff tag2='Other stuff'
salt-cloud -a se... |
5,233 | def AddRoute(self, short_name, long_name, route_type, route_id=None):
if route_id is None:
route_id = util.FindUniqueId(self.routes)
route = self._gtfs_factory.Route(short_name=short_name, long_name=long_name,
route_type=route_type, route_id=route_id)
route.agency_id = sel... | Add a route to this schedule.
Args:
short_name: Short name of the route, such as "71L"
long_name: Full name of the route, such as "NW 21st Ave/St Helens Rd"
route_type: A type such as "Tram", "Subway" or "Bus"
route_id: id of the route or None, in which case a unique id is picked
Return... |
5,234 | def get_lifecycle(self, policy=None, params=None):
return self.transport.perform_request(
"GET", _make_path("_ilm", "policy", policy), params=params
) | `<https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-get-lifecycle.html>`_
:arg policy: The name of the index lifecycle policy |
5,235 | def calc_size_and_sha265(content: io.IOBase, chunk_size: int):
size = 0
sha256 = hashlib.sha256()
content.seek(0, io.SEEK_SET)
while True:
buf = content.read(chunk_size)
length = len(buf)
size += length
sha256.update(buf)
if length != chunk_size:
... | Calculates the size and the sha2566 value of the content. |
5,236 | def import_single_vpn_path_to_all_vrfs(self, vpn_path, path_rts=None):
LOG.debug(, vpn_path)
if not path_rts:
LOG.info(, vpn_path)
return
interested_tables = set()
if vpn_path.route_family == RF_IPv4_VPN:
route_fa... | Imports *vpn_path* to qualifying VRF tables.
Import RTs of VRF table is matched with RTs from *vpn4_path* and if we
have any common RTs we import the path into VRF. |
5,237 | def check_for_required_columns(problems, table, df):
r = cs.PROTOFEED_REF
req_columns = r.loc[(r[] == table) & r[],
].values
for col in req_columns:
if col not in df.columns:
problems.append([, .format(col),
table, []])
return problems | Check that the given ProtoFeed table has the required columns.
Parameters
----------
problems : list
A four-tuple containing
1. A problem type (string) equal to ``'error'`` or ``'warning'``;
``'error'`` means the ProtoFeed is violated;
``'warning'`` means there is a p... |
5,238 | def zoom_in(self, action=None, channel=0):
ret = self.command(
.format(action, channel)
)
return ret.content.decode() | Params:
action - start or stop
channel - channel number
The magic of zoom in 1x, 2x etc. is the timer between the cmd
'start' and cmd 'stop'. My suggestion for start/stop cmd is 0.5 sec |
5,239 | def weighted_std(values, weights):
average = np.average(values, weights=weights)
variance = np.average((values-average)**2, weights=weights)
return np.sqrt(variance) | Calculate standard deviation weighted by errors |
5,240 | def cache_result(func):
def cache_set(key, value):
cache.set(key, value, AVATAR_CACHE_TIMEOUT)
return value
def cached_func(user, size):
prefix = func.__name__
cached_funcs.add(prefix)
key = get_cache_key(user, size, prefix=prefix)
return cache.get(key) or c... | Decorator to cache the result of functions that take a ``user`` and a
``size`` value. |
5,241 | def _convert_to_cwl_json(data, fnargs, input_files):
out = {}
for outvar in _get_output_cwl_keys(fnargs):
keys = []
for key in outvar.split("__"):
try:
key = int(key)
except ValueError:
pass
keys.append(key)
if isin... | Convert world data object (or list of data objects) into outputs for CWL ingestion. |
5,242 | def zoning_defined_configuration_cfg_cfg_name(self, **kwargs):
config = ET.Element("config")
zoning = ET.SubElement(config, "zoning", xmlns="urn:brocade.com:mgmt:brocade-zone")
defined_configuration = ET.SubElement(zoning, "defined-configuration")
cfg = ET.SubElement(defined_con... | Auto Generated Code |
5,243 | def get_humidity(self):
self._init_humidity()
humidity = 0
data = self._humidity.humidityRead()
if (data[0]):
humidity = data[1]
return humidity | Returns the percentage of relative humidity |
5,244 | def add_local_option(self, *args, **kw):
try:
group = self.local_option_group
except AttributeError:
group = SConsOptionGroup(self, )
group = self.add_option_group(group)
self.local_option_group = group
result = group.add_option(*args, **... | Adds a local option to the parser.
This is initiated by a SetOption() call to add a user-defined
command-line option. We add the option to a separate option
group for the local options, creating the group if necessary. |
5,245 | def total_variation(domain, grad=None):
if grad is None:
grad = odl.Gradient(domain, method=, pad_mode=)
grad.norm = 2 * np.sqrt(sum(1 / grad.domain.cell_sides**2))
else:
grad = grad
f = odl.solvers.GroupL1Norm(grad.range, exponent=2)
return f * grad | Total variation functional.
Parameters
----------
domain : odlspace
domain of TV functional
grad : gradient operator, optional
Gradient operator of the total variation functional. This may be any
linear operator and thereby generalizing TV. default=forward
differences wi... |
5,246 | def cached_property(getter):
def decorator(self):
key = "_cached_property_" + getter.__name__
if not hasattr(self, key):
setattr(self, key, getter(self))
return getattr(self, key)
decorator.__name__ = getter.__name__
decorator.__module__ = getter.__module__
de... | Decorator that converts a method into memoized property.
The decorator works as expected only for classes with
attribute '__dict__' and immutable properties. |
5,247 | def is_compliant(self, path):
log("Auditing contents of file " % (path), level=DEBUG)
with open(path, ) as fd:
contents = fd.read()
matches = 0
for pattern in self.pass_cases:
key = re.compile(pattern, flags=re.MULTILINE)
results = re.search(... | Given a set of content matching cases i.e. tuple(regex, bool) where
bool value denotes whether or not regex is expected to match, check that
all cases match as expected with the contents of the file. Cases can be
expected to pass of fail.
:param path: Path of file to check.
:ret... |
5,248 | def pauseMovie(self):
if self.state == self.PLAYING:
self.sendRtspRequest(self.PAUSE) | Pause button handler. |
5,249 | def _fault_to_exception(f):
e = _fault_to_exception_map.get(f.faultCode)
if e is None:
e = NipapError
return e(f.faultString) | Converts XML-RPC Fault objects to Pynipap-exceptions.
TODO: Is this one neccesary? Can be done inline... |
5,250 | def override_cluster_spec(self, srd):
merged_cluster_spec = copy.deepcopy(self.entrypoints)
merged_cluster_spec = dict([(k, v) for k, v in merged_cluster_spec.items() if v.get("clusterSpec") is not None])
merged_cluster_spec = dict([(k, v) for k, v in merged_cluster... | Returns SystemRequirementsDict can be passed in a "systemRequirements"
input to app-xxx/run, e.g. {'fn': {'clusterSpec': {initialInstanceCount: 3, version: "2.4.0", ..}}}
Since full clusterSpec must be passed to the API server, we need to retrieve the cluster
spec defined in app doc's systemRequ... |
5,251 | def install_theme(path_to_theme):
pref_init()
filename = basename(path_to_theme)
dest = join(THEMES_DIR, filename)
copy(path_to_theme, dest)
zf = zipfile.ZipFile(dest)
zf.extractall(THEMES_DIR)
unlink(dest) | Pass a path to a theme file which will be extracted to the themes directory. |
5,252 | def marketShortInterest(date=None, token=, version=):
if date:
date = _strOrDate(date)
return _getJson( + date, token, version)
return _getJson(, token, version) | The consolidated market short interest positions in all IEX-listed securities are included in the IEX Short Interest Report.
The report data will be published daily at 4:00pm ET.
https://iexcloud.io/docs/api/#listed-short-interest-list-in-dev
Args:
date (datetime); Effective Datetime
toke... |
5,253 | def add_to_parser(self, parser, group):
return parser.add_argument_group(*self.args, **self.kwds) | Add this object's information to the parser. |
5,254 | def sort_index(self, axis=0, level=None, ascending=True, inplace=False,
kind=, na_position=, sort_remaining=True):
inplace = validate_bool_kwarg(inplace, )
axis = self._get_axis_number(axis)
axis_name = self._get_axis_name(axis)
labels = self._get_axis(axis)
... | Sort object by labels (along an axis).
Parameters
----------
axis : {0 or 'index', 1 or 'columns'}, default 0
The axis along which to sort. The value 0 identifies the rows,
and 1 identifies the columns.
level : int or level name or list of ints or list of level ... |
5,255 | def _Open(self, path_spec=None, mode=):
if not self._file_object_set_in_init and not path_spec:
raise ValueError()
if self._file_object_set_in_init:
return
self._file_object = self._OpenFileObject(path_spec)
if not self._file_object:
raise IOError() | Opens the file-like object defined by path specification.
Args:
path_spec (Optional[PathSpec]): path specification.
mode (Optional[str]): file access mode.
Raises:
AccessError: if the access to open the file was denied.
IOError: if the file-like object could not be opened.
OSErro... |
5,256 | def batch_scan(points, xdist=20, ydist=20, N=5):
chr_pair_points = group_hits(points)
clusters = []
for chr_pair in sorted(chr_pair_points.keys()):
points = chr_pair_points[chr_pair]
clusters.extend(synteny_scan(points, xdist, ydist, N))
return clusters | runs synteny_scan() per chromosome pair |
5,257 | def get_install_requires():
install_requires = get_requirements()
if not in sys.argv:
if sys.version_info[0] == 2:
install_requires.append()
if sys.version_info[2:] == (2, 6):
install_requires.append()
elif... | Add conditional dependencies (when creating source distributions). |
5,258 | def _show(self, pk):
pages = get_page_args()
page_sizes = get_page_size_args()
orders = get_order_args()
item = self.datamodel.get(pk, self._base_filters)
if not item:
abort(404)
widgets = self._get_show_widget(pk, item)
self.update_redirect(... | show function logic, override to implement different logic
returns show and related list widget |
5,259 | def close(self, code=None, reason=):
self.send_close_frame(code, reason)
frame = self.sock.recv()
if frame.opcode != OPCODE_CLOSE:
raise ValueError( % frame)
self.handle_control_frame(frame) | Close the socket by sending a CLOSE frame and waiting for a response
close message, unless such a message has already been received earlier
(prior to calling this function, for example). The onclose() handler is
called after the response has been received, but before the socket is
actual... |
5,260 | def load_variants(adapter, vcf_obj, case_obj, skip_case_id=False, gq_treshold=None,
max_window=3000, variant_type=):
if variant_type == :
nr_variants = case_obj[]
else:
nr_variants = case_obj[]
nr_inserted = 0
case_id = case_obj[]
if skip_case_id:
case... | Load variants for a family into the database.
Args:
adapter (loqusdb.plugins.Adapter): initialized plugin
case_obj(Case): dict with case information
nr_variants(int)
skip_case_id (bool): whether to include the case id on variant level
or not
gq_t... |
5,261 | def render(self, code):
if self._callbacks[] is not None:
self._callbacks[](code)
ypos = 1.0
for line in code:
xpos = self.quiet_zone
for mod in line:
if mod == :
color = self.background
... | Renders the barcode to whatever the inheriting writer provides,
using the registered callbacks.
:parameters:
code : List
List of strings matching the writer spec
(only contain 0 or 1). |
5,262 | def expand_as_args(args):
return (isinstance(args, collections.Sequence) and
not _is_namedtuple(args) and not _force_leaf(args)) | Returns `True` if `args` should be expanded as `*args`. |
5,263 | def warn_import_error(type_of_obj_support: str, caught: ImportError):
msg = StringIO()
msg.writelines( + type_of_obj_support +
)
traceback.print_tb(caught.__traceback__, file=msg)
msg.writelines(str(caught.__class__.__name__) + + str(caught) + )
warn(msg.getvalue()) | Utility method to print a warning message about failed import of some modules
:param type_of_obj_support:
:param caught:
:return: |
5,264 | def interface_by_name(self, name):
if name in self._devinfo:
return self._devinfo[name]
raise KeyError("No device named {}".format(name)) | Given a device name, return the corresponding interface object |
5,265 | def substitute_harmonic(progression, substitute_index, ignore_suffix=False):
simple_substitutions = [(, ), (, ), (, ),
(, ), (, )]
res = []
(roman, acc, suff) = parse_string(progression[substitute_index])
if suff == or suff == or ignore_suffix:
for subs in simple_substitutions... | Do simple harmonic substitutions. Return a list of possible substitions
for progression[substitute_index].
If ignore_suffix is set to True the suffix of the chord being
substituted will be ignored. Otherwise only progressions without a
suffix, or with suffix '7' will be substituted.
The following ... |
5,266 | def free_size(self, units="MiB"):
self.open()
size = lvm_vg_get_free_size(self.handle)
self.close()
return size_convert(size, units) | Returns the volume group free size in the given units. Default units are MiB.
*Args:*
* units (str): Unit label ('MiB', 'GiB', etc...). Default is MiB. |
5,267 | def length(self, vertices):
length = ((np.diff(self.discrete(vertices),
axis=0)**2).sum(axis=1)**.5).sum()
return length | Return the total length of the entity.
Returns
---------
length: float, total length of entity |
5,268 | def create_vm(self, userid, cpu, memory, disk_list, profile,
max_cpu, max_mem, ipl_from, ipl_param, ipl_loadparam):
rd = (
%
{: userid, : memory,
: const.ZVM_USER_DEFAULT_PRIVILEGE,
: cpu, : profile,
... | Create VM and add disks if specified. |
5,269 | def copy_script(self, filename, id_=-1):
for repo in self._children:
repo.copy_script(filename, id_) | Copy a script to all repositories.
Takes into account whether a JSS has been migrated. See the
individual DistributionPoint types for more information.
Args:
filename: String path to the local file to copy.
id_: Integer ID you wish to associate script with for a JDS
... |
5,270 | def _parse_reflectivity(line, lines):
split_line = line.split()
energy = float(split_line[0])
reflect_xx = float(split_line[1])
reflect_zz = float(split_line[2])
return {"energy": energy, "reflect_xx": reflect_xx, "reflect_zz": reflect_zz} | Parse Energy [eV] reflect_xx reflect_zz |
5,271 | def load_yaml(file):
if hasattr(yaml, "full_load"):
return yaml.full_load(file)
else:
return yaml.load(file) | If pyyaml > 5.1 use full_load to avoid warning |
5,272 | def _tokenize(cls, sentence):
while True:
match = cls._regex_tag.search(sentence)
if not match:
yield from cls._split(sentence)
return
chunk = sentence[:match.start()]
yield from cls._split(chunk)
tag = match.gr... | Split a sentence while preserving tags. |
5,273 | def get_items(self):
from .layers import Layer
results = []
for url in self.items:
if in url:
r = self._client.request(, url)
results.append(self._client.get_manager(Layer).create_from_result(r.json()))
else:
... | Return the item models associated with this Publish group. |
5,274 | def load_from_ini(ini, default_section=_DEFAULT_SECTION):
global _CONFIG_CACHE
if ini not in _CONFIG_CACHE:
if six.PY3:
logger.debug("PY3........")
_CONFIG_CACHE[ini] = _load_from_ini_py3(ini, default_section)
else:
_CONFIG_CACHE[ini] = _load_from_ini_py2... | 从单个配置文件读取配置
:param ini:
:param default_section:
:return: |
5,275 | def walk(prev, inital_path, *args, **kw):
for dir_path, dir_names, filenames in os.walk(inital_path):
for filename in filenames:
yield os.path.join(dir_path, filename) | This pipe wrap os.walk and yield absolute path one by one.
:param prev: The previous iterator of pipe.
:type prev: Pipe
:param args: The end-of-line symbol for each output.
:type args: list of string.
:param kw: The end-of-line symbol for each output.
:type kw: dictionary of options. Add 'endl'... |
5,276 | def get_signature(self, signature):
resp = self.request_list()
if resp and (len(resp) > 0):
for sig_dict in resp:
sig = zobjects.Signature.from_dict(sig_dict)
if hasattr(signature, ):
its_this_one = (sig.id == si... | Retrieve one signature, discriminated by name or id.
Note that signature name is not case sensitive.
:param: a zobjects.Signature describing the signature
like "Signature(name='my-sig')"
:returns: a zobjects.Signature object, filled with the signature if no
sig... |
5,277 | def get_cookbook_dirs(self, base_dir=None):
if base_dir is None:
base_dir = self.env_root
cookbook_dirs = []
dirs_to_skip = set([])
for root, dirs, files in os.walk(base_dir):
dirs[:] = [d for d in dirs if d not in dirs_to_skip]
for name in... | Find cookbook directories. |
5,278 | def get_last_fingerprint(fullpath):
record = model.FileFingerprint.get(file_path=fullpath)
if record:
return record.fingerprint
return None | Get the last known modification time for a file |
5,279 | def p_lpartselect_lpointer(self, p):
p[0] = Partselect(p[1], p[3], p[5], lineno=p.lineno(1))
p.set_lineno(0, p.lineno(1)) | lpartselect : pointer LBRACKET expression COLON expression RBRACKET |
5,280 | def file_digest(source):
hash_sha256 = hashlib.sha256()
should_close = False
if isinstance(source, six.string_types):
should_close = True
source = open(source, )
for chunk in iter(lambda: source.read(_BUFFER_SIZE), b):
hash_sha256.update(chunk)
if should_close:
... | Calculates SHA256 digest of a file.
Args:
source: either a file-like object or a path to file |
5,281 | def load_featured(data):
from invenio_communities.models import FeaturedCommunity
obj = FeaturedCommunity(id=data[],
id_community=data[],
start_date=iso2dt(data[]))
db.session.add(obj)
db.session.commit() | Load community featuring from data dump.
:param data: Dictionary containing community featuring data.
:type data: dict |
5,282 | def printImports(self):
for module in self.listModules():
print("%s:" % module.label)
if self.external_dependencies:
imports = list(module.imports)
else:
imports = [modname for modname in module.imports
if mo... | Produce a report of dependencies. |
5,283 | def _parse_datapoints(self, parsed_duration, parsed_resolution, limit):
return self.datapoints_parser.parse(parsed_duration, parsed_resolution, limit) | Parse the number of datapoints of a query.
This can be calculated from the given duration and resolution of the query.
E.g. if the query has a duation of 2*60*60 = 7200 seconds and a resolution of 10 seconds
then the number of datapoints would be 7200/10 => 7200 datapoints.
:param parse... |
5,284 | def dump_sensor_memory(self, cb_compress=False, custom_compress=False, custom_compress_file=None, auto_collect_result=False):
print("~ dumping contents of memory on {}".format(self.sensor.computer_name))
local_file = remote_file = "{}.memdmp".format(self.sensor.computer_name)
if not se... | Customized function for dumping sensor memory.
:arguments cb_compress: If True, use CarbonBlack's built-in compression.
:arguments custom_compress_file: Supply path to lr_tools/compress_file.bat to fork powershell compression
:collect_mem_file: If True, wait for memdump + and compression to com... |
5,285 | def validate_row(self, row):
clean_row = {}
if isinstance(row, (tuple, list)):
assert self.header_order, "No attribute order specified."
assert len(row) == len(self.header_order), \
"Row length does not match header length."
itr = zip(self.hea... | Ensure each element in the row matches the schema. |
5,286 | def _process_inbox_message(self, message: praw.models.Message):
self._func_message(message, *self._func_message_args) | Process a reddit inbox message. Calls `func_message(message, *func_message_args)`.
:param message: Item to process |
5,287 | def query_pop(query, prefix, sep=):
Annotation.namespaceAnnotationnamespacenamespaceAnnotationnamespace
terms = query.split(sep)
if terms[0] == prefix:
terms = terms[1:]
return sep.join(terms) | Pop a prefix from a query string.
Parameters
----------
query : str
The query string
prefix : str
The prefix string to pop, if it exists
sep : str
The string to separate fields
Returns
-------
popped : str
`query` with a `prefix` removed from the fron... |
5,288 | def wait_for_stable_cluster(
hosts,
jolokia_port,
jolokia_prefix,
check_interval,
check_count,
unhealthy_time_limit,
):
stable_counter = 0
max_checks = int(math.ceil(unhealthy_time_limit / check_interval))
for i in itertools.count():
partitions, brokers = read_cluster_st... | Block the caller until the cluster can be considered stable.
:param hosts: list of brokers ip addresses
:type hosts: list of strings
:param jolokia_port: HTTP port for Jolokia
:type jolokia_port: integer
:param jolokia_prefix: HTTP prefix on the server for the Jolokia queries
:type jolokia_pref... |
5,289 | def _ensure_counter(self):
if not isinstance(self.sync_counter, self._SynchronizationManager):
self.sync_counter = self._SynchronizationManager() | Ensure the sync counter is a valid non-dummy object. |
5,290 | def add(self, source_id, auth, validate=True):
params = {: source_id, : auth, : validate}
return self.request.post(, params) | Add one or more sets of authorization credentials to a Managed Source
Uses API documented at http://dev.datasift.com/docs/api/rest-api/endpoints/sourceauthadd
:param source_id: target Source ID
:type source_id: str
:param auth: An array of the source-specific authorizat... |
5,291 | def filter(self, collection, data, **kwargs):
ops = self.parse(data)
collection = self.apply(collection, ops, **kwargs)
return ops, collection | Filter given collection. |
5,292 | def generate_cache_key(value):
if is_bytes(value):
return hashlib.md5(value).hexdigest()
elif is_text(value):
return generate_cache_key(to_bytes(text=value))
elif is_boolean(value) or is_null(value) or is_number(value):
return generate_cache_key(repr(value))
elif is_dict(val... | Generates a cache key for the *args and **kwargs |
5,293 | def expire(key, seconds, host=None, port=None, db=None, password=None):
*
server = _connect(host, port, db, password)
return server.expire(key, seconds) | Set a keys time to live in seconds
CLI Example:
.. code-block:: bash
salt '*' redis.expire foo 300 |
5,294 | def download(model, direct=False, *pip_args):
dl_tpl = "{m}-{v}/{m}-{v}.tar.gz
if direct:
components = model.split("-")
model_name = "".join(components[:-1])
version = components[-1]
dl = download_model(dl_tpl.format(m=model_name, v=version), pip_args)
else:
shor... | Download compatible model from default download path using pip. Model
can be shortcut, model name or, if --direct flag is set, full model name
with version. For direct downloads, the compatibility check will be skipped. |
5,295 | def shuffled_batches(self, batch_size):
if batch_size >= self.num_envs * self.num_steps:
yield self
else:
rollouts_in_batch = batch_size // self.num_steps
batch_splits = math_util.divide_ceiling(self.num_envs, rollouts_in_batch)
indices = list(r... | Generate randomized batches of data - only sample whole trajectories |
5,296 | def upload(self, filename, directory=None):
filename = eval_path(filename)
if directory is None:
directory = self.downloads_directory
res1 = self._req_upload(filename, directory)
data1 = res1[]
file_id = data1[]
res2 = self._req_fi... | Upload a file ``filename`` to ``directory``
:param str filename: path to the file to upload
:param directory: destionation :class:`.Directory`, defaults to
:attribute:`.API.downloads_directory` if None
:return: the uploaded file
:rtype: :class:`.File` |
5,297 | def make_systemrestoreitem_originalfilename(original_filename, condition=, negate=False, preserve_case=False):
document =
search =
content_type =
content = original_filename
ii_node = ioc_api.make_indicatoritem_node(condition, document, search, content_type, content,
... | Create a node for SystemRestoreItem/OriginalFileName
:return: A IndicatorItem represented as an Element node |
5,298 | def get_collection(self, event_collection):
url = "{0}/{1}/projects/{2}/events/{3}".format(self.base_url, self.api_version,
self.project_id, event_collection)
headers = utilities.headers(self.read_key)
response = self.fulfill(HTTPM... | Extracts info about a collection using the Keen IO API. A master key must be set first.
:param event_collection: the name of the collection to retrieve info for |
5,299 | def generate_contentinfo_from_folder(self, csvwriter, rel_path, filenames):
LOGGER.debug( + str(rel_path) + + str(filenames))
from ricecooker.utils.linecook import filter_filenames, filter_thumbnail_files, chan_path_from_rel_path
topicrow = self.channeldir_node_to_row( rel_pa... | Create a topic node row in Content.csv for the folder at `rel_path` and
add content node rows for all the files in the `rel_path` folder. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.