def main(): rootp = argparse.ArgumentParser() creds = rootp.add_mutually_exclusive_group(required=False) creds.add_argument('--creds', help='username:password', action='store') creds.add_argument('--kerberos', help='use kerberos', action='store_true') sub = rootp.add_subparsers(help='commands', dest='cmd') sub.required = True #cmd_list = ['state', 'gpo'] #cmd_list = ['gpo', 'state'] cmd_list = ['policy'] commands = {} debug("import CLI commands") for c in cmd_list: debug(c) try: mod = importlib.import_module("gpom.cli.cmd.%s" % c) impl = mod.CMDImpl() except Exception as e: raise RuntimeError("Cannot load module for %s: %s" % (c, e)) debug("add '%s' to the commands list" % impl.cmd) impl.init_subparser(sub) commands[impl.cmd] = impl args = rootp.parse_args() commands[args.cmd].run(args)
def __apply__(self): de = self.desktop_name() if not de: error("Cannot determine DE") debug("Set policy state as NOT IMPLEMENTED") return if de == 'MATE': debug("Looks like DE is MATE") key = "/org/mate/desktop/background/picture-filename" value = "%s/%s" % (config['Policy']['cache_dir'], self.payload[0]) command = " ".join([ # 'export `/usr/bin/dbus-launch`', # ';', '/usr/bin/dconf write', key, "\"'%s'\"" % _escape_single_quotes(value), # ';', # 'kill $DBUS_SESSION_BUS_PID &> /dev/null' ]) # command = '/usr/bin/dconf write %s %s' % (key, "\"'%s'\"" % _escape_single_quotes(value)) debug(command) res = subprocess.check_output(['/bin/sh', '-c', command]).strip() debug("result: %s" % res)
def fetch_gpo(self, gpo, force=False): gpo_name = gpo['displayName'][0] gpo_whenChanged = gpo['whenChanged'][0] l_time = self.state.get(gpo_name, 'whenChanged') # gpo_guid = gpo['name'][0] gpo_path = "%s/%s" % (self.gpo_cache_path, gpo['name'][0]) # gpo_path = gpo['path'] gpo_link_path = "%s/%s" % (self.gpo_cache_path, gpo_name) if l_time: l_time = datetime.strptime(l_time, '%Y%m%d%H%M%S.%fZ') try: r_time = datetime.strptime(gpo_whenChanged, '%Y%m%d%H%M%S.%fZ') except Exception as e: raise ValueError("Got invalid datetime format from remote. Expected '%Y%m%d%H%M%S.%fZ' but got %s" % gpo_whenChanged) debug('remote time for %s is %s' % (gpo_name, r_time)) debug('local time for %s is %s' % (gpo_name, l_time)) if not force and l_time and l_time >= r_time: debug("local time match remote time. No need to update") return l_dir = gpo_path if os.path.isdir(l_dir): link_name = "%s/%s" % (self.gpo_cache_path, gpo_name) if os.path.exists(link_name): os.unlink(link_name) shutil.rmtree(l_dir) os.makedirs(l_dir) os.symlink(l_dir, "%s/%s" % (self.gpo_cache_path, gpo_name)) for unc in gpo['gPCFileSysPath']: self.fetch_dir(unc, l_dir, recursive=True) self.state.set(gpo_name, 'whenChanged', gpo_whenChanged)
import importlib from gpom.common import config, error, warning, info, debug #, SambaParams rootp = argparse.ArgumentParser() creds = rootp.add_mutually_exclusive_group(required=False) creds.add_argument('--creds', help='username:password', action='store') creds.add_argument('--kerberos', help='use kerberos', action='store_true') sub = rootp.add_subparsers(help='commands', dest='cmd') sub.required = True #cmd_list = ['state', 'gpo'] #cmd_list = ['gpo', 'state'] cmd_list = ['policy'] commands = {} debug("import CLI commands") for c in cmd_list: debug(c) try: mod = importlib.import_module("gpom.cli.cmd.%s" % c) impl = mod.CMDImpl() except Exception as e: raise RuntimeError("Cannot load module for %s: %s" % (c, e)) debug("add '%s' to the commands list" % impl.cmd) impl.init_subparser(sub) commands[impl.cmd] = impl args = rootp.parse_args() commands[args.cmd].run(args)