本文整理汇总了Python中utils.msg函数的典型用法代码示例。如果您正苦于以下问题:Python msg函数的具体用法?Python msg怎么用?Python msg使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了msg函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: summary
def summary(self, unabridged=False):
props= ("watching_r "
"u_watching "
"r_info "
"r_name "
"r_langs "
"forks_of_r "
"parent_of_r "
"gparent_of_r "
"lang_by_r "
"u_authoring "
).split()
for prop in props:
print(">> %s" % prop)
if unabridged:
pprint(dict(getattr(self, prop)).items())
else:
pprint(dict(getattr(self, prop)).items()[:5])
print("")
msg(">> test_u")
if unabridged:
pprint(self.test_u)
else:
pprint(self.test_u[:5])
示例2: search
def search(self, keyword):
if keyword is None:
return None
try:
msg("Connecting to shell-storm.org...")
s = http.client.HTTPConnection("shell-storm.org")
s.request("GET", "/api/?s="+str(keyword))
res = s.getresponse()
data_l = res.read().split('\n')
except:
error_msg("Cannot connect to shell-storm.org")
return None
data_dl = []
for data in data_l:
try:
desc = data.split("::::")
dico = {
'ScAuthor': desc[0],
'ScArch': desc[1],
'ScTitle': desc[2],
'ScId': desc[3],
'ScUrl': desc[4]
}
data_dl.append(dico)
except:
pass
return data_dl
示例3: console
def console(results):
"""
Just prints results into your neat terminal window.
"""
results = sorted(
results,
key=lambda res: (res.exception is None, res.location)
)
for idx, result in enumerate(results):
if result.exception:
title = msg(result.location, TITLE_COLOR, attrs=["bold"])
title += msg(
u" ({}) ".format(text_type(result.exception)),
EXCEPTION_COLOR, attrs=["bold"]
)
title += LOCATION_DELIMETER * (STDOUT_WIDTH - len(title))
print_(title)
continue
if len(results) > 1:
title = msg(result.location + u" ", TITLE_COLOR)
title += LOCATION_DELIMETER * (STDOUT_WIDTH - len(title))
print_(title)
for track_idx, (title, length) in enumerate(result.data, start=1):
message = str(track_idx)
message += CSV_DELIMIETER
message += msg(title.replace("|", r"\|"), attrs=["bold"])
message += CSV_DELIMIETER
message += length
print_(message)
if idx < len(results) - 1:
print_("")
示例4: parse_lang
def parse_lang(self):
"""Parse the repos langs information from file "lang.txt"
"""
msg("parsing lang.txt")
lines = file('/'.join((self.datadir,"lang.txt"))).read().split('\n')
pairs = [line.split(":") for line in lines if line]
pairs = [(int(pair[0]),
[tuple(x.split(";")) for x in pair[1].split(",")])
for pair in pairs]
pairs = [(x, tuple([(int(z[1]), z[0].lower()) for z in y]))
for (x, y) in pairs]
all_langs = defaultdict(bool)
for repos, langs in pairs:
for kloc, lang in langs:
all_langs[lang]=True
all_langs = sorted(all_langs.keys())
msg("building lang_by_r and r_langs")
for repos, langs in pairs:
for kloc, lang in langs:
lnloc = int(log(kloc + 1, 10))
self.lang_by_r[lang].append((lnloc, repos))
self.r_langs[repos].append((lang,lnloc))
for lang in self.lang_by_r.keys():
self.lang_by_r[lang].sort(key=lambda x:x[1])
示例5: parse_repos
def parse_repos(self):
"""Parse repos information from file "repos.txt"
"""
msg("Parsing repos.txt")
lines = file('/'.join((self.datadir, "repos.txt"))).read().split('\n')
pairs = [line.replace(':',',').split(',') for line in lines if line]
pairs = [tuple([int(pair[0]),
int(pair[3]) if pair[3:4] else 0,
pair[1],
pair[2]
])
for pair in pairs]
for repos, parent, name, creation in pairs:
if parent > 0:
self.forks_of_r[parent].append(repos)
self.parent_of_r[repos] = parent
author, name = name.split('/')
words = [int(x) for x in creation.split('-')]
creation = date(words[0],words[1],words[2]).toordinal()
self.r_info[repos] = (author, name, creation)
self.u_authoring[author].append(repos)
self.r_name[name].append(repos)
for repos_gen1, repos_gen2 in self.parent_of_r.items():
if repos_gen2 in self.parent_of_r:
repos_gen3 = self.parent_of_r[repos_gen2]
self.gparent_of_r[repos_gen1] = repos_gen3
示例6: select_by
def select_by(layer, selection, expression):
try:
utils.msg("Performing selection {} with query {}".format(selection, expression))
arcpy.SelectLayerByAttribute_management(layer, selection, expression)
except Exception as e:
utils.msg("Unable to select by attributes", mtype='error', exception=e)
sys.exit()
示例7: item_model
def item_model(self):
"""construct item similarities
"""
msg("building r_matrix")
repos=set(self.data.watching_r.keys())
for repo in repos:
r_similar[repo] = self.related_items(repo)
r_similar.sort(reverse=True)
示例8: user_model
def user_model(self):
"""construct user similarities
"""
msg("building u_matrix")
users = set(self.data.u_watching.keys())
for user in users:
u_similar[user] = self.related_users(user)
u_similar.sort(reverse=True)
示例9: tag
def tag(force='no', push='no'):
"""
Tag a new release.
Normally, if a Git tag exists matching the current version, and no Git
commits appear after that tag, we abort assuming the user is making a
mistake or forgot to commit their work.
To override this -- i.e. to re-tag and re-upload -- specify ``force=yes``.
We assume you know what you're doing if you use this.
By default we do not push the tag remotely; specify ``push=yes`` to force a
``git push origin <tag>``.
"""
force = force.lower() in ['y', 'yes']
with settings(warn_only=True):
changed = []
# Does the current in-code version exist as a Git tag already?
# If so, this means we haven't updated the in-code version specifier
# yet, and need to do so.
if current_version_is_tagged():
# That is, if any work has been done since. Sanity check!
if not commits_since_last_tag() and not force:
abort("No work done since last tag!")
# Open editor, update version
version_file = "fabric/version.py"
changed.append(update_code(version_file, force))
# If the tag doesn't exist, the user has already updated version info
# and we can just move on.
else:
print("Version has already been updated, no need to edit...")
# Similar process but for the changelog.
changelog = "docs/changelog.rst"
if not current_version_is_changelogged(changelog):
changed.append(update_code(changelog, force))
else:
print("Changelog already updated, no need to edit...")
# Commit any changes
if changed:
with msg("Committing updated version and/or changelog"):
reload(fabric.version)
local("git add %s" % " ".join(changed))
local("git commit -m \"Cut %s\"" % _version('verbose'))
local("git push")
# At this point, we've incremented the in-code version and just need to
# tag it in Git.
f = 'f' if force else ''
with msg("Tagging"):
local("git tag -%sam \"Fabric %s\" %s" % (
f,
_version('normal'),
_version('short')
))
# And push to the central server, if we were told to
if push.lower() in ['y', 'yes']:
with msg("Pushing"):
local("git push origin %s" % _version('short'))
示例10: parse_watching
def parse_watching(self):
"""Parse watching data from file "data.txt"
"""
msg("Parsing data.txt")
lines = file('/'.join((self.datadir,"data.txt"))).read().split('\n')
pairs = [[int(x) for x in line.split(':')] for line in lines if line]
for user, repos in pairs:
self.watching_r[repos].append(user)
self.u_watching[user].append(repos)
示例11: main
def main(bathy=None, out_raster=None):
try:
arcpy.env.rasterStatistics = "STATISTICS"
# Calculate the slope of the bathymetric raster
utils.msg("Calculating the slope...")
out_slope = Slope(bathy, "DEGREE", 1)
out_raster = utils.validate_path(out_raster)
out_slope.save(out_raster)
except Exception as e:
utils.msg(e, mtype='error')
示例12: main
def main(out_workspace, input_bathymetry, broad_bpi_inner_radius,
broad_bpi_outer_radius, fine_bpi_inner_radius, fine_bpi_outer_radius,
classification_dict, output_zones):
# Load required toolboxes
local_path = os.path.dirname(__file__)
btm_toolbox = os.path.abspath(os.path.join(local_path, '..', 'btm.pyt'))
arcpy.ImportToolbox(btm_toolbox)
# local variables:
broad_bpi = os.path.join(out_workspace, "broad_bpi")
fine_bpi = os.path.join(out_workspace, "fine_bpi")
slope_rast = os.path.join(out_workspace, "slope")
broad_std = os.path.join(out_workspace, "broad_std")
fine_std = os.path.join(out_workspace, "fine_std")
utils.workspace_exists(out_workspace)
# set geoprocessing environments
arcpy.env.scratchWorkspace = out_workspace
arcpy.env.workspace = out_workspace
# TODO: currently set to automatically overwrite, expose this as option
arcpy.env.overwriteOutput = True
try:
# Process: Build Broad Scale BPI
utils.msg("Calculating broad-scale BPI...")
bpi.main(input_bathymetry, broad_bpi_inner_radius, \
broad_bpi_outer_radius, broad_bpi, bpi_type='broad')
# Process: Build Fine Scale BPI
utils.msg("Calculating fine-scale BPI...")
bpi.main(input_bathymetry, fine_bpi_inner_radius, \
fine_bpi_outer_radius, fine_bpi, bpi_type='fine')
# Process: Standardize BPIs
utils.msg("Standardizing BPI rasters...")
arcpy.standardizebpi_btm(broad_bpi, "0", "0", broad_std, fine_bpi, \
"0", "0", fine_std)
# Process: Calculate Slope
slope.main(input_bathymetry, slope_rast)
# Process: Zone Classification Builder
outputs_base = arcpy.env.addOutputsToMap
arcpy.env.addOutputsToMap = True
utils.msg("Classifying Zones...")
classify.main(classification_dict, broad_std, fine_std, slope_rast, \
input_bathymetry, output_zones)
arcpy.env.addOutputsToMap = outputs_base
except Exception as e:
# Print error message if an error occurs
utils.msg(e, mtype='error')
示例13: main
def main(input_raster=None, selected_layer=None, interpolate=None,
mode=settings.mode):
utils.msg("Executing ExtractRasterValuesToPoints.")
arcpy.CheckOutExtension("Spatial")
# was bilinear interpolation asked for? maps to
# 'bilinear_intepolate_values'.
if interpolate in ('BILINEAR', True):
bilinear = 'BILINEAR'
else:
bilinear = 'NONE'
# create a value table, prefix all output rasters with 'R_'
rasters = input_raster.split(";")
value_table = []
for raster in rasters:
# default name is just the label, prepend 'R_'
(label, input_ext) = os.path.splitext(os.path.basename(raster))
label = "R_{0}".format(label)
value_table.append([raster, label])
utils.msg("generated value table: %s" % value_table)
utils.msg("Running ExtractMultiValuesToPoints...")
ExtractMultiValuesToPoints(selected_layer, value_table, bilinear)
utils.msg("Values successfully extracted")
示例14: zsc
def zsc(self,os,job,encode):
try:
msg('Connection to OWASP ZSC API api.z3r0d4y.com')
params = urlencode({
'api_name': 'zsc',
'os': os,
'job': job,
'encode': encode})
shellcode = urlopen("http://api.z3r0d4y.com/index.py?%s\n"%(str(params))).read()
if pyversion is 3:
shellcode = str(shellcode,encoding='ascii')
return '\n"'+shellcode.replace('\n','')+'"\n'
except:
error_msg("Error while connecting to api.z3r0d4y.com ...")
return None
示例15: fill_pickle_jar
def fill_pickle_jar(self):
"""Fill the data to pickle
"""
jar = '/'.join((self.datadir,"pickle.jar"))
d = {}
msg("Filling pickle jar '%s'" % jar)
for field in self.fields:
d[field] = getattr(self, field)
d['fields'] = self.fields
jarf = open(jar, 'w')
pickle.dump(d, jarf)
jarf.close()