text stringlengths 0 828 |
|---|
""""""Increments context variables |
"""""" |
for name, value in attrs.iteritems(): |
v = getattr(obj, name, None) |
if not hasattr(obj, name) or v is None: |
v = 0 |
setattr(obj, name, v + value)" |
1306,"def redirect(view=None, url=None, **kwargs): |
""""""Redirects to the specified view or url |
"""""" |
if view: |
if url: |
kwargs[""url""] = url |
url = flask.url_for(view, **kwargs) |
current_context.exit(flask.redirect(url))" |
1307,"def lines(query): |
""""""lines(query) -- print the number of lines in a given file |
"""""" |
filename = support.get_file_name(query) |
if(os.path.isfile(filename)): |
with open(filename) as openfile: |
print len(openfile.readlines()) |
else: |
print 'File not found : ' + filename" |
1308,"def words(query): |
""""""lines(query) -- print the number of words in a given file |
"""""" |
filename = support.get_file_name(query) |
if(os.path.isfile(filename)): |
with open(filename) as openfile: |
print len(openfile.read().split()) |
else: |
print 'File not found : ' + filename" |
1309,"def file_info(query): |
""""""file_info(query) -- print some human readable information of a given file |
"""""" |
filename = support.get_file_name(query) |
if(os.path.isfile(filename)): |
stat_info = os.stat(filename) |
owner_name = pwd.getpwuid(stat_info.st_uid).pw_name |
print 'owner : ' + owner_name |
file_size = support.get_readable_filesize(stat_info.st_size) |
print 'size : ' + file_size |
print 'created : ' + time.ctime(stat_info.st_ctime) |
print 'last modified : ' + time.ctime(stat_info.st_mtime) |
else: |
print 'file not found'" |
1310,"def make_executable(query): |
""""""make_executable(query) -- give executable permissions to a given file |
"""""" |
filename = support.get_file_name(query) |
if(os.path.isfile(filename)): |
os.system('chmod +x '+filename) |
else: |
print 'file not found'" |
1311,"def add_to_path(query): |
"""""" add_to_path(query) -- add user given path to environment PATH variable. |
"""""" |
new_entry = support.get_path(query) |
if(new_entry): |
print 'Adding '+new_entry+' to PATH variable.' |
print '''1 : confirm |
2 : cancel |
''' |
choice = int(raw_input('>> ')) |
if(choice == 1): |
home_dir = os.path.expanduser('~') |
bashrc = open(os.path.join(home_dir, "".bashrc""), ""a"") |
bashrc.write('\n\nexport PATH=\""'+new_entry+':$PATH\""\n') |
bashrc.close() |
os.system('source '+os.path.join(os.path.expanduser('~'),'.bashrc')) |
print 'Success!!' |
print os.system('echo $PATH') |
else: |
print 'We were unable to extract the \'path\' from your query.'" |
1312,"def system_info(query): |
""""""system_info(query) -- print system specific information like OS, kernel, |
architecture etc. |
"""""" |
proc = subprocess.Popen([""uname -o""], stdout=subprocess.PIPE, shell=True) |
(out, err) = proc.communicate() |
print ""operating system : ""+str(out), |
proc = subprocess.Popen([""uname""], stdout=subprocess.PIPE, shell=True) |
(out, err) = proc.communicate() |
print ""kernel : ""+str(out), |
proc = subprocess.Popen([""uname -r""], stdout=subprocess.PIPE, shell=True) |
(out, err) = proc.communicate() |
print ""kernel release : ""+str(out), |
proc = subprocess.Popen([""uname -m""], stdout=subprocess.PIPE, shell=True) |
(out, err) = proc.communicate() |
print ""architecture : ""+str(out), |
proc = subprocess.Popen([""uname -n""], stdout=subprocess.PIPE, shell=True) |
(out, err) = proc.communicate() |
print ""network node name : ""+str(out)," |
1313,"def statsd_metric(name, count, elapsed): |
""""""Metric that records to statsd & graphite"""""" |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.