39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
import os
|
|
import grp
|
|
import pwd
|
|
##
|
|
import paramiko
|
|
|
|
|
|
class Mirror(object):
|
|
def __init__(self, mirror_xml, ns = '', *args, **kwargs):
|
|
self.xml = mirror_xml
|
|
self.ns = ns
|
|
if os.environ.get('SUDO_USER'):
|
|
_uname = os.environ['SUDO_USER']
|
|
else:
|
|
_uname = pwd.getpwuid(os.geteuid()).pw_name
|
|
self.user = pwd.getpwnam(mirror_xml.attrib.get('user', _uname))
|
|
self.fmode = int(self.xml.attrib.get('fileMode', '0600'), 8)
|
|
self.dmode = int(self.xml.attrib.get('dirMode', '0700'), 8)
|
|
self.dest = self.xml.text
|
|
|
|
|
|
class LocalMirror(Mirror):
|
|
def __init__(self, mirror_xml, ns = '', *args, **kwargs):
|
|
super().__init__(mirror_xml, ns = ns, *args, **kwargs)
|
|
if os.environ.get('SUDO_GID'):
|
|
_grpnm = os.environ['SUDO_GID']
|
|
else:
|
|
_grpnm = grp.getgrgid(os.getegid()).gr_name
|
|
self.group = grp.getgrnam(mirror_xml.attrib.get('group', _grpnm))
|
|
self.dest = os.path.abspath(os.path.expanduser(self.dest))
|
|
|
|
|
|
class RemoteMirror(Mirror):
|
|
def __init__(self, mirror_xml, ns = '', *args, **kwargs):
|
|
super().__init__(mirror_xml, ns = ns, *args, **kwargs)
|
|
self.port = int(mirror_xml.attrib.get('port', 22))
|
|
self.keyfile = os.path.abspath(os.path.expanduser(mirror_xml.attrib.get('key', '~/.ssh/id_rsa')))
|
|
self.remote_user = mirror_xml.attrib.get('remoteUser')
|
|
self.remote_group = mirror_xml.attrib.get('remoteGroup') |