Bläddra i källkod

GITC: Pull GITC Manifest Dir from the config.

Updates the repo launcher and gitc_utils to pull the manifest
directory location out of the gitc config file.

Change-Id: Id08381b8a7d61962093d5cddcb3ff6afbb13004b
Simran Basi 10 år sedan
förälder
incheckning
8ce5041596
5 ändrade filer med 35 tillägg och 21 borttagningar
  1. 4 2
      gitc_utils.py
  2. 1 1
      manifest_xml.py
  3. 27 2
      repo
  4. 3 3
      subcmds/gitc_init.py
  5. 0 13
      subcmds/sync.py

+ 4 - 2
gitc_utils.py

@@ -20,13 +20,15 @@ import time
 
 import git_command
 import git_config
+import wrapper
 
 
-# TODO (sbasi) - Remove this constant and fetch manifest dir from /gitc/.config
-GITC_MANIFEST_DIR = '/usr/local/google/gitc/'
 GITC_FS_ROOT_DIR = '/gitc/manifest-rw/'
 NUM_BATCH_RETRIEVE_REVISIONID = 300
 
+def get_gitc_manifest_dir():
+  return wrapper.Wrapper().get_gitc_manifest_dir()
+
 def parse_clientdir(gitc_fs_path):
   """Parse a path in the GITC FS and return its client name.
 

+ 1 - 1
manifest_xml.py

@@ -956,7 +956,7 @@ class GitcManifest(XmlManifest):
     super(GitcManifest, self).__init__(repodir)
     self.isGitcClient = True
     self.gitc_client_name = gitc_client_name
-    self.gitc_client_dir = os.path.join(gitc_utils.GITC_MANIFEST_DIR,
+    self.gitc_client_dir = os.path.join(gitc_utils.get_gitc_manifest_dir(),
                                         gitc_client_name)
     self.manifestFile = os.path.join(self.gitc_client_dir, '.manifest')
 

+ 27 - 2
repo

@@ -108,7 +108,7 @@ S_repo = 'repo'                 # special repo repository
 S_manifests = 'manifests'       # special manifest repository
 REPO_MAIN = S_repo + '/main.py' # main script
 MIN_PYTHON_VERSION = (2, 6)     # minimum supported python version
-GITC_MANIFEST_DIR = '/usr/local/google/gitc'
+GITC_CONFIG_FILE = '/gitc/.config'
 
 
 import errno
@@ -222,6 +222,20 @@ def _GitcInitOptions(init_optparse):
                dest='gitc_client',
                help='The name for the new gitc_client instance.')
 
+_gitc_manifest_dir = None
+def get_gitc_manifest_dir():
+  global _gitc_manifest_dir
+  if _gitc_manifest_dir is None:
+    try:
+      with open(GITC_CONFIG_FILE, 'r') as gitc_config:
+        for line in gitc_config:
+          match = re.match('gitc_dir=(?P<gitc_manifest_dir>.*)', line)
+          if match:
+            _gitc_manifest_dir = match.group('gitc_manifest_dir')
+    except IOError:
+      _gitc_manifest_dir = ''
+  return _gitc_manifest_dir
+
 class CloneFailure(Exception):
   """Indicate the remote clone of repo itself failed.
   """
@@ -255,7 +269,12 @@ def _Init(args, gitc_init=False):
 
   try:
     if gitc_init:
-      client_dir = os.path.join(GITC_MANIFEST_DIR, opt.gitc_client)
+      gitc_manifest_dir = get_gitc_manifest_dir()
+      if not gitc_manifest_dir:
+        _print('error: GITC filesystem is not running. Exiting...',
+               file=sys.stderr)
+        sys.exit(1)
+      client_dir = os.path.join(gitc_manifest_dir, opt.gitc_client)
       if not os.path.exists(client_dir):
         os.makedirs(client_dir)
       os.chdir(client_dir)
@@ -746,6 +765,12 @@ def main(orig_args):
   wrapper_path = os.path.abspath(__file__)
   my_main, my_git = _RunSelf(wrapper_path)
 
+  cwd = os.getcwd()
+  if cwd.startswith(get_gitc_manifest_dir()):
+    _print('error: repo cannot be used in the GITC local manifest directory.'
+           '\nIf you want to work on this GITC client please rerun this '
+           'command from the corresponding client under /gitc/', file=sys.stderr)
+    sys.exit(1)
   if not repo_main:
     if opt.help:
       _Usage()

+ 3 - 3
subcmds/gitc_init.py

@@ -59,10 +59,10 @@ use for this GITC client.
     if not opt.gitc_client:
       print('fatal: gitc client (-c) is required', file=sys.stderr)
       sys.exit(1)
-    self.client_dir = os.path.join(gitc_utils.GITC_MANIFEST_DIR,
+    self.client_dir = os.path.join(gitc_utils.get_gitc_manifest_dir(),
                                    opt.gitc_client)
-    if not os.path.exists(gitc_utils.GITC_MANIFEST_DIR):
-      os.makedirs(gitc_utils.GITC_MANIFEST_DIR)
+    if not os.path.exists(gitc_utils.get_gitc_manifest_dir()):
+      os.makedirs(gitc_utils.get_gitc_manifest_dir())
     if not os.path.exists(self.client_dir):
       os.mkdir(self.client_dir)
     super(GitcInit, self).Execute(opt, args)

+ 0 - 13
subcmds/sync.py

@@ -194,9 +194,6 @@ later is required to fix a server side protocol bug.
                  help="overwrite an existing git directory if it needs to "
                       "point to a different object directory. WARNING: this "
                       "may cause loss of data")
-    p.add_option('--force-gitc',
-                 dest='force_gitc', action='store_true',
-                 help="actually sync sources in the gitc client directory.")
     p.add_option('-l', '--local-only',
                  dest='local_only', action='store_true',
                  help="only update working tree, don't fetch")
@@ -539,16 +536,6 @@ later is required to fix a server side protocol bug.
         print('error: both -u and -p must be given', file=sys.stderr)
         sys.exit(1)
 
-    cwd = os.getcwd()
-    if cwd.startswith(gitc_utils.GITC_MANIFEST_DIR) and not opt.force_gitc:
-      print('WARNING this will pull all the sources like a normal repo sync.\n'
-            '\nIf you want to update your GITC Client View please rerun this '
-            'command in \n%s%s.\nOr if you actually want to pull the sources, '
-            'rerun with --force-gitc.' %
-            (gitc_utils.GITC_FS_ROOT_DIR,
-             cwd.split(gitc_utils.GITC_MANIFEST_DIR)[1]))
-      sys.exit(1)
-
     if opt.manifest_name:
       self.manifest.Override(opt.manifest_name)