@@ -2400,6 +2400,53 @@ class ProjectWikiManager(CRUDMixin, RESTManager):
2400
2400
_list_filters = ('with_content' , )
2401
2401
2402
2402
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
+
2403
2450
class Project (SaveMixin , ObjectDeleteMixin , RESTObject ):
2404
2451
_short_print_attr = 'path'
2405
2452
_managers = (
@@ -2412,10 +2459,12 @@ class Project(SaveMixin, ObjectDeleteMixin, RESTObject):
2412
2459
('deployments' , 'ProjectDeploymentManager' ),
2413
2460
('environments' , 'ProjectEnvironmentManager' ),
2414
2461
('events' , 'ProjectEventManager' ),
2462
+ ('exports' , 'ProjectExportManager' ),
2415
2463
('files' , 'ProjectFileManager' ),
2416
2464
('forks' , 'ProjectForkManager' ),
2417
2465
('hooks' , 'ProjectHookManager' ),
2418
2466
('keys' , 'ProjectKeyManager' ),
2467
+ ('imports' , 'ProjectImportManager' ),
2419
2468
('issues' , 'ProjectIssueManager' ),
2420
2469
('labels' , 'ProjectLabelManager' ),
2421
2470
('members' , 'ProjectMemberManager' ),
@@ -2847,6 +2896,41 @@ class ProjectManager(CRUDMixin, RESTManager):
2847
2896
'with_issues_enabled' , 'with_merge_requests_enabled' ,
2848
2897
'custom_attributes' )
2849
2898
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
+
2850
2934
2851
2935
class Runner (SaveMixin , ObjectDeleteMixin , RESTObject ):
2852
2936
pass
0 commit comments