From cc29db4551a417864101c11193b9d189356ef92f Mon Sep 17 00:00:00 2001 From: Marcus Huewe Date: Sat, 9 Oct 2010 16:26:55 +0200 Subject: [PATCH] - get rid of osc.core.init_project_dir - moved cleaned up code to the Project class' "init_project" static method --- osc/commandline.py | 6 +++--- osc/core.py | 41 +++++++++++++++++++++-------------------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/osc/commandline.py b/osc/commandline.py index 9e82fe0b..792d1014 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -189,7 +189,7 @@ class Osc(cmdln.Cmdln): apiurl = self.get_api_url() if not package: - init_project_dir(apiurl, os.curdir, project) + Project.init_project(apiurl, os.curdir, project, conf.config['do_package_tracking']) print 'Initializing %s (Project: %s)' % (os.curdir, project) else: Package.init_package(apiurl, project, package, os.curdir) @@ -2233,7 +2233,7 @@ Please submit there instead, or use --nodevelproject to force direct submission. print "Project " + r + " created." if opts.checkout: - init_project_dir(apiurl, r, r) + Project.init_project(apiurl, r, r, conf.config['do_package_tracking']) print statfrmt('A', r) # all packages @@ -2769,7 +2769,7 @@ Please submit there instead, or use --nodevelproject to force direct submission. # check if the project does exist (show_project_meta will throw an exception) show_project_meta(apiurl, project) - init_project_dir(apiurl, prj_dir, project) + Project.init_project(apiurl, prj_dir, project, conf.config['do_package_tracking']) print statfrmt('A', prj_dir) # all packages diff --git a/osc/core.py b/osc/core.py index 98fc30d1..037f679c 100644 --- a/osc/core.py +++ b/osc/core.py @@ -784,6 +784,24 @@ class Project: r.append('*****************************************************') return '\n'.join(r) + @staticmethod + def init_project(apiurl, dir, project, package_tracking=True): + global store + + if not os.path.exists(dir): + # use makedirs (checkout_no_colon config option might be enabled) + os.makedirs(dir) + elif not os.path.isdir(dir): + raise oscerr.OscIOError(None, 'error: \'%s\' is no directory' % dir) + if os.path.exists(os.path.join(dir, store)): + raise oscerr.OscIOError(None, 'error: \'%s\' is already an initialized osc working copy' % dir) + else: + os.mkdir(os.path.join(dir, store)) + + store_write_project(dir, project) + store_write_apiurl(dir, apiurl) + if package_tracking: + store_write_initial_packages(dir, project, []) class Package: @@ -2598,23 +2616,6 @@ def http_PUT(*args, **kwargs): return http_request('PUT', *args, **kwargs) def http_DELETE(*args, **kwargs): return http_request('DELETE', *args, **kwargs) -def init_project_dir(apiurl, dir, project): - global store - - if not os.path.exists(dir): - if conf.config['checkout_no_colon']: - os.makedirs(dir) # helpful with checkout_no_colon - else: - os.mkdir(dir) - if not os.path.exists(os.path.join(dir, store)): - os.mkdir(os.path.join(dir, store)) - - # print 'project=',project,' dir=',dir - store_write_project(dir, project) - store_write_apiurl(dir, apiurl) - if conf.config['do_package_tracking']: - store_write_initial_packages(dir, project, []) - def check_store_version(dir): global store @@ -3625,7 +3626,7 @@ def request_diff(apiurl, reqid): return f.read() -def make_dir(apiurl, project, package, pathname=None, prj_dir=None): +def make_dir(apiurl, project, package, pathname=None, prj_dir=None, package_tracking=True): """ creates the plain directory structure for a package dir. The 'apiurl' parameter is needed for the project dir initialization. @@ -3652,7 +3653,7 @@ def make_dir(apiurl, project, package, pathname=None, prj_dir=None): # this directory could exist as a parent direory for one of our earlier # checked out sub-projects. in this case, we still need to initialize it. print statfrmt('A', prj_dir) - init_project_dir(apiurl, prj_dir, project) + Project.init_project(apiurl, prj_dir, project, package_tracking) if is_project_dir(os.path.join(prj_dir, package)): # the thing exists, but is a project directory and not a package directory @@ -3706,7 +3707,7 @@ def checkout_package(apiurl, project, package, isfrozen = True if x: revision = x - directory = make_dir(apiurl, project, package, pathname, prj_dir) + directory = make_dir(apiurl, project, package, pathname, prj_dir, conf.config['do_package_tracking']) p = Package.init_package(apiurl, project, package, directory, size_limit, meta, progress_obj) if isfrozen: p.mark_frozen()