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 (3)
......@@ -19,6 +19,37 @@ logging.basicConfig(
logger = logging.getLogger(__name__)
class Migrator(object):
src = None
dest = None
def __init__(self, sunet=None):
self.src = SuAFS(sunet)
self.dest = SuGDrive(sunet)
self.setup()
def setup(self):
self.dest.setup_dest_dir()
def migrate(self):
command = (
"gdrive sync upload --keep-local "
+ self.src.AFS_USER_HOME
+ " "
+ self.dest.DEST_DIR_ID
)
os.system(command)
logger.debug(
'Failed command {} to migrate {} to destination dir on gDrive "{}" ({}):'.format(
command,
self.src.AFS_USER_HOME,
self.dest.DEST_DIR,
self.dest.DEST_DIR_ID,
)
)
# gdrive sync upload --keep-local /afs/ir/users/g/o/golfieri/ 18tOx4OdFPyIRkkokmz3Z1Ln0_XbPcAw5
class SuDatastore(object):
SUNET = None
HOME = None
......@@ -39,7 +70,7 @@ class SuDatastore(object):
def os_spec(self, key):
return self.OS_SPECIFICS.get(self.OS).get(key)
def get_output(self, command, **kwargs):
def shell_output(self, command, **kwargs):
options = {"stderr": subprocess.STDOUT, "shell": True}
options.update(kwargs)
return subprocess.check_output(command, **options)
......@@ -54,7 +85,6 @@ class SuAFS(SuDatastore):
if afs_user_home:
self.AFS_USER_HOME = afs_user_home
else:
# import IPython; IPython.embed()
self.AFS_USER_HOME = os.path.join(
self.os_spec("HOME_PATH"), self.SUNET[0], self.SUNET[1], self.SUNET
)
......@@ -87,8 +117,7 @@ class SuAFS(SuDatastore):
if (
not re.search(
rb"^Callers access to \. is rlidwka$",
self.get_output("fs getcalleraccess")
# subprocess.check_output(["fs", "getcalleraccess"]),
self.shell_output("fs getcalleraccess"),
)
and self.AFS_HOME_OWNER != self.SUNET
):
......@@ -112,7 +141,7 @@ class SuGDrive(SuDatastore):
)
if not os.path.exists(os.path.join(self.HOME + ".gdrive/token_v2.json")):
try:
self.get_output("gdrive list", input=b"\n")
self.shell_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'
......@@ -134,19 +163,28 @@ class SuGDrive(SuDatastore):
)
def setup_dest_dir(self, dirname="AFS_HOME"):
output = self.get_output(
self.DEST_DIR = dirname
listing = self.shell_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
if dirname.encode() not in listing:
output = self.shell_output("gdrive mkdir '{}'".format(dirname))
match = re.match(rb"^Directory (.*) created$", output)
if match:
self.DEST_DIR_ID = match.groups()[0].decode("utf-8")
else:
return False
raise Exception(
'Cannot create destination directory "{}"'.format(dirname)
)
else:
return True
self.DEST_DIR_ID = (
re.search(b"\s(.*)\s+" + dirname.encode(), listing, re.MULTILINE)
.groups()[0]
.strip()
).decode("utf-8")
return True
if __name__ == "__main__":
......@@ -169,14 +207,14 @@ if __name__ == "__main__":
)
args = parser.parse_args()
afs = SuAFS(sunet=args.sunet)
gdrive = SuGDrive(sunet=args.sunet)
gdrive.setup_dest_dir()
migrator = Migrator(sunet=args.sunet)
logger.debug("Detected AFS attributes: {}".format(migrator.src.__dict__))
logger.debug("Detected gDrive attributes: {}".format(migrator.dest.__dict__))
logger.debug("Detected AFS attributes: {}".format(afs.__dict__))
logger.debug("Detected gDrive attributes: {}".format(gdrive.__dict__))
migrator.migrate()
if args.interactive:
import IPython
import IPython # import IPython; IPython.embed()
IPython.embed() ##############################################################
IPython.embed()