本文整理汇总了Python中core.db.connection.DataHubConnection.export_table方法的典型用法代码示例。如果您正苦于以下问题:Python DataHubConnection.export_table方法的具体用法?Python DataHubConnection.export_table怎么用?Python DataHubConnection.export_table使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core.db.connection.DataHubConnection
的用法示例。
在下文中一共展示了DataHubConnection.export_table方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: export_table
# 需要导入模块: from core.db.connection import DataHubConnection [as 别名]
# 或者: from core.db.connection.DataHubConnection import export_table [as 别名]
def export_table(repo_base, table_name, file_path, file_format="CSV", delimiter=",", header=True):
superuser_con = DataHubConnection(
user=settings.DATABASES["default"]["USER"],
password=settings.DATABASES["default"]["USER"],
repo_base=repo_base,
)
return superuser_con.export_table(
table_name=table_name, file_path=file_path, file_format=file_format, delimiter=delimiter, header=header
)
示例2: export_table
# 需要导入模块: from core.db.connection import DataHubConnection [as 别名]
# 或者: from core.db.connection.DataHubConnection import export_table [as 别名]
def export_table(repo_base, table_name, file_path, file_format='CSV',
delimiter=',', header=True):
superuser_con = DataHubConnection(
user=settings.DATABASES['default']['USER'],
password=settings.DATABASES['default']['USER'],
repo_base=repo_base)
return superuser_con.export_table(
table_name=table_name,
file_path=file_path,
file_format=file_format,
delimiter=delimiter,
header=header)
示例3: export_table
# 需要导入模块: from core.db.connection import DataHubConnection [as 别名]
# 或者: from core.db.connection.DataHubConnection import export_table [as 别名]
def export_table(username, repo_base, repo, table, file_format='CSV',
delimiter=',', header=True):
"""
Export a table to a CSV file in the same repo.
Only superusers can execute the copy command, so this function
passes the username, and verifies user's permissions.
"""
# check for permissions
res = DataHubManager.has_repo_privilege(
username, repo_base, repo, 'CREATE')
if not res:
raise PermissionDenied(
'Access denied. Missing required privileges.')
# make the base_repo and repo's folder, if they don't already exist
DataHubManager.create_user_data_folder(repo_base, repo)
# define the file path for the new table
file_name = clean_file_name(table)
file_path = user_data_path(repo_base, repo, file_name, file_format)
# format the full table name
long_table_name = '%s.%s.%s' % (repo_base, repo, table)
# pass arguments to the connector
superuser_con = DataHubConnection(
user=settings.DATABASES['default']['USER'],
password=settings.DATABASES['default']['USER'],
repo_base=repo_base)
return superuser_con.export_table(
table_name=long_table_name,
file_path=file_path,
file_format=file_format,
delimiter=delimiter,
header=header)
示例4: __init__
# 需要导入模块: from core.db.connection import DataHubConnection [as 别名]
# 或者: from core.db.connection.DataHubConnection import export_table [as 别名]
#.........这里部分代码省略.........
DataHubManager.create_user_data_folder(self.repo_base, repo)
file_name = clean_file_name(data_file.name)
file_path = user_data_path(self.repo_base, repo, file_name)
with open(file_path, 'wb+') as destination:
for chunk in data_file.chunks():
destination.write(chunk)
def delete_file(self, repo, file_name):
"""
Deletes a file from a repo.
Raises PermissionDenied on insufficient privileges.
"""
DataHubManager.has_repo_file_privilege(
self.username, self.repo_base, repo, 'write')
file_path = user_data_path(self.repo_base, repo, file_name)
os.remove(file_path)
def get_file(self, repo, file_name):
"""
Gets the contents of a file in a repo.
Raises PermissionDenied on insufficient privileges.
"""
DataHubManager.has_repo_file_privilege(
self.username, self.repo_base, repo, 'read')
file_path = user_data_path(self.repo_base, repo, file_name)
file = open(file_path).read()
return file
def export_table(self, repo, table, file_name, file_format='CSV',
delimiter=',', header=True):
"""
Exports a table to a file in the same repo.
Defaults to CSV format with header row.
Raises LookupError on invalid repo or table.
Raises ProgrammingError on invalid combinations of file_format,
delimiter, and header.
Raises PermissionDenied on insufficient privileges.
"""
# clean up names:
repo = clean_str(repo, '')
table = clean_str(table, '')
# check for permissions
DataHubManager.has_repo_db_privilege(
self.username, self.repo_base, repo, 'CREATE')
# make the base_repo and repo's folder, if they don't already exist
DataHubManager.create_user_data_folder(self.repo_base, repo)
# define the file path for the new table
file_name = clean_file_name(file_name)
file_path = user_data_path(
self.repo_base, repo, file_name, file_format)
# format the full table name
table_name = '%s.%s' % (repo, table)
# pass arguments to the connector
self.user_con.export_table(