本文整理汇总了Python中trac.mimeview.Context.cursor方法的典型用法代码示例。如果您正苦于以下问题:Python Context.cursor方法的具体用法?Python Context.cursor怎么用?Python Context.cursor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trac.mimeview.Context
的用法示例。
在下文中一共展示了Context.cursor方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _do_remove
# 需要导入模块: from trac.mimeview import Context [as 别名]
# 或者: from trac.mimeview.Context import cursor [as 别名]
def _do_remove(self, identifier):
# Get downloads API component.
api = self.env[DownloadsApi]
# Create context.
context = Context('downloads-consoleadmin')
db = self.env.get_db_cnx()
context.cursor = db.cursor()
context.req = FakeRequest(self.env, self.consoleadmin_user)
# Get download by ID or filename.
try:
download_id = int(identifier)
download = api.get_download(context, download_id)
except ValueError:
download = api.get_download_by_file(context, identifier)
# Check if download exists.
if not download:
raise AdminCommandError(_('Invalid download identifier: %(value)s',
value = identifier))
# Delete download by ID.
api.delete_download(context, download_id)
# Commit changes in DB.
db.commit()
示例2: _do_add
# 需要导入模块: from trac.mimeview import Context [as 别名]
# 或者: from trac.mimeview.Context import cursor [as 别名]
def _do_add(self, filename, *arguments):
# Get downloads API component.
api = self.env[DownloadsApi]
# Create context.
context = Context('downloads-consoleadmin')
db = self.env.get_db_cnx()
context.cursor = db.cursor()
context.req = FakeRequest(self.env, self.consoleadmin_user)
# Convert relative path to absolute.
if not os.path.isabs(filename):
filename = os.path.join(self.path, filename)
# Open file object.
file, filename, file_size = self._get_file(filename)
# Create download dictionary from arbitrary attributes.
download = {'file' : filename,
'size' : file_size,
'time' : to_timestamp(datetime.now(utc)),
'count' : 0}
# Read optional attributes from arguments.
for argument in arguments:
# Check correct format.
argument = argument.split("=")
if len(argument) != 2:
AdminCommandError(_('Invalid format of download attribute:'
' %(value)s', value = argument))
name, value = argument
# Check known arguments.
if not name in ('description', 'author', 'tags', 'component', 'version',
'architecture', 'platform', 'type'):
raise AdminCommandError(_('Invalid download attribute:'
' %(value)s', value = name))
# Transform architecture, platform and type name to ID.
if name == 'architecture':
value = api.get_architecture_by_name(context, value)['id']
elif name == 'platform':
value = api.get_platform_by_name(context, value)['id']
elif name == 'type':
value = api.get_type_by_name(context, value)['id']
# Add attribute to download.
download[name] = value
self.log.debug(download)
# Upload file to DB and file storage.
api._add_download(context, download, file)
# Close input file and commit changes in DB.
file.close()
db.commit()
示例3: _resolve_ids
# 需要导入模块: from trac.mimeview import Context [as 别名]
# 或者: from trac.mimeview.Context import cursor [as 别名]
def _resolve_ids(self, download):
# Create context.
context = Context('downloads-core')
db = self.env.get_db_cnx()
context.cursor = db.cursor()
# Resolve platform and type names.
api = self.env[DownloadsApi]
platform = api.get_platform(context, download['platform'])
type = api.get_type(context, download['type'])
download['platform'] = platform['name']
download['type'] = type['name']
示例4: get_resource_description
# 需要导入模块: from trac.mimeview import Context [as 别名]
# 或者: from trac.mimeview.Context import cursor [as 别名]
def get_resource_description(self, resource, format="default", context=None, **kwargs):
# Create context.
context = Context("downloads-core")
db = self.env.get_db_cnx()
context.cursor = db.cursor()
# Get download from ID.
api = self.env[DownloadsApi]
download = api.get_download(context, safe_int(resource.id))
if format == "compact":
return download["file"]
elif format == "summary":
return "(%s) %s" % (pretty_size(download["size"]), download["description"])
return download["file"]
示例5: _do_list
# 需要导入模块: from trac.mimeview import Context [as 别名]
# 或者: from trac.mimeview.Context import cursor [as 别名]
def _do_list(self):
# Get downloads API component.
api = self.env[DownloadsApi]
# Create context.
context = Context('downloads-consoleadmin')
db = self.env.get_db_cnx()
context.cursor = db.cursor()
# Print uploded download
downloads = api.get_downloads(context)
print_table([(download['id'], download['file'], pretty_size(
download['size']), format_datetime(download['time']), download['component'], download['version'],
download['platform']['name'], download['type']['name']) for download in downloads], ['ID',
'Filename', 'Size', 'Uploaded', 'Component', 'Version', 'Platform', 'Type'])
示例6: get_resource_description
# 需要导入模块: from trac.mimeview import Context [as 别名]
# 或者: from trac.mimeview.Context import cursor [as 别名]
def get_resource_description(self, resource, format = 'default',
context = None, **kwargs):
# Create context.
context = Context('downloads-core')
db = self.env.get_db_cnx()
context.cursor = db.cursor()
# Get download from ID.
api = self.env[DownloadsApi]
download = api.get_download(context, resource.id)
if format == 'compact':
return download['file']
elif format == 'summary':
return '(%s) %s' % (pretty_size(download['size']),
download['description'])
return download['file']