I know the way to get list of all commands but idk how to get aliases list for all/specify command.
# List of all bot commands
bot_commands = [_.name for _ in self.bot.commands]
There's an aliases attribute for the command.
command_info = [f'{command.name} has aliases {command.aliases}' for command in self.bot.commands]
await ctx.send(command_info)
For example, this outputs
solved it ;)
# List of all bot commands with aliases
bot_commands = [
*[_.name for _ in self.bot.commands],
*sum([_.aliases for _ in self.bot.commands], [])
]
# aliases list for specify command
aliases = lambda c: [_.aliases for _ in self.bot.commands if _.name == c]
clear_aliases = aliases('clear')
# output for example - ['purge', 'p', 'c']
Related
I have a code
require 'rubygems'
conf_array = []
File.open("C:/My Program Files/readme.txt", "r").each_line do |line|
conf_array << line.chop.split("\t")
end
a = conf_array.index{|s| s.include?("server =")}
puts a
and it doesn't display the index of item. Why?
Array looks like
conf_array = [
["# This file can be used to override the default puppet settings."],
["# See the following links for more details on what settings are available:"],
["# - docs.puppetlabs.com/puppet/latest/reference/config_important_settings.html"],
["# - docs.puppetlabs.com/puppet/latest/reference/config_about_settings.html"],
["# - docs.puppetlabs.com/puppet/latest/reference/config_file_main.html"],
["# - docs.puppetlabs.com/references/latest/configuration.html"], ["[main]"],
["server = server.net.pl"],
["splay = true"],
["splaylimit = 1h"],
["wiatforcert = 30m"],
["http_connect_timeout = 2m"],
["http_read_timeout = 30m"],
["runinterval = 6h"],
["waitforcert = 30m"]
]
And next how to display that item? I mean a = conf_array[#{a}] says syntax error.
I tried also
new_array = []
new_array = conf_array.select! {|s| s.include?("server =")}
and it again does't display found item. Any suggestion?
Perfect use case for Enumerable#grep
File.open("C:/My Program Files/readme.txt", "r")
.each_line
# no need to .flat_map { |l| l.split(/\t/) }
.grep /server =/
#⇒ ["server = server.net.pl"]
The problem is that you don't call String#include?, but Array#include? :
["server = something.pl"].include?('server = ')
# false
"server = something.pl".include?('server = ')
# true
Remove the split("\t").
To read the file into an array, you can just use :
conf_array = File.readlines("C:/My Program Files/readme.txt")
or
conf_array = File.readlines("C:/My Program Files/readme.txt").map(&:chomp)
I have a line as:
Name:sample Location:(xyz)
I want to to convert it to dictionary as follows:
{'Name':'sample','Location':'(xyz)'}
I want to do this using python script. So, please suggest how do i make this possible. The platform i am working on is linux.
# First split at whitespaces ==> ['Name:sample', 'Location:(xyz)']
# Next split each item at ':' and convert them into list of tuples
# ==>[('Name', 'sample'), ('Location', '(xyz)')]
# Convert the list of tuples to dictionary
sample_string = "Name:sample Location:(xyz)"
split_sample_string = sample_string.split()
tuple_string = [tuple(item.split(":")) for item in split_sample_string]
final_dictionary = dict(tuple_string)
print final_dictionary
# final_dictionary = {'Name': 'sample', 'Location': '(xyz)'}
I am stuck with middle of the development, Need some help to resolve this. I want to add the Combobox to my interface and selection should come from text file.Text file have all the list of items. I want to put text file list to combobox and after select and click ok, should run with shell script. My code as below.
__author__ = 'shanaka'
from tkinter import *
from tkinter import filedialog
from tkinter.filedialog import askopenfilename
import subprocess
import os
from tkinter import messagebox
import Pmw
from tkinter import tix
################Options
def sel():
# selection = "You selected the option " + str(var.get())
if str(var.get()) == '1':
label.config(text= 'Windows is not supporting yet')
if str(var.get())== '2':
label.config(text = 'Linux is supporting')
####
def helloCallBack():
messagebox.showinfo( "Hello Python", "Hello World")
#######
def handle_selection():
print("You've selected: " + var1.get())
#################
root = Tk()
root.title("Volatility")
root.geometry("600x300")
#########OS Selection GUI
var = IntVar()
R1 = Radiobutton(root, text="Windows", variable=var, value=1,command=sel)
R1.grid( row=0, column=0, sticky=W )
R2 = Radiobutton(root, text="Linux", variable=var, value=2,command=sel)
#R2.pack( anchor = W )
R2.grid( row=1, column=0, sticky=W )
label = Label(root)
label.grid(row=3, column=0, sticky=W)
#########
########Get Dump GUI
DumpButton = Button(root, text ="Create Memory Dump", command = helloCallBack)
DumpButton.grid(row=2, column=0, sticky=W)
###############
######Copy Dump
CopyButton = Button(root, text ="Copy Dump to analyis directory", command = helloCallBack)
CopyButton.grid(row=4, column=0, sticky=W)
#############################
########Cobobox
with open('Plugins') as f:
lines = f.readlines()
# options = OptionMenu(root,var1,*lines)
options = Pmw.Combobox(root,label_text='Plugins',scrolledlist_items=[*lines])
options.grid(row=5, column=0,sticky=W)
options.selectitem(lines[1])
# var1.set(lines[1])
b = Button(root,text="Select", command = handle_selection , width=10)
b.grid(row=5,column=1,sticky=W)
root.mainloop()
But giving below error.
line 73
options = Pmw.Combobox(root,label_text='Plugins',scrolledlist_items=[*lines])
^
SyntaxError: can use starred expression only as assignment target
Still no luck :(, error as below- Traceback (most recent call last): File "/home/shanaka/PycharmProjects/volatility/main2.py", line 73, in options = Pmw.ComboBox(root,label_text='Plugins',scrolledlist_items=lines) File "/usr/local/lib/python3.4/dist-packages/Pmw/Pmw_2_0_0/lib/PmwComboBox.py", line 147, in init self.initialiseoptions() File "/usr/local/lib/python3.4/dist-packages/Pmw/Pmw_2_0_0/lib/PmwBase.py", line 599, in initialiseoptions '" for ' + self.class.name) TypeError: descriptor 'join' requires a 'str' object but received a 'list' –
Thanks for the Support I found the solution , I used ttk.ComboBox, rather using Pmw. Thank you Jonrsharp option = ttk.Combobox(root,state="readonly",values=(lines))
In Waf how can I create multiple custom tasks, that can run parallel (with --jobs=JOBS)?
Sources = ["C:\\src1.c", "C:\\Mod1\src2.c", ... 30pcs] # one per call
Incl_Paths = ["Mod1". "Mod1"] # list all of them in all call
INCL_ST = "-I%s" # how to format an include path in an argument
Ext_out = "_loc" # output file extension
The goal:
C:\\LOC.exe -IMod1 -IMod2 C:\\src1.c > build\\src1.c_loc //or better src1_loc
C:\\LOC.exe -IMod1 -IMod2 C:\\Mod1\src2.c > build\\src2.c_loc //or better src2_loc
...
I couldn't get it work
def build(bld):
for i in Sources:
bld.new_task_gen(
source = i,
rule='C:\\LOC.exe ${INCL_ST:Incl_Paths} ${SRC} > ' + i + Ext_out,
)
Also I couldn't extract the exe
# find_program(self, filename, path_list=[], var=None, environ=None, exts=''):
cfg.find_program("C:\\LOC.exe", var='LOC')
To change from:
rule='C:\\LOC.exe ...'
To:
rule='${LOC} ...'
Something like this should work with waf 1.7:
from waflib.Task import Task
from waflib.TaskGen import extension
Ext_out = "_loc" # output file extension
def configure(conf):
# loc.exe must be in the system path for this to work
conf.find_program(
'loc',
var = "LOC",
)
conf.env.Incl_Paths = ["Mod1", "Mod1"]
conf.env.INCL_ST = "-I%s"
#extension('.c')
def process_loc(self, node):
out_node = node.change_ext(Ext_out)
tsk = self.create_task('loc')
tsk.set_inputs(node)
tsk.set_outputs(out_node)
class loc_task(Task):
ext_in = ['.c']
ext_out = ['_loc']
run_str = "${LOC} ${INCL_ST:Incl_Paths} ${SRC} > ${TGT}"
def build(bld):
bld(source = ["src1.c", "src2.c"])
Well it works for me on linux faking loc ...
The waf command waf build shows compiler errors (if there are any) while waf debug or waf release does not and always fails, utilizing the following wscript file (or maybe the wscript file has some other shortcomings I am currently not aware of):
APPNAME = 'waftest'
VERSION = '0.0.1'
def configure(ctx):
ctx.load('compiler_c')
ctx.define('VERSION', VERSION)
ctx.define('GETTEXT_PACKAGE', APPNAME)
ctx.check_cfg(atleast_pkgconfig_version='0.1.1')
ctx.check_cfg(package='glib-2.0', uselib_store='GLIB', args=['--cflags', '--libs'], mandatory=True)
ctx.check_cfg(package='gobject-2.0', uselib_store='GOBJECT', args=['--cflags', '--libs'], mandatory=True)
ctx.check_cfg(package='gtk+-3.0', uselib_store='GTK3', args=['--cflags', '--libs'], mandatory=True)
ctx.check_cfg(package='libxml-2.0', uselib_store='XML', args=['--cflags', '--libs'], mandatory=True)
ctx.check_large_file(mandatory=False)
ctx.check_endianness(mandatory=False)
ctx.check_inline(mandatory=False)
ctx.setenv('debug')
ctx.env.CFLAGS = ['-g', '-Wall']
ctx.define('DEBUG',1)
ctx.setenv('release')
ctx.env.CFLAGS = ['-O2', '-Wall']
ctx.define('RELEASE',1)
def pre(ctx):
print ('Building [[[' + ctx.variant + ']]] ...')
def post(ctx):
print ('Building is complete.')
def build(ctx):
ctx.add_pre_fun(pre)
ctx.add_post_fun(post)
# if not ctx.variant:
# ctx.fatal('Do "waf debug" or "waf release"')
exe = ctx.program(
features = ['c', 'cprogram'],
target = APPNAME+'.bin',
source = ctx.path.ant_glob(['src/*.c']),
includes = ['src/'],
export_includes = ['src/'],
uselib = 'GOBJECT GLIB GTK3 XML'
)
# for item in exe.includes:
# print(item)
from waflib.Build import BuildContext
class release(BuildContext):
cmd = 'release'
variant = 'release'
class debug(BuildContext):
cmd = 'debug'
variant = 'debug'
Error resulting from waf debug :
Build failed
-> task in 'waftest.bin' failed (exit status -1):
{task 46697488: c qqq.c -> qqq.c.1.o}
[useless filepaths]
I had a look at the waf demos, read the wafbook at section 6.2.2 but those did not supply me with valuable information in order to fix this issue.
What's wrong, and how do I fix it?
You need to do at least the following:
def configure(ctx):
...
ctx.setenv('debug')
ctx.load('compiler_c')
...
Since the cfg.setenv function resets whole previous environment. If you want to save previous environment, you can do cfg.setenv('debug', env=cfg.env.derive()).
Also, you don't need to explicitly specify the features = ['c', 'cprogram'], since, it's redundant, when you call bld.program(...).
P.S. Don't forget to reconfigure after modifying wscript file.