本文整理匯總了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(