text_prompt stringlengths 157 13.1k | code_prompt stringlengths 7 19.8k ⌀ |
|---|---|
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def addChildren(self, child_ids):
"""Add children to current workitem :param child_ids: a :class:`list` contains the children workitem id/number (integer or equi... |
if not hasattr(child_ids, "__iter__"):
error_msg = "Input parameter 'child_ids' is not iterable"
self.log.error(error_msg)
raise exception.BadValue(error_msg)
self.log.debug("Try to add children <Workitem %s> to current "
"<Workitem %s>",
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def removeParent(self):
"""Remove the parent workitem from current workitem Notice: for a certain workitem, no more than one parent workitem can be added and spe... |
self.log.debug("Try to remove the parent workitem from current "
"<Workitem %s>",
self)
headers = copy.deepcopy(self.rtc_obj.headers)
headers["Content-Type"] = self.OSLC_CR_JSON
req_url = "".join([self.url,
"?osl... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def removeChild(self, child_id):
"""Remove a child from current workitem :param child_id: the child workitem id/number (integer or equivalent string) """ |
self.log.debug("Try to remove a child <Workitem %s> from current "
"<Workitem %s>",
child_id,
self)
self._removeChildren([child_id])
self.log.info("Successfully remove a child <Workitem %s> from "
"curre... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def removeChildren(self, child_ids):
"""Remove children from current workitem :param child_ids: a :class:`list` contains the children workitem id/number (integer... |
if not hasattr(child_ids, "__iter__"):
error_msg = "Input parameter 'child_ids' is not iterable"
self.log.error(error_msg)
raise exception.BadValue(error_msg)
self.log.debug("Try to remove children <Workitem %s> from current "
"<Workitem %s>"... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def addAttachment(self, filepath):
"""Upload attachment to a workitem :param filepath: the attachment file path :return: the :class:`rtcclient.models.Attachment`... |
proj_id = self.contextId
fa = self.rtc_obj.getFiledAgainst(self.filedAgainst,
projectarea_id=proj_id)
fa_id = fa.url.split("/")[-1]
headers = copy.deepcopy(self.rtc_obj.headers)
if headers.__contains__("Content-Type"):
hea... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def list_containers(active=True, defined=True, as_object=False, config_path=None):
""" List the containers on the system. """ |
if config_path:
if not os.path.exists(config_path):
return tuple()
try:
entries = _lxc.list_containers(active=active, defined=defined,
config_path=config_path)
except ValueError:
return tuple()
else:
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def attach_run_command(cmd):
""" Run a command when attaching Please do not call directly, this will execvp the command. This is to be used in conjunction with t... |
if isinstance(cmd, tuple):
return _lxc.attach_run_command(cmd)
elif isinstance(cmd, list):
return _lxc.attach_run_command((cmd[0], cmd))
else:
return _lxc.attach_run_command((cmd, [cmd])) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def arch_to_personality(arch):
""" Determine the process personality corresponding to the architecture """ |
if isinstance(arch, bytes):
arch = unicode(arch)
return _lxc.arch_to_personality(arch) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def add_device_net(self, name, destname=None):
""" Add network device to running container. """ |
if not self.running:
return False
if os.path.exists("/sys/class/net/%s/phy80211/name" % name):
with open("/sys/class/net/%s/phy80211/name" % name) as fd:
phy = fd.read().strip()
if subprocess.call(['iw', 'phy', phy, 'set', 'netns',
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def append_config_item(self, key, value):
""" Append 'value' to 'key', assuming 'key' is a list. If 'key' isn't a list, 'value' will be set as the value of 'key'... |
return _lxc.Container.set_config_item(self, key, value) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def create(self, template=None, flags=0, args=()):
""" Create a new rootfs for the container. "template" if passed must be a valid template name. "flags" (option... |
if isinstance(args, dict):
template_args = []
for item in args.items():
template_args.append("--%s" % item[0])
template_args.append("%s" % item[1])
else:
template_args = args
if template:
return _lxc.Container.cre... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def clone(self, newname, config_path=None, flags=0, bdevtype=None, bdevdata=None, newsize=0, hookargs=()):
""" Clone the current container. """ |
args = {}
args['newname'] = newname
args['flags'] = flags
args['newsize'] = newsize
args['hookargs'] = hookargs
if config_path:
args['config_path'] = config_path
if bdevtype:
args['bdevtype'] = bdevtype
if bdevdata:
ar... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_cgroup_item(self, key):
""" Returns the value for a given cgroup entry. A list is returned when multiple values are set. """ |
value = _lxc.Container.get_cgroup_item(self, key)
if value is False:
return False
else:
return value.rstrip("\n") |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_config_item(self, key):
""" Returns the value for a given config key. A list is returned when multiple values are set. """ |
value = _lxc.Container.get_config_item(self, key)
if value is False:
return False
elif value.endswith("\n"):
return value.rstrip("\n").split("\n")
else:
return value |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_keys(self, key=None):
""" Returns a list of valid sub-keys. """ |
if key:
value = _lxc.Container.get_keys(self, key)
else:
value = _lxc.Container.get_keys(self)
if value is False:
return False
elif value.endswith("\n"):
return value.rstrip("\n").split("\n")
else:
return value |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_ips(self, interface=None, family=None, scope=None, timeout=0):
""" Get a tuple of IPs for the container. """ |
kwargs = {}
if interface:
kwargs['interface'] = interface
if family:
kwargs['family'] = family
if scope:
kwargs['scope'] = scope
ips = None
timeout = int(os.environ.get('LXC_GETIP_TIMEOUT', timeout))
while not ips:
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def rename(self, new_name):
""" Rename the container. On success, returns the new Container object. On failure, returns False. """ |
if _lxc.Container.rename(self, new_name):
return Container(new_name)
return False |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def set_config_item(self, key, value):
""" Set a config key to a provided value. The value can be a list for the keys supporting multiple values. """ |
try:
old_value = self.get_config_item(key)
except KeyError:
old_value = None
# Get everything to unicode with python2
if isinstance(value, str):
value = value.decode()
elif isinstance(value, list):
for i in range(len(value)):
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def wait(self, state, timeout=-1):
""" Wait for the container to reach a given state or timeout. """ |
if isinstance(state, str):
state = state.upper()
return _lxc.Container.wait(self, state, timeout) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def render(self, template, **kwargs):
"""Renders the template :param template: The template to render. The template is actually a file, which is usually generate... |
try:
temp = self.environment.get_template(template)
return temp.render(**kwargs)
except AttributeError:
err_msg = "Invalid value for 'template'"
self.log.error(err_msg)
raise exception.BadValue(err_msg) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def listFields(self, template):
"""List all the attributes to be rendered from the template file :param template: The template to render. The template is actuall... |
try:
temp_source = self.environment.loader.get_source(self.environment,
template)
return self.listFieldsFromSource(temp_source)
except AttributeError:
err_msg = "Invalid value for 'template'"
s... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def listFieldsFromSource(self, template_source):
"""List all the attributes to be rendered directly from template source :param template_source: the template sou... |
ast = self.environment.parse(template_source)
return jinja2.meta.find_undeclared_variables(ast) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def _get_file(self):
'''
return an opened tempfile pointer that can be used
http://docs.python.org/2/library/tempfile.html
'''
f = tempfile.NamedTemporaryFile(delete=False)
self.tmp_files.add(f.name)
return f |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _get_args(self, executable, *args):
"""compile all the executable and the arguments, combining with common arguments to create a full batch of command args""... |
args = list(args)
args.insert(0, executable)
if self.username:
args.append("--username={}".format(self.username))
if self.host:
args.append("--host={}".format(self.host))
if self.port:
args.append("--port={}".format(self.port))
args.a... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _get_outfile_path(self, table):
"""return the path for a file we can use to back up the table""" |
self.outfile_count += 1
outfile = os.path.join(self.directory, '{:03d}_{}.sql.gz'.format(self.outfile_count, table))
return outfile |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _run_queries(self, queries, *args, **kwargs):
"""run the queries queries -- list -- the queries to run return -- string -- the results of the query? """ |
# write out all the commands to a temp file and then have psql run that file
f = self._get_file()
for q in queries:
f.write("{};\n".format(q))
f.close()
psql_args = self._get_args('psql', '-X', '-f {}'.format(f.name))
return self._run_cmd(' '.join(psql_args)... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _restore_auto_increment(self, table):
"""restore the auto increment value for the table to what it was previously""" |
query, seq_table, seq_column, seq_name = self._get_auto_increment_info(table)
if query:
queries = [query, "select nextval('{}')".format(seq_name)]
return self._run_queries(queries) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _get_auto_increment_info(self, table):
"""figure out the the autoincrement value for the given table""" |
query = ''
seq_table = ''
seq_column = ''
seq_name = ''
find_query = "\n".join([
"SELECT",
" t.relname as related_table,",
" a.attname as related_column,",
" s.relname as sequence_name",
"FROM pg_class s",
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def restore(self):
"""use the self.directory to restore a db NOTE -- this will only restore a database dumped with one of the methods of this class """ |
sql_files = []
for root, dirs, files in os.walk(self.directory):
for f in files:
if f.endswith(".sql.gz"):
path = os.path.join(self.directory, f)
self._run_cmd(["gunzip", path])
sql_files.append(f.rstrip(".gz"))
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _get_env(self):
"""this returns an environment dictionary we want to use to run the command this will also create a fake pgpass file in order to make it poss... |
if hasattr(self, 'env'): return self.env
# create a temporary pgpass file
pgpass = self._get_file()
# format: http://www.postgresql.org/docs/9.2/static/libpq-pgpass.html
pgpass.write('*:*:*:{}:{}\n'.format(self.username, self.password).encode("utf-8"))
pgpass.close()
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _get_response(**kwargs):
"""Get a template response Use kwargs to add things to the dictionary """ |
if 'code' not in kwargs:
kwargs['code'] = 200
if 'headers' not in kwargs:
kwargs['headers'] = dict()
if 'version' not in kwargs:
kwargs['version'] = 'HTTP/1.1'
return dict(**kwargs) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _write_transport(self, string):
"""Convenience function to write to the transport""" |
if isinstance(string, str): # we need to convert to bytes
self.transport.write(string.encode('utf-8'))
else:
self.transport.write(string) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _write_response(self, response):
"""Write the response back to the client Arguments: response -- the dictionary containing the response. """ |
status = '{} {} {}\r\n'.format(response['version'],
response['code'],
responses[response['code']])
self.logger.debug("Responding status: '%s'", status.strip())
self._write_transport(status)
if 'body' in respo... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def connection_made(self, transport):
"""Called when the connection is made""" |
self.logger.info('Connection made at object %s', id(self))
self.transport = transport
self.keepalive = True
if self._timeout:
self.logger.debug('Registering timeout event')
self._timout_handle = self._loop.call_later(
self._timeout, self._handle_... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def connection_lost(self, exception):
"""Called when the connection is lost or closed. The argument is either an exception object or None. The latter means a reg... |
if exception:
self.logger.exception('Connection lost!')
else:
self.logger.info('Connection lost') |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def data_received(self, data):
"""Process received data from the socket Called when we receive data """ |
self.logger.debug('Received data: %s', repr(data))
try:
request = self._parse_headers(data)
self._handle_request(request)
except InvalidRequestError as e:
self._write_response(e.get_http_response())
if not self.keepalive:
if self._timeou... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _get_request_uri(self, request):
"""Parse the request URI into something useful Server MUST accept full URIs (5.1.2)""" |
request_uri = request['target']
if request_uri.startswith('/'): # eg. GET /index.html
return (request.get('Host', 'localhost').split(':')[0],
request_uri[1:])
elif '://' in request_uri: # eg. GET http://rded.nl
locator = request_uri.split('://', 1)[... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _handle_request(self, request):
"""Process the headers and get the file""" |
# Check if this is a persistent connection.
if request['version'] == 'HTTP/1.1':
self.keepalive = not request.get('Connection') == 'close'
elif request['version'] == 'HTTP/1.0':
self.keepalive = request.get('Connection') == 'Keep-Alive'
# Check if we're getting... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_http_response(self):
"""Get this exception as an HTTP response suitable for output""" |
return _get_response(
code=self.code,
body=str(self),
headers={
'Content-Type': 'text/plain'
}
) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _start_server(bindaddr, port, hostname, folder):
"""Starts an asyncio server""" |
import asyncio
from .httpserver import HttpProtocol
loop = asyncio.get_event_loop()
coroutine = loop.create_server(lambda: HttpProtocol(hostname, folder),
bindaddr,
port)
server = loop.run_until_complete(coroutine)
print('St... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def run(argv=None):
# pragma: no cover """Run the HTTP server Usage: httpserver [options] [<folder>] Options:: -h,--host=<hostname> What host name to serve (defa... |
import sys
import os
import docopt
import textwrap
# Check for the version
if not sys.version_info >= (3, 4):
print('This python version is not supported. Please use python 3.4')
exit(1)
argv = argv or sys.argv[1:]
# remove some RST formatting
docblock = run.__doc... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def reading(self):
"""Open url and read """ |
try:
# testing proxy
proxies = {}
try:
proxies["http_proxy"] = os.environ['http_proxy']
except KeyError:
pass
try:
proxies["https_proxy"] = os.environ['https_proxy']
except KeyError:
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def repos(self):
"""View or enabled or disabled repositories """ |
def_cnt, cus_cnt = 0, 0
print("")
self.msg.template(78)
print("{0}{1}{2}{3}{4}{5}{6}".format(
"| Repo id", " " * 2,
"Repo URL", " " * 44,
"Default", " " * 3,
"Status"))
self.msg.template(78)
for repo_id, repo_URL in sorted(... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def view(self):
"""View slpkg config file """ |
print("") # new line at start
conf_args = [
"RELEASE",
"SLACKWARE_VERSION",
"COMP_ARCH",
"BUILD_PATH",
"PACKAGES",
"PATCHES",
"CHECKMD5",
"DEL_ALL",
"DEL_BUILD",
"SBO_BUILD_LOG",
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def edit(self):
"""Edit configuration file """ |
subprocess.call("{0} {1}".format(self.meta.editor,
self.config_file), shell=True) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def reset(self):
"""Reset slpkg.conf file with default values """ |
shutil.copy2(self.config_file + ".orig", self.config_file)
if filecmp.cmp(self.config_file + ".orig", self.config_file):
print("{0}The reset was done{1}".format(
self.meta.color["GREEN"], self.meta.color["ENDC"]))
else:
print("{0}Reset failed{1}".format(s... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get(self):
"""Return sbo arch """ |
if self.arch.startswith("i") and self.arch.endswith("86"):
self.arch = self.x86
elif self.meta.arch.startswith("arm"):
self.arch = self.arm
return self.arch |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def case_sensitive(self, lst):
"""Create dictionary from list with key in lower case and value with default """ |
dictionary = {}
for pkg in lst:
dictionary[pkg.lower()] = pkg
return dictionary |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def remove_dbs(self, double):
"""Remove double item from list """ |
one = []
for dup in double:
if dup not in one:
one.append(dup)
return one |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def read_file(self, registry):
"""Returns reading file """ |
with open(registry, "r") as file_txt:
read_file = file_txt.read()
file_txt.close()
return read_file |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def package_name(self, PACKAGES_TXT):
"""Returns list with all the names of packages repository """ |
packages = []
for line in PACKAGES_TXT.splitlines():
if line.startswith("PACKAGE NAME:"):
packages.append(split_package(line[14:].strip())[0])
return packages |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def check_downloaded(self, path, maybe_downloaded):
"""Check if files downloaded and return downloaded packages """ |
downloaded = []
for pkg in maybe_downloaded:
if os.path.isfile(path + pkg):
downloaded.append(pkg)
return downloaded |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def dependencies(self, deps_dict):
"""Generate graph file with depenndencies map tree """ |
try:
import pygraphviz as pgv
except ImportError:
graph_easy, comma = "", ""
if (self.image == "ascii" and
not os.path.isfile("/usr/bin/graph-easy")):
comma = ","
graph_easy = " graph-easy"
print("Requir... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def check_file(self):
"""Check for file format and type """ |
try:
image_type = ".{0}".format(self.image.split(".")[1])
if image_type not in self.file_format:
print("Format: '{0}' not recognized. Use one of "
"them:\n{1}".format(self.image.split(".")[1],
", ".join(self... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def graph_easy(self):
"""Draw ascii diagram. graph-easy perl module require """ |
if not os.path.isfile("/usr/bin/graph-easy"):
print("Require 'graph-easy': Install with 'slpkg -s sbo "
"graph-easy'")
self.remove_dot()
raise SystemExit()
subprocess.call("graph-easy {0}.dot".format(self.image), shell=True)
self.remove_dot(... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def remove_dot(self):
"""Remove .dot files """ |
if os.path.isfile("{0}.dot".format(self.image)):
os.remove("{0}.dot".format(self.image)) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def alien_filter(packages, sizes):
"""This filter avoid list double packages from alien repository """ |
cache, npkg, nsize = [], [], []
for p, s in zip(packages, sizes):
name = split_package(p)[0]
if name not in cache:
cache.append(name)
npkg.append(p)
nsize.append(s)
return npkg, nsize |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def upgrade(self, flag):
"""Upgrade Slackware binary packages with new """ |
for pkg in self.binary:
try:
subprocess.call("upgradepkg {0} {1}".format(flag, pkg),
shell=True)
check = pkg[:-4].split("/")[-1]
if os.path.isfile(self.meta.pkg_path + check):
print("Completed!\n")
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def remove(self, flag, extra):
"""Remove Slackware binary packages """ |
self.flag = flag
self.extra = extra
self.dep_path = self.meta.log_path + "dep/"
dependencies, rmv_list = [], []
self.removed = self._view_removed()
if not self.removed:
print("") # new line at end
else:
msg = "package"
if len... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _rmv_deps_answer(self):
"""Remove dependencies answer """ |
if self.meta.remove_deps_answer in ["y", "Y"]:
remove_dep = self.meta.remove_deps_answer
else:
try:
remove_dep = raw_input(
"\nRemove dependencies (maybe used by "
"other packages) [y/N]? ")
print("")
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _get_removed(self):
"""Manage removed packages by extra options """ |
removed, packages = [], []
if "--tag" in self.extra:
for pkg in find_package("", self.meta.pkg_path):
for tag in self.binary:
if pkg.endswith(tag):
removed.append(split_package(pkg)[0])
packages.append(pkg)
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _view_removed(self):
"""View packages before removed """ |
print("\nPackages with name matching [ {0}{1}{2} ]\n".format(
self.meta.color["CYAN"], ", ".join(self.binary),
self.meta.color["ENDC"]))
removed, packages = self._get_removed()
if packages and "--checklist" in self.extra:
removed = []
text = "Pres... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _calc_sizes(self):
"""Package size calculation """ |
if self.size > 1024:
self.unit = "Mb"
self.size = (self.size / 1024)
if self.size > 1024:
self.unit = "Gb"
self.size = (self.size / 1024) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _remove_summary(self):
"""Removed packge size summary """ |
if self.size > 0:
print("\nRemoved summary")
print("=" * 79)
print("{0}Size of removed packages {1} {2}.{3}".format(
self.meta.color["GREY"], round(self.size, 2), self.unit,
self.meta.color["ENDC"])) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _view_deps(self, path, package):
"""View dependencies before remove """ |
self.size = 0
packages = []
dependencies = (Utils().read_file(path + package)).splitlines()
for dep in dependencies:
if GetFromInstalled(dep).name():
ver = GetFromInstalled(dep).version()
packages.append(dep + ver)
else:
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _removepkg(self, package):
"""removepkg Slackware command """ |
try:
subprocess.call("removepkg {0} {1}".format(self.flag, package),
shell=True)
if os.path.isfile(self.dep_path + package):
os.remove(self.dep_path + package) # remove log
except subprocess.CalledProcessError as er:
print... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _rmv_pkg(self, package):
"""Remove one signle package """ |
removes = []
if GetFromInstalled(package).name() and package not in self.skip:
ver = GetFromInstalled(package).version()
removes.append(package + ver)
self._removepkg(package)
return removes |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _skip_remove(self):
"""Skip packages from remove """ |
if "--checklist" not in self.extra:
self.msg.template(78)
print("| Insert packages to exception remove:")
self.msg.template(78)
try:
self.skip = raw_input(" > ").split()
except EOFError:
print("")
raise ... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _check_if_used(self, removes):
"""Check package if dependencies for another package before removed""" |
if "--check-deps" in self.extra:
package, dependency, pkg_dep = [], [], []
for pkg in find_package("", self.dep_path):
deps = Utils().read_file(self.dep_path + pkg)
for rmv in removes:
if GetFromInstalled(rmv).name() and rmv in deps.sp... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _reference_rmvs(self, removes):
"""Prints all removed packages """ |
print("")
self.msg.template(78)
msg_pkg = "package"
if len(removes) > 1:
msg_pkg = "packages"
print("| Total {0} {1} removed".format(len(removes), msg_pkg))
self.msg.template(78)
for pkg in removes:
if not GetFromInstalled(pkg).name():
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def find(self, flag):
"""Find installed Slackware packages """ |
matching, pkg_cache, match_cache = 0, "", ""
print("\nPackages with matching name [ {0}{1}{2} ]\n".format(
self.meta.color["CYAN"], ", ".join(self.binary),
self.meta.color["ENDC"]))
for pkg in self.binary:
for match in find_package("", self.meta.pkg_path):
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _sizes(self, package):
"""Package size summary """ |
data = Utils().read_file(self.meta.pkg_path + package)
for line in data.splitlines():
if line.startswith("UNCOMPRESSED PACKAGE SIZE:"):
digit = float((''.join(re.findall(
"[-+]?\d+[\.]?\d*[eE]?[-+]?\d*", line[26:]))))
self.file_size = line... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def display(self):
"""Print the Slackware packages contents """ |
for pkg in self.binary:
name = GetFromInstalled(pkg).name()
ver = GetFromInstalled(pkg).version()
find = find_package("{0}{1}{2}".format(name, ver, self.meta.sp),
self.meta.pkg_path)
if find:
package = Utils().read_... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def package_list(self, repo, name, INDEX, installed):
"""List with the installed packages """ |
tty_size = os.popen("stty size", "r").read().split()
row = int(tty_size[0]) - 2
try:
all_installed_names = []
index, page, pkg_list = 0, row, []
r = self.list_lib(repo)
pkg_list = self.list_greps(repo, r)[0]
all_installed_names = self.... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _splitting_packages(self, pkg, repo, name):
"""Return package name from repositories """ |
if name and repo != "sbo":
pkg = split_package(pkg)[0]
elif not name and repo != "sbo":
pkg = pkg[:-4]
return pkg |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def list_lib(self, repo):
"""Return package lists """ |
packages = ""
if repo == "sbo":
if (os.path.isfile(
self.meta.lib_path + "{0}_repo/SLACKBUILDS.TXT".format(
repo))):
packages = Utils().read_file(self.meta.lib_path + "{0}_repo/"
"SLACKB... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def list_color_tag(self, pkg):
"""Tag with color installed packages """ |
name = GetFromInstalled(pkg).name()
find = name + self.meta.sp
if pkg.endswith(".txz") or pkg.endswith(".tgz"):
find = pkg[:-4]
if find_package(find, self.meta.pkg_path):
pkg = "{0}{1}{2}".format(self.meta.color["GREEN"], pkg,
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def list_of_installed(self, repo, name):
"""Return installed packages """ |
all_installed_names = []
all_installed_packages = find_package("", self.meta.pkg_path)
for inst in all_installed_packages:
if repo == "sbo" and inst.endswith("_SBo"):
name = split_package(inst)[0]
all_installed_names.append(name)
else:
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def rlw_filter(name, location, size, unsize):
"""Filter rlw repository data """ |
arch = _meta_.arch
if arch.startswith("i") and arch.endswith("86"):
arch = "i486"
(fname, flocation, fsize, funsize) = ([] for i in range(4))
for n, l, s, u in zip(name, location, size, unsize):
loc = l.split("/")
if arch == loc[-1]:
fname.append(n)
floca... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def alien_filter(name, location, size, unsize):
"""Fix to avoid packages include in slackbuilds folder """ |
(fname, flocation, fsize, funsize) = ([] for i in range(4))
for n, l, s, u in zip(name, location, size, unsize):
if "slackbuilds" != l:
fname.append(n)
flocation.append(l)
fsize.append(s)
funsize.append(u)
return [fname, flocation, fsize, funsize] |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def rested_filter(name, location, size, unsize):
"""Filter Alien"s repository data """ |
ver = slack_ver()
if _meta_.slack_rel == "current":
ver = "current"
path_pkg = "pkg"
if _meta_.arch == "x86_64":
path_pkg = "pkg64"
(fname, flocation, fsize, funsize) = ([] for i in range(4))
for n, l, s, u in zip(name, location, size, unsize):
if path_pkg == l.split("/"... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_deps(self):
"""Grap package requirements from repositories """ |
if self.repo == "rlw":
dependencies = {}
rlw_deps = Utils().read_file(_meta_.conf_path + "rlworkman.deps")
for line in rlw_deps.splitlines():
if line and not line.startswith("#"):
pkgs = line.split(":")
dependencies[pkg... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _req_fix(self, line):
"""Fix slacky and salix requirements because many dependencies splitting with "," and others with "|" """ |
deps = []
for dep in line[18:].strip().split(","):
dep = dep.split("|")
if self.repo == "slacky":
if len(dep) > 1:
for d in dep:
deps.append(d.split()[0])
dep = "".join(dep)
deps.append(d... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def run(self):
"""print .new configuration files """ |
self.find_new()
for n in self.news:
print("{0}".format(n))
print("")
self.msg.template(78)
print("| Installed {0} new configuration files:".format(
len(self.news)))
self.msg.template(78)
self.choices() |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def choices(self):
"""Menu options for new configuration files """ |
print("| {0}K{1}{2}eep the old and .new files, no changes".format(
self.red, self.endc, self.br))
print("| {0}O{1}{2}verwrite all old configuration files with new "
"ones".format(self.red, self.endc, self.br))
print("| The old files will be saved with suffix .old")
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def question(self, n):
"""Choose what do to file by file """ |
print("")
prompt_ask = raw_input("{0} [K/O/R/D/M/Q]? ".format(n))
print("")
if prompt_ask in ("K", "k"):
self.keep()
elif prompt_ask in ("O", "o"):
self._overwrite(n)
elif prompt_ask in ("R", "r"):
self._remove(n)
elif prompt_a... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _remove(self, n):
"""Remove one single file """ |
if os.path.isfile(n):
os.remove(n)
if not os.path.isfile(n):
print("File '{0}' removed".format(n)) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _overwrite(self, n):
"""Overwrite old file with new and keep file with suffix .old """ |
if os.path.isfile(n[:-4]):
shutil.copy2(n[:-4], n[:-4] + ".old")
print("Old file {0} saved as {1}.old".format(
n[:-4].split("/")[-1], n[:-4].split("/")[-1]))
if os.path.isfile(n):
shutil.move(n, n[:-4])
print("New file {0} overwrite as {1}... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def diff(self, n):
"""Print the differences between the two files """ |
if os.path.isfile(n[:-4]):
diff1 = Utils().read_file(n[:-4]).splitlines()
if os.path.isfile(n):
diff2 = Utils().read_file(n).splitlines()
lines, l, c = [], 0, 0
for a, b in itertools.izip_longest(diff1, diff2):
l += 1
if a != b:
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def merge(self, n):
"""Merge new file into old """ |
if os.path.isfile(n[:-4]):
old = Utils().read_file(n[:-4]).splitlines()
if os.path.isfile(n):
new = Utils().read_file(n).splitlines()
with open(n[:-4], "w") as out:
for l1, l2 in itertools.izip_longest(old, new):
if l1 is None:
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def status_bar(self):
"""Top view bar status """ |
print("")
self.msg.template(78)
print("| Repository Status")
self.msg.template(78) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def run(self):
"""Run and check if new in ChangeLog.txt """ |
if (self.repo in self.meta.default_repositories and
self.repo in self.meta.repositories):
try:
self.check = self.all_repos[self.repo]()
except OSError:
usage(self.repo)
raise SystemExit()
elif self.repo in self.meta... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def md5(source):
"""Return MD5 Checksum """ |
# fix passing char '+' from source
source = source.replace("%2B", "+")
with open(source) as file_to_check:
data = file_to_check.read()
return hashlib.md5(data).hexdigest() |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def run(self):
"""Run tracking dependencies """ |
self.msg.resolving()
self.repositories()
if self.find_pkg:
self.dependencies_list.reverse()
self.requires = Utils().dimensional_list(self.dependencies_list)
self.dependencies = Utils().remove_dbs(self.requires)
if self.dependencies == []:
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def repositories(self):
"""Get dependencies by repositories """ |
if self.repo == "sbo":
self.sbo_case_insensitive()
self.find_pkg = sbo_search_pkg(self.name)
if self.find_pkg:
self.dependencies_list = Requires(self.flag).sbo(self.name)
else:
PACKAGES_TXT = Utils().read_file(
self.meta.li... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def sbo_case_insensitive(self):
"""Matching packages distinguish between uppercase and lowercase for sbo repository """ |
if "--case-ins" in self.flag:
data = SBoGrep(name="").names()
data_dict = Utils().case_sensitive(data)
for key, value in data_dict.iteritems():
if key == self.name.lower():
self.name = value |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def check_used(self, pkg):
"""Check if dependencies used """ |
used = []
dep_path = self.meta.log_path + "dep/"
logs = find_package("", dep_path)
for log in logs:
deps = Utils().read_file(dep_path + log)
for dep in deps.splitlines():
if pkg == dep:
used.append(log)
return used |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def deps_tree(self):
"""Package dependencies image map file """ |
dependencies = self.dependencies + [self.name]
if self.repo == "sbo":
for dep in dependencies:
deps = Requires(flag="").sbo(dep)
if dep not in self.deps_dict.values():
self.deps_dict[dep] = Utils().dimensional_list(deps)
else:
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def deps_used(self, pkg, used):
"""Create dependencies dictionary """ |
if find_package(pkg + self.meta.sp, self.meta.pkg_path):
if pkg not in self.deps_dict.values():
self.deps_dict[pkg] = used
else:
self.deps_dict[pkg] += used |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def version(self):
"""Return version from installed packages """ |
if self.find:
return self.meta.sp + split_package(self.find)[1]
return "" |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.