本文整理汇总了Python中utility.Utility类的典型用法代码示例。如果您正苦于以下问题:Python Utility类的具体用法?Python Utility怎么用?Python Utility使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Utility类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _parse_dir
def _parse_dir(self):
dir_name = Utility.get_dir_name(self.current_path)
file_name = Utility.get_base_name(self.current_path)
# get files with extension stored in ext
file_list = []
for ext in self.extension_list:
file_list += glob.glob1(dir_name, ext)
# sort list
file_list = [f for f in file_list]
file_list.sort()
# current file index list
current_index = file_list.index(file_name)
# find the next file path
if current_index + 1 < len(file_list):
self._next_path = \
dir_name + '/' + file_list[current_index + 1]
else:
self._next_path = None
# find the previous file path
if current_index > 0:
self._previous_path = \
dir_name + '/' + file_list[current_index - 1]
else:
self._previous_path = None
return file_list
示例2: simpanItemMutasi
def simpanItemMutasi(reqData):
requtil = Utility(reqData=reqData);
id = requtil.nvlGet('id', 0)
idBrg = requtil.nvlGet('barang_id', 0)
pbl = None
if id == 0:
pbl = initMutasi(reqData)
else:
pbls = models.Mutasi.objects.filter(id__exact=id)
if len(pbls):
pbl = pbls[0]
#prepare barang
brg = None
brgs = models.Barang.objects.filter(id__exact=idBrg)
if len(brgs):
brg = brgs[0]
else:
raise StandardError('Barang ini tidak ditemukan')
ipbl = models.ItemMutasi()
ipbl.barang = brg
ipbl.mutasi = pbl
ipbl.harga = brg.harga
ipbl.jumlah = requtil.nvlGet('barang_qty', 0)
ipbl.save()
return ipbl
示例3: parse_Jobberman
def parse_Jobberman(self, response):
i = CareerItem()
utility = Utility()
i['url'] = response.url
logging.info(response.url)
try:
i['title'] = response.xpath('//div[@class="job-quick-sum"]/h1/text()').extract()[0]
except IndexError:
i['title'] = response.xpath('//div[@class="job-quick-sum"]/h1/text()').extract()
try:
description = response.xpath('//div[@class="job-details-main"]/p[2]/text()').extract()[0]
except IndexError:
description = response.xpath('//div[@class="job-details-main"]/p[2]/text()').extract()
i['description'] = utility.limit_length_of_string(description)#(description[:150] + '...') if len(description) > 150 else description
i['category'] = utility.stringReplace(self.category, '/', ',')
i['location'] = self.location #str(self.location).replace('/', ',')
# try:
# i['location'] = response.xpath('//div[@class="job-details-sidebar"]/p[7]/a/text()').extract()[0]
# except IndexError:
# i['location'] = response.xpath('//div[@class="job-details-sidebar"]/p[7]/a/text()').extract()
# try:
# i['category'] = str(response.xpath('//div[@class="job-details-sidebar"]/p[9]/a/text()').extract()[0]).replace('/', ',')
# except IndexError:
# i['category'] = str(response.xpath('//div[@class="job-details-sidebar"]/p[9]/a/text()').extract()).replace('/', ',')Onye
i['sponsor'] = 'jobberman.com'
#log.msg(i)
yield i
示例4: stop_loop
def stop_loop():
now = time.time()
if now < deadline and (io_loop._callbacks or io_loop._timeouts):
io_loop.add_timeout(now + 1, stop_loop)
else:
io_loop.stop()
Utility.print_msg ('\033[93m'+ 'shutdown' + '\033[0m', True, 'done')
示例5: addTask
def addTask(projectId, taskId, taskType):
tasks = Settings.getTasks(projectId, taskType)
if taskId in tasks:
return
tasks.append( taskId )
path = "%s/%s.%s.json"%(PROJECTS_PATH, projectId, taskType)
Utility.saveJson( path, tasks )
示例6: main_handler
def main_handler():
response.content_type = 'application/json'
return {
'status': 'OK',
'detail': 'Nothing to show on this page, try http://%s:%s/login'
% (Utility.ins().hostname(), Utility.ins().port())
}
示例7: load
def load(self, filename, initial_page=0):
image_extensions = ['.bmp', '.jpg', '.jpeg', '.gif', '.png', '.pbm',
'.pgm', '.ppm', '.tiff', '.xbm', '.xpm', '.webp']
loader = LoaderFactory.create_loader(
Utility.get_file_extension(filename), set(image_extensions))
loader.progress.connect(self.load_progressbar_value)
try:
loader.load(filename)
except NoDataFindException as excp:
# Caso nao exista nenhuma imagem, carregamos a imagem indicando
# erro
from page import Page
print excp.message
q_file = QtCore.QFile(":/icons/notCover.png")
q_file.open(QtCore.QIODevice.ReadOnly)
loader.data.append(Page(q_file.readAll(), 'exit_red_1.png', 0))
self.comic = Comic(Utility.get_base_name(filename),
Utility.get_dir_name(filename), initial_page)
self.comic.pages = loader.data
self.current_directory = Utility.get_dir_name(filename)
self.path_file_filter.parse(filename)
示例8: index
def index(request):
util = Utility(post=request.POST, get=request.GET)
c = util.nvlGet('c');
if c is not None:
if 'formtutorial' == c:
return render_to_response('inventory/form_tutorial.html')
if 'local' == c:
t = loader.get_template('portal_ivtamd.html')
djProd = '''http://ajax.googleapis.com/ajax/libs/dojo/1.7.2/'''
djProdExt = '''.js'''
djDev = '''/static/dojolib/'''
djDevExt = '''.js'''
d = {"dj": djDev, 'djExt': djProdExt}
return HttpResponse(t.render(Context(d)))
if 'home' == c:
return render_to_response('inventory/web.html')
if 'pabean' == c:
return render_to_response('inventory/dokumen_css.html')
else:
#t = loader.get_template('portal_ivt.html')
t = loader.get_template('portal_ivtamd.html')
# t = loader.get_template('portal_inventory.html') // the old system
#djProd = '''http://ajax.googleapis.com/ajax/libs/dojo/1.6/'''
djProd = '''http://ajax.googleapis.com/ajax/libs/dojo/1.7.2/'''
djProdExt = '''.js'''
djDev = '''/static/dojolib/'''
djDevExt = '''.js'''
d = {"dj": djProd, 'djExt': djProdExt}
return HttpResponse(t.render(Context(d)))
示例9: build_alert
def build_alert(self, alert_id, alert_message, location=None):
"""Build the actual alert and returns it, formatted.
DEPRECATION NOTICE: The 'alert_id' field has been introduced for
better readability. It's currently set to be the same as 'id'.
At some point in the future, the 'id' field will be removed.
Args:
alert_id (int): The ID of the alert you want to build
alert_message (str): The message to be embedded in the alert.
Returns:
tuple: Position 0 contains the string 'sitch_alert'. Position 1
contains the alert and metadata.
"""
if location is None:
print("AlertManager: No geo for alarm: %s" % str(alert_message))
location = {"type": "Point", "coordinates": [0, 0]}
elif Utility.validate_geojson(location) is False:
print("AlertManager: Invalid geojson %s for: %s" % (location,
alert_message))
location = {"type": "Point", "coordinates": [0, 0]}
lat = location["coordinates"][1]
lon = location["coordinates"][0]
gmaps_url = Utility.create_gmaps_link(lat, lon)
message = Utility.generate_base_event()
message["alert_id"] = alert_id
message["id"] = alert_id
message["alert_type"] = self.get_alert_type(alert_id)
message["event_type"] = "sitch_alert"
message["details"] = ("%s %s" % (alert_message, gmaps_url))
message["location"] = location
retval = ("sitch_alert", message)
return retval
示例10: addPredictionTask
def addPredictionTask(projectId, taskId):
print 'addPredictionTask....'
path = "%s/%s.%s.json"%(PROJECTS_PATH, projectId, PREDICT_TASK_TYPE)
Utility.lock(path)
Settings.reconcilePredictionTasks( projectId )
Settings.addTask(projectId, taskId, PREDICT_TASK_TYPE)
Utility.unlock(path)
示例11: removeTask
def removeTask(projectId, taskId, taskType):
tasks = Settings.getTasks(projectId, taskType)
if taskId in tasks:
tasks.remove( taskId)
path = "%s/%s.%s.json"%(PROJECTS_PATH, projectId, taskType)
if not Utility.isLocked( path ):
Utility.saveJson( path, tasks )
示例12: close_file
def close_file(self, left_hemi_file, right_hemi_file, left_curvature_output_file, right_curvature_output_file):
'''
'''
m = numpy.ctypeslib.as_array(self.__matrix.get_obj())
m = m.reshape(self.__shape)
#here
lh_vertices, lh_faces = nibabel.freesurfer.read_geometry( left_hemi_file )
rh_vertices, rh_faces = nibabel.freesurfer.read_geometry( right_hemi_file )
sum_vector = numpy.sum( m, axis=0 )
import sys, os
sys.path.append(os.path.join( os.path.dirname( __file__ ),'../'))
from utility import Utility
# write curvature files
Utility.write_freesurfer_curvature( left_curvature_output_file, sum_vector[0:len( lh_vertices )] )
Utility.write_freesurfer_curvature( right_curvature_output_file, sum_vector[len( lh_vertices ):] ) # here we start with the offset
# end here
print 'crv written!!! FTW!'
numpy.save( self.__matrix_file, m)
print 'stored matrix'
示例13: lookupBdi
def lookupBdi(katakunci, inventory_id, id, max):
requtil = Utility()
if max is None:
max = 40;
pasiens = []
if katakunci is not None and '' != katakunci and id is None:
print 'katakunci'
print max
pasiens = models.BarangDiInventory.objects.filter(
Q(barang__nama__icontains=katakunci) | Q(barang__merk__icontains=katakunci) |
Q(barang__kode__icontains=katakunci, inventori__id__exact=inventory_id))[
:max]
elif id is not None:
print 'id'
pasiens = models.BarangDiInventory.objects.filter(barang__id__exact=id)
print 'query from id'
#lookup specific id, to set id value
else:
print 'other'
print id
print katakunci
pasiens = models.BarangDiInventory.objects.filter(inventory__id__exact=inventory_id)[:max]
jpasiens = [];
for bdi in pasiens:
jpasien = requtil.modelToDicts([bdi.barang])
jpasiens.append(jpasien)
return jpasiens;
示例14: lookupBarang
def lookupBarang(katakunci, id, max):
requtil = Utility()
if max is None:
max = 40;
pasiens = []
if katakunci is not None and '' != katakunci and id is None:
print 'katakunci'
print max
pasiens = models.Barang.objects.filter(
Q(nama__icontains=katakunci) | Q(merk__icontains=katakunci) | Q(kode__icontains=katakunci))[
:max]
elif id is not None:
print 'id'
pasiens = models.Barang.objects.filter(id__exact=id)
print 'query from id'
#lookup specific id, to set id value
else:
print 'other'
print id
print katakunci
pasiens = models.Barang.objects.all()[:max]
jpasiens = [];
for pasien in pasiens:
jpasien = requtil.modelToDicts([pasien])
jpasiens.append(jpasien)
return jpasiens;
示例15: getSupplierSider
def getSupplierSider(reqData):
requtil = Utility(reqData=reqData)
pas = models.Supplier.objects.filter(id__exact=requtil.nvlGet('id'))
if pas[0] is not None:
id = pas[0].id
jpas = requtil.modelToDicts([pas[0]])
html = render_to_string('inventory/form_supplier_sider.html', jpas)
return html