@@ -2400,6 +2400,53 @@ class ProjectWikiManager(CRUDMixin, RESTManager):
24002400 _list_filters = ('with_content' , )
24012401
24022402
2403+ class ProjectExport (RefreshMixin , RESTObject ):
2404+ _id_attr = None
2405+
2406+ @cli .register_custom_action ('ProjectExport' )
2407+ @exc .on_http_error (exc .GitlabGetError )
2408+ def download (self , streamed = False , action = None , chunk_size = 1024 , ** kwargs ):
2409+ """Download the archive of a project export.
2410+
2411+ Args:
2412+ streamed (bool): If True the data will be processed by chunks of
2413+ `chunk_size` and each chunk is passed to `action` for
2414+ reatment
2415+ action (callable): Callable responsible of dealing with chunk of
2416+ data
2417+ chunk_size (int): Size of each chunk
2418+ **kwargs: Extra options to send to the server (e.g. sudo)
2419+
2420+ Raises:
2421+ GitlabAuthenticationError: If authentication is not correct
2422+ GitlabGetError: If the server failed to perform the request
2423+
2424+ Returns:
2425+ str: The blob content if streamed is False, None otherwise
2426+ """
2427+ path = '/projects/%d/export/download' % self .project_id
2428+ result = self .manager .gitlab .http_get (path , streamed = streamed ,
2429+ ** kwargs )
2430+ return utils .response_content (result , streamed , action , chunk_size )
2431+
2432+
2433+ class ProjectExportManager (GetWithoutIdMixin , CreateMixin , RESTManager ):
2434+ _path = '/projects/%(project_id)s/export'
2435+ _obj_cls = ProjectExport
2436+ _from_parent_attrs = {'project_id' : 'id' }
2437+ _create_attrs = (tuple (), ('description' ,))
2438+
2439+
2440+ class ProjectImport (RefreshMixin , RESTObject ):
2441+ _id_attr = None
2442+
2443+
2444+ class ProjectImportManager (GetWithoutIdMixin , RESTManager ):
2445+ _path = '/projects/%(project_id)s/import'
2446+ _obj_cls = ProjectImport
2447+ _from_parent_attrs = {'project_id' : 'id' }
2448+
2449+
24032450class Project (SaveMixin , ObjectDeleteMixin , RESTObject ):
24042451 _short_print_attr = 'path'
24052452 _managers = (
@@ -2412,10 +2459,12 @@ class Project(SaveMixin, ObjectDeleteMixin, RESTObject):
24122459 ('deployments' , 'ProjectDeploymentManager' ),
24132460 ('environments' , 'ProjectEnvironmentManager' ),
24142461 ('events' , 'ProjectEventManager' ),
2462+ ('exports' , 'ProjectExportManager' ),
24152463 ('files' , 'ProjectFileManager' ),
24162464 ('forks' , 'ProjectForkManager' ),
24172465 ('hooks' , 'ProjectHookManager' ),
24182466 ('keys' , 'ProjectKeyManager' ),
2467+ ('imports' , 'ProjectImportManager' ),
24192468 ('issues' , 'ProjectIssueManager' ),
24202469 ('labels' , 'ProjectLabelManager' ),
24212470 ('members' , 'ProjectMemberManager' ),
@@ -2847,6 +2896,41 @@ class ProjectManager(CRUDMixin, RESTManager):
28472896 'with_issues_enabled' , 'with_merge_requests_enabled' ,
28482897 'custom_attributes' )
28492898
2899+ def import_project (self , file , path , namespace = None , overwrite = False ,
2900+ override_params = None , ** kwargs ):
2901+ """Import a project from an archive file.
2902+
2903+ Args:
2904+ file: Data or file object containing the project
2905+ path (str): Name and path for the new project
2906+ namespace (str): The ID or path of the namespace that the project
2907+ will be imported to
2908+ overwrite (bool): If True overwrite an existing project with the
2909+ same path
2910+ override_params (dict): Set the specific settings for the project
2911+ **kwargs: Extra options to send to the server (e.g. sudo)
2912+
2913+ Raises:
2914+ GitlabAuthenticationError: If authentication is not correct
2915+ GitlabListError: If the server failed to perform the request
2916+
2917+ Returns:
2918+ dict: A representation of the import status.
2919+ """
2920+ files = {
2921+ 'file' : ('file.tar.gz' , file )
2922+ }
2923+ data = {
2924+ 'path' : path ,
2925+ 'overwrite' : overwrite
2926+ }
2927+ if override_params :
2928+ data ['override_params' ] = override_params
2929+ if namespace :
2930+ data ['namespace' ] = namespace
2931+ return self .gitlab .http_post ('/projects/import' , post_data = data ,
2932+ files = files , ** kwargs )
2933+
28502934
28512935class Runner (SaveMixin , ObjectDeleteMixin , RESTObject ):
28522936 pass
0 commit comments