本文整理汇总了Python中core.db.connection.DataHubConnection类的典型用法代码示例。如果您正苦于以下问题:Python DataHubConnection类的具体用法?Python DataHubConnection怎么用?Python DataHubConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DataHubConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: list_collaborators
def list_collaborators(repo_base, repo):
superuser_con = DataHubConnection(
user=settings.DATABASES["default"]["USER"],
password=settings.DATABASES["default"]["USER"],
repo_base=repo_base,
)
return superuser_con.list_collaborators(repo_base=repo_base, repo=repo)
示例2: has_column_privilege
def has_column_privilege(login, repo_base, table, column, privilege):
superuser_con = DataHubConnection(
user=settings.DATABASES["default"]["USER"],
password=settings.DATABASES["default"]["USER"],
repo_base=repo_base,
)
return superuser_con.has_column_privilege(login=login, table=table, column=column, privilege=privilege)
示例3: has_table_privilege
def has_table_privilege(login, repo_base, table, privilege):
superuser_con = DataHubConnection(
user=settings.DATABASES['default']['USER'],
password=settings.DATABASES['default']['USER'],
repo_base=repo_base)
return superuser_con.has_table_privilege(
login=login, table=table, privilege=privilege)
示例4: remove_app
def remove_app(app_id):
app = App.objects.get(app_id=app_id)
app.delete()
superuser_con = DataHubConnection(
user=settings.DATABASES['default']['USER'],
password=settings.DATABASES['default']['USER'])
superuser_con.remove_user(username=app_id)
示例5: export_query
def export_query(repo_base, query, 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_query(
query=query, file_path=file_path, file_format=file_format, delimiter=delimiter, header=header
)
示例6: list_all_databases
def list_all_databases():
'''
lists all user databases. Does not list some,
like postgres, templates0, templates1, or datahub
'''
superuser_con = DataHubConnection(
user=settings.DATABASES['default']['USER'],
password=settings.DATABASES['default']['USER'])
return superuser_con.list_all_databases()
示例7: create_user
def create_user(username, password, create_db=True):
"""Creates a DB role, database, and data folder for a new user."""
superuser_con = DataHubConnection(
user=settings.DATABASES['default']['USER'],
password=settings.DATABASES['default']['USER'])
res = superuser_con.create_user(
username=username, password=password, create_db=create_db)
DataHubManager.create_user_data_folder(username)
return res
示例8: remove_database
def remove_database(repo_name, revoke_collaborators=True):
collaborators = Collaborator.objects.filter(repo_name=repo_name)
for collaborator in collaborators:
collaborator.delete()
DataHubManager.delete_user_data_folder(repo_name)
superuser_con = DataHubConnection(
user=settings.DATABASES['default']['USER'],
password=settings.DATABASES['default']['USER'])
return superuser_con.remove_database(repo_name, revoke_collaborators)
示例9: export_query
def export_query(repo_base, query, 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_query(
query=query,
file_path=file_path,
file_format=file_format,
delimiter=delimiter,
header=header)
示例10: import_file
def import_file(repo_base, table_name, file_path, file_format='CSV',
delimiter=',', header=True, encoding='ISO-8859-1', quote_character='"'):
superuser_con = DataHubConnection(
user=settings.DATABASES['default']['USER'],
password=settings.DATABASES['default']['USER'],
repo_base=repo_base)
return superuser_con.import_file(
table_name=table_name,
file_path=file_path,
file_format=file_format,
delimiter=delimiter,
header=header,
encoding=encoding,
quote_character=quote_character)
示例11: import_file
def import_file(username, repo_base, repo, table, file_name,
file_format='CSV', delimiter=',', header=True,
encoding='ISO-8859-1', quote_character='"'):
# check for permissions
delimiter = delimiter.decode('string_escape')
res = DataHubManager.has_repo_privilege(
username, repo_base, repo, 'CREATE')
if not res:
raise PermissionDenied(
'Access denied. Missing required privileges.')
# prepare some variables
file_path = user_data_path(repo_base, repo, file_name)
table_name, _ = os.path.splitext(file_name)
table_name = clean_str(table_name, 'table')
dh_table_name = '%s.%s.%s' % (repo_base, repo, table_name)
# open the file
f = codecs.open(file_path, 'r', 'ISO-8859-1')
data = csv.reader(f, delimiter=delimiter)
# create a table for the data
cells = data.next()
columns = [clean_str(str(i), 'col') for i in range(0, len(cells))]
if header:
columns = map(lambda x: clean_str(x, 'col'), cells)
columns = rename_duplicates(columns)
query = 'CREATE TABLE %s (%s text' % (dh_table_name, columns[0])
for column in columns[1:len(columns)]:
query += ', %s %s' % (column, 'text')
query += ')'
manager = DataHubManager(user=username, repo_base=repo_base)
manager.execute_sql(query=query)
# populate the newly created table with data from the csv
superuser_con = DataHubConnection(
user=settings.DATABASES['default']['USER'],
password=settings.DATABASES['default']['USER'],
repo_base=repo_base)
return superuser_con.import_file(
table_name=dh_table_name,
file_path=file_path,
file_format=file_format,
delimiter=delimiter,
header=header,
encoding=encoding,
quote_character=quote_character)
示例12: _superuser_connection
class _superuser_connection():
superuser_con = None
def __init__(self, repo_base=None):
self.repo_base = repo_base
def __enter__(self):
self.superuser_con = DataHubConnection(
user=settings.DATABASES['default']['USER'],
password=settings.DATABASES['default']['PASSWORD'],
repo_base=self.repo_base)
return self.superuser_con
def __exit__(self, type, value, traceback):
self.superuser_con.close_connection()
示例13: __init__
def __init__(self, user=settings.ANONYMOUS_ROLE, repo_base=None,
is_app=False):
# blank users are set to anonymous role
if user == '':
user = settings.ANONYMOUS_ROLE
username = None
password = None
if is_app:
app = App.objects.get(app_id=user)
username = app.app_id
password = hashlib.sha1(app.app_token).hexdigest()
else:
user = User.objects.get(username=user)
username = user.username
password = user.password
if not repo_base:
repo_base = username
self.username = username
self.repo_base = repo_base
self.user_con = DataHubConnection(
user=username,
repo_base=repo_base,
password=password)
示例14: remove_user
def remove_user(username, remove_db=True):
# get the user associated with the username, and delete their apps
try:
user = User.objects.get(username=username)
apps = App.objects.filter(user=user)
for app in apps:
app_id = app.app_id
DataHubManager.remove_app(app_id=app_id)
Collaborator.objects.filter(user=user).delete()
except:
user = None
# do the same thing for legacy users
try:
legacy_user = DataHubLegacyUser.objects.get(username=username)
apps = App.objects.filter(legacy_user=legacy_user)
for app in apps:
app_id = app.app_id
DataHubManager.remove_app(app_id=app_id)
except:
legacy_user = None
# delete the users
if user:
user.delete()
if legacy_user:
legacy_user.delete()
# delete the user's db
if remove_db:
DataHubManager.remove_database(username)
# make a connection, and delete the user's database account
superuser_con = DataHubConnection(
user=settings.DATABASES['default']['USER'],
password=settings.DATABASES['default']['USER'])
try:
return superuser_con.remove_user(username=username)
except:
all_db_list = DataHubManager.list_all_databases()
for db in all_db_list:
DataHubManager.drop_owned_by(username=username, repo_base=db)
return superuser_con.remove_user(username=username)
示例15: __init__
def __init__(self, user, repo_base=None, is_app=False):
username = None
password = None
if is_app:
app = App.objects.get(app_id=user)
username = app.app_id
password = hashlib.sha1(app.app_token).hexdigest()
else:
user = User.objects.get(username=user)
username = user.username
password = user.password
self.user_con = DataHubConnection(user=username, repo_base=repo_base, password=password)