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


Python DataHubConnection.import_file方法代码示例

本文整理汇总了Python中core.db.connection.DataHubConnection.import_file方法的典型用法代码示例。如果您正苦于以下问题:Python DataHubConnection.import_file方法的具体用法?Python DataHubConnection.import_file怎么用?Python DataHubConnection.import_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在core.db.connection.DataHubConnection的用法示例。


在下文中一共展示了DataHubConnection.import_file方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: import_file

# 需要导入模块: from core.db.connection import DataHubConnection [as 别名]
# 或者: from core.db.connection.DataHubConnection import import_file [as 别名]
 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,代码行数:16,代码来源:manager.py

示例2: import_file

# 需要导入模块: from core.db.connection import DataHubConnection [as 别名]
# 或者: from core.db.connection.DataHubConnection import import_file [as 别名]
    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,代码行数:52,代码来源:manager.py

示例3: import_file

# 需要导入模块: from core.db.connection import DataHubConnection [as 别名]
# 或者: from core.db.connection.DataHubConnection import import_file [as 别名]
 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:hongsenliu,项目名称:datahub,代码行数:26,代码来源:manager.py


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