Commit 0ba4251e authored by Gao, Shang's avatar Gao, Shang
Browse files

minor formatting changes to conform to PEP8

parent 05efd662
Loading
Loading
Loading
Loading

crossbow/__init__.pyc

0 → 100644
+134 B

File added.

No diff preview for this file type.

+31 −24
Original line number Diff line number Diff line
@@ -51,8 +51,9 @@ class crossbowBase(object):

        return metadata

    def create_package(self,package,owner_org,title=None,description=None,author=None,
        author_email=None,maintainer=None,maintainer_email=None,version=None,tags=[]):
    def create_package(self,package,owner_org,title=None,description=None,
                       author=None,author_email=None,maintainer=None,
                       maintainer_email=None,version=None,tags=[]):
        '''
        creates a new package (dataset)

@@ -80,9 +81,11 @@ class crossbowBase(object):
        '''
        if " " in package or any(x.isupper() for x in package):
            raise Exception('package must be lowercase and without spaces')
        self.ckan.action.package_create(name=package,owner_org=owner_org,title=title,
            author=author,author_email=author_email,maintainer=maintainer,
            maintainer_email=maintainer_email,notes=description,version=version,tags=tags)
        self.ckan.action.package_create(
                name=package,owner_org=owner_org,title=title,author=author,
                author_email=author_email,maintainer=maintainer,
                maintainer_email=maintainer_email,notes=description,
                version=version,tags=tags)

    def edit_package(self,package,*args,**kwargs):
        '''
@@ -94,8 +97,8 @@ class crossbowBase(object):
          see create_package() function for additional parameters
        '''
        #add args to kwargs dic
        keywords = ['owner_org','title','notes','author','author_email','maintainer',\
            'maintainer_email','version','tags']
        keywords = ['owner_org','title','notes','author','author_email',\
                    'maintainer','maintainer_email','version','tags']
        for idx,arg in enumerate(args):
            kwargs[keywords[idx]] = arg
        
@@ -214,7 +217,8 @@ class crossbowMount(crossbowBase):
        prints and returns details for a specific package

      - create_package(package,owner_org,title=None,description=None,author=None,
            author_email=None,maintainer=None,maintainer_email=None,version=None,tags=[])
                       author_email=None,maintainer=None,maintainer_email=None,
                       version=None,tags=[])
        creates a new package (dataset)

      - edit_package(package,*args,**kwargs)
@@ -311,13 +315,15 @@ class crossbowMount(crossbowBase):

        #copy file to crossbow NFS
        prog = ProgressBar(widgets=[Percentage(), Bar()], maxval=100).start()
        self._copy_with_progress(resource_path, nfs_path, 
        self._copy_with_progress(
                resource_path, nfs_path, 
                lambda pos, total: prog.update(100*pos/float(total)))
        print ''

        #add file to CKAN
        self.ckan.action.resource_create(package_id=package,url=url,name=resource,
            description=description,format=format,size=size)
        self.ckan.action.resource_create(
                package_id=package,url=url,name=resource,description=description,
                format=format,size=size)

    def edit_resource(self,package,resource,new_name=None,new_description=None):
        '''
@@ -383,7 +389,8 @@ class crossbowMount(crossbowBase):
        
        #copy file to local drive
        prog = ProgressBar(widgets=[Percentage(), Bar()], maxval=100).start()
        self._copy_with_progress(resource_path, dest_path, 
        self._copy_with_progress(
                resource_path, dest_path, 
                lambda pos, total: prog.update(100*pos/float(total)))
        print ''

crossbow/crossbow.pyc

0 → 100644
+16.5 KiB

File added.

No diff preview for this file type.

+23 −19
Original line number Diff line number Diff line
@@ -5,27 +5,30 @@ import os
def setup_module():
    #create cbowMount class for testing
    global cbowMount
    cbowMount = crossbowMount(NFS_path="/data",
    cbowMount = crossbowMount(
            NFS_path="/data",
            api_key="eaabd7d9-3cb4-4014-85fe-73736e658472")
    
    #create direct ckan connection for environment setup
    global ckan 
    ckan = RemoteCKAN("http://128.219.185.145:5000",
    ckan = RemoteCKAN(
            "http://128.219.185.145:5000",
            apikey="eaabd7d9-3cb4-4014-85fe-73736e658472",user_agent="nosetests")

    #create package for testing
    if "nosetests1" in ckan.action.package_list():
        ckan.action.dataset_purge(id="nosetests1")
    ckan.action.package_create(name="nosetests1",owner_org="test",
        title="nosetests1",author="nosetests1",notes="nosetests1")
    ckan.action.package_create(
            name="nosetests1",owner_org="test",title="nosetests1",
            author="nosetests1",notes="nosetests1")
    
    #create resource for testing
    ckan.action.resource_create(package_id="nosetests1",
        url="file://CROSSBOW_NFS/nosetests1/testfile.csv",name="myresource1",
        description="myresource1")
    ckan.action.resource_create(package_id="nosetests1",
        url="file://CROSSBOW_NFS/nosetests1/testfile.dcd",name="myresource2",
        description="myresource2")
    ckan.action.resource_create(
            package_id="nosetests1",url="file://CROSSBOW_NFS/nosetests1/testfile.csv",
            name="myresource1",description="myresource1")
    ckan.action.resource_create(
            package_id="nosetests1",url="file://CROSSBOW_NFS/nosetests1/testfile.dcd",
            name="myresource2",description="myresource2")

    #create temporary files for testing
    tempfile = open('/data/nosetests1/testfile.csv', 'w+')
@@ -42,8 +45,9 @@ def test_get_package_details():
    assert cbowMount.get_package_details("nosetests1")['title'] == "nosetests1"

def test_create_package():
    cbowMount.create_package("nosetests2",owner_org="test",title="nosetests2",
        description="nosetests2",author="nosetests2")
    cbowMount.create_package(
            "nosetests2",owner_org="test",title="nosetests2",description="nosetests2",
            author="nosetests2")
    assert "nosetests2" in ckan.action.package_list()

def test_edit_package():
@@ -68,8 +72,8 @@ def test_get_resource_details():
           == "file://CROSSBOW_NFS/nosetests1/testfile.csv"

def test_add_resource():
    cbowMount.add_resource("nosetests1","myresource3","./testfile2.dcd",
        description="myresource3")
    cbowMount.add_resource(
            "nosetests1","myresource3","./testfile2.dcd",description="myresource3")
    metadata = ckan.action.package_show(id="nosetests1")
    resources = [resource['name'] for resource in metadata['resources']]
    resource_urls = [resource['url'] for resource in metadata['resources']]
+6.06 KiB

File added.

No diff preview for this file type.