当前位置: 首页>>代码示例>>Python>>正文


Python connection.DataHubConnection类代码示例

本文整理汇总了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)
开发者ID:hongsenliu,项目名称:datahub,代码行数:7,代码来源:manager.py

示例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)
开发者ID:hongsenliu,项目名称:datahub,代码行数:7,代码来源:manager.py

示例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)
开发者ID:digideskio,项目名称:mit-datahub,代码行数:7,代码来源:manager.py

示例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)
开发者ID:digideskio,项目名称:mit-datahub,代码行数:8,代码来源:manager.py

示例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
     )
开发者ID:hongsenliu,项目名称:datahub,代码行数:9,代码来源:manager.py

示例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()
开发者ID:digideskio,项目名称:mit-datahub,代码行数:9,代码来源:manager.py

示例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
开发者ID:digideskio,项目名称:mit-datahub,代码行数:9,代码来源:manager.py

示例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)
开发者ID:digideskio,项目名称:mit-datahub,代码行数:10,代码来源:manager.py

示例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)
开发者ID:digideskio,项目名称:mit-datahub,代码行数:12,代码来源:manager.py

示例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)
开发者ID:alessandroleite,项目名称:datahub,代码行数:14,代码来源:manager.py

示例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)
开发者ID:digideskio,项目名称:mit-datahub,代码行数:50,代码来源:manager.py

示例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()
开发者ID:datahuborg,项目名称:datahub,代码行数:15,代码来源:manager.py

示例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)
开发者ID:datahuborg,项目名称:datahub,代码行数:29,代码来源:manager.py

示例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)
开发者ID:digideskio,项目名称:mit-datahub,代码行数:46,代码来源:manager.py

示例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)
开发者ID:hongsenliu,项目名称:datahub,代码行数:14,代码来源:manager.py


注:本文中的core.db.connection.DataHubConnection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。