On Friday August 14th. from 9 p.m. to 9:30 p.m., we will upgrade GitLab software and its cloud platform release. Service may not be available during this maintenance window. Please schedule your work accordingly.

...
 
Commits (2)
......@@ -36,6 +36,14 @@ class SuDatastore(object):
self.SUNET = sunet or os.environ.get("USER")
self.HOME = os.environ.get("HOME")
def os_spec(self, key):
return self.OS_SPECIFICS.get(self.OS).get(key)
def get_output(self, command, **kwargs):
options = {"stderr": subprocess.STDOUT, "shell": True}
options.update(kwargs)
return subprocess.check_output(command, **options)
class SuAFS(SuDatastore):
AFS_USER_HOME = None
......@@ -48,10 +56,7 @@ class SuAFS(SuDatastore):
else:
# import IPython; IPython.embed()
self.AFS_USER_HOME = os.path.join(
self.OS_SPECIFICS.get(self.OS).get("HOME_PATH"),
self.SUNET[0],
self.SUNET[1],
self.SUNET,
self.os_spec("HOME_PATH"), self.SUNET[0], self.SUNET[1], self.SUNET
)
if subprocess.call(["klist", "-t"]) != 0:
raise Exception(
......@@ -82,7 +87,8 @@ class SuAFS(SuDatastore):
if (
not re.search(
rb"^Callers access to \. is rlidwka$",
subprocess.check_output(["fs", "getcalleraccess"]),
self.get_output("fs getcalleraccess")
# subprocess.check_output(["fs", "getcalleraccess"]),
)
and self.AFS_HOME_OWNER != self.SUNET
):
......@@ -94,19 +100,19 @@ class SuAFS(SuDatastore):
class SuGDrive(SuDatastore):
DEST_DIR = None
def __init__(self, sunet=None, dest_home_path="imported_AFS"):
super().__init__(sunet)
if subprocess.call(["which", "gdrive"]) != 0:
raise Exception(
'Gdrive CLI app not installed, please install it. {0}"'.format(
self.OS_SPECIFICS.get(self.OS).get("GDRIVE_INSTALL_STEPS")
self.os_spec("GDRIVE_INSTALL_STEPS")
)
)
if not os.path.exists(os.path.join(self.HOME + ".gdrive/token_v2.json")):
try:
subprocess.check_output(
"gdrive list", input=b"\n", stderr=subprocess.STDOUT, shell=True
)
self.get_output("gdrive list", input=b"\n")
except subprocess.CalledProcessError as e:
print(
'After you have copied the token from the browser window that just displayed, run "gdrive list" from your command line and paste it when asked'
......@@ -124,10 +130,23 @@ class SuGDrive(SuDatastore):
)
logger.debug("auth url => {}".format(auth_url))
os.system(
self.OS_SPECIFICS.get(self.OS).get("DEFAULT_BROWSER_CMD")
+ " '{}'".format(auth_url)
self.os_spec("DEFAULT_BROWSER_CMD") + " '{}'".format(auth_url)
)
# subprocess.check_output('gdrive about')
def setup_dest_dir(self, dirname="AFS_HOME"):
output = self.get_output(
"gdrive list -q \"name = '{}' and 'root' in parents and trashed=false\"".format(
dirname
)
)
if not dirname.encode() in output:
output = self.get_output("gdrive mkdir '{}'".format(dirname))
if re.match(r"^Directory .* created$", str(output)):
self.DEST_DIR = dirname
else:
return False
else:
return True
if __name__ == "__main__":
......@@ -152,6 +171,7 @@ if __name__ == "__main__":
afs = SuAFS(sunet=args.sunet)
gdrive = SuGDrive(sunet=args.sunet)
gdrive.setup_dest_dir()
logger.debug("Detected AFS attributes: {}".format(afs.__dict__))
logger.debug("Detected gDrive attributes: {}".format(gdrive.__dict__))
......