def init_skin(self, skin_name, system_skin_dir, user_skin_dir, skin_config_file, app_given_id, app_given_version): '''Init skin.''' self.skin_config_file = skin_config_file if os.path.exists(skin_config_file): # Read skin name from config file. skin_config = Config(skin_config_file) skin_config.load() # Load skin. init_skin_name = skin_config.get("skin", "skin_name") else: # Create skin config if it not exists. touch_file(self.skin_config_file) init_skin_name = skin_name if self.is_skin_exist(init_skin_name, system_skin_dir, user_skin_dir): self.load_skin(init_skin_name, system_skin_dir, user_skin_dir) else: # Try load default skin if user's select skin not exists. default_skin_name = self.get_default_skin(system_skin_dir, user_skin_dir) assert(default_skin_name != None) self.load_skin(default_skin_name, system_skin_dir, user_skin_dir) self.app_given_id = app_given_id self.app_given_version = app_given_version
def __init__(self, train_path, output_path, proportion): self.path = train_path self.output_path = output_path self.proportion = proportion self.res = [] touch_file(self.output_path) self.out_f = open(self.output_path, 'a') self.tem_file_path = 'tem.tem'
def __init__(self, config_files, defaults=None, logger=None, loglevel=log.loglevel_DEFAULT): """\ @param config_files: a list of configuration file names (e.g. a global filename and a user's home directory filename) @type config_files: C{list} @param defaults: a cascaded Python dicitionary structure with ini file defaults (to override Python X2Go's hard coded defaults in L{defaults} @type defaults: C{dict} @param logger: you can pass an L{X2GoLogger} object to the L{X2GoIniFile} constructor @type logger: L{X2GoLogger} instance @param loglevel: if no L{X2GoLogger} object has been supplied a new one will be constructed with the given loglevel @type loglevel: C{int} """ self.user_config_file = None self._write_user_config = True # make sure a None type gets turned into list type if not config_files: config_files = [] if logger is None: self.logger = log.X2GoLogger(loglevel=loglevel) else: self.logger = copy.deepcopy(logger) self.logger.tag = __NAME__ self.config_files = config_files if utils._checkIniFileDefaults(defaults): self.defaultValues = defaults else: self.defaultValues = {} # we purposefully do not inherit the SafeConfigParser class # here as we do not want to run into name conflicts between # X2Go ini file options and method / property names in # SafeConfigParser... This is a pre-cautious approach... self.iniConfig = ConfigParser.SafeConfigParser() self.iniConfig.optionxform = str _create_file = False for file_name in self.config_files: file_name = os.path.normpath(file_name) if file_name.startswith(_current_home): if not os.path.exists(file_name): utils.touch_file(file_name) _create_file = True self.user_config_file = file_name break self.load() if _create_file: self._write_user_config = True self._X2GoIniFile__write()
def extract(self): env.show_status('.. extracting test file') with open(self.path) as f: touch_file(self.tem_file_path) with open(self.tem_file_path, 'a') as tem_f: for i,l in enumerate(f.readlines()): if i in self.extracted_line_nos: self.out_f.write(l) else: tem_f.write(l)
def update_snapshot(versions,v): a=versions._retriever(v) x=TarFile.open(a,'r').extractfile("sourceversion.txt") sv=read_first_line(x,'cannot read sourcerversion.txt from '+a) log.info( "latest version of "+v+' is '+sv) def retrieve(aid): return a x=versions.get((v,sv),retrieve) d=versions.path(v) if isdir(d): touch_file(d) return x
def create_dev(dev_name=None): with ROOT.locks.drafts.acquire_exclusive(): draft_name = os.readlink(ROOT.drafts.curr) os.symlink(str(int(draft_name) + 1), ROOT.drafts.next) os.rename(ROOT.drafts.next, ROOT.drafts.curr) dev_name = dev_name or ANONYM_PREFIX + draft_name dev_path = ROOT.devs[dev_name] os.rename(ROOT.drafts[draft_name], dev_path) os.symlink('../apps', dev_path.grantors[dev_name]) touch_file(ROOT.locks[dev_name]) execute_sql('CREATE TABLESPACE "%s" LOCATION \'%s\'' % (dev_name.lower(), dev_path.tablespace)) create_app(dev_name, SAMPLE_NAME) return dev_name
def __init__(self): QObject.__init__(self) self.video_db_path = os.path.join(CONFIG_DIR, "video_db") touch_file(self.video_db_path) self.video_db_connect = sqlite3.connect(self.video_db_path) self.video_db_cursor = self.video_db_connect.cursor() self.video_db_cursor.execute( "CREATE TABLE IF NOT EXISTS settings(key PRIMARY KEY NOT NULL, value)" ) self._commit_timer = QTimer() self._commit_timer.setInterval(500) self._commit_timer.setSingleShot(True) self._commit_timer.timeout.connect(lambda: self.video_db_connect.commit())
def export_skin(self, filepath): '''Export skin.''' # Build temp config file. config_filepath = os.path.join("/tmp/%s", str(uuid.uuid4())) touch_file(config_filepath) self.save_skin(config_filepath) # Build skin package. with tarfile.open("%s.tar.gz" % filepath, "w:gz") as tar: # Add config file. tar.add(config_filepath, "config.ini", False) # Add background image file. tar.add(self.get_skin_file_path(self.image), self.image, False) # Copy theme files is theme is not standard theme. if not self.theme_name in COLOR_SEQUENCE: tar.add(os.path.join(self.ui_theme_dir, self.theme_name), os.path.join("ui_theme", self.theme_name)) tar.add(os.path.join(self.app_theme_dir, self.theme_name), os.path.join("app_theme", self.theme_name)) # Remove temp config file. remove_file(config_filepath)
def create_paths(use_test_db=False): dev_path = ROOT.devs[ANONYM_NAME] app_path = dev_path.apps[SAMPLE_NAME] for path in ( ROOT.locks, ROOT.drafts, ROOT.tmp, ROOT.trash, ROOT.domains, ROOT.etc, app_path, ): if not os.path.isdir(path): os.makedirs(path) touch_file(ROOT.locks.domains) touch_file(ROOT.locks.drafts) write_file(dev_path.config, '{}') write_file(app_path.name, SAMPLE_NAME) if not os.path.islink(app_path.code): os.symlink(SAMPLE_PATH, app_path.code) if not os.path.isdir(app_path.envs): os.mkdir(app_path.envs) write_file(app_path.envs[INITIAL_ENV_NAME], INITIAL_ENV_NAME) write_file( ROOT.etc.patsak_conf, '''\ lib=%s db=dbname=%s ''' % (PATSAK_LIB_PATH, DATABASES['default']['TEST_NAME' if use_test_db else 'NAME'])) write_file( ROOT.etc.ecilop_conf, '''\ port=%d data=%s locks=%s patsak=%s patsak-config=%s log=%s ''' % (ECILOP_PORT, ROOT.data, ROOT.locks, PATSAK_EXE_PATH, ROOT.etc.patsak_conf, ROOT.log))
def create_paths(use_test_db=False): dev_path = ROOT.devs[ANONYM_NAME] app_path = dev_path.apps[SAMPLE_NAME] for path in ( ROOT.locks, ROOT.drafts, ROOT.tmp, ROOT.trash, ROOT.domains, ROOT.etc, app_path, ): if not os.path.isdir(path): os.makedirs(path) touch_file(ROOT.locks.domains) touch_file(ROOT.locks.drafts) write_file(dev_path.config, '{}') write_file(app_path.name, SAMPLE_NAME) if not os.path.islink(app_path.code): os.symlink(SAMPLE_PATH, app_path.code) if not os.path.isdir(app_path.envs): os.mkdir(app_path.envs) write_file(app_path.envs[INITIAL_ENV_NAME], INITIAL_ENV_NAME) write_file(ROOT.etc.patsak_conf, '''\ lib=%s db=dbname=%s ''' % (PATSAK_LIB_PATH, DATABASES['default']['TEST_NAME' if use_test_db else 'NAME'])) write_file(ROOT.etc.ecilop_conf, '''\ port=%d data=%s locks=%s patsak=%s patsak-config=%s log=%s ''' % (ECILOP_PORT, ROOT.data, ROOT.locks, PATSAK_EXE_PATH, ROOT.etc.patsak_conf, ROOT.log))
def __init__(self, hostname=None, port=22, username=None, password=None, passphrase=None, force_password_auth=False, key_filename=None, local_host='localhost', local_port=22022, remote_host='localhost', remote_port=22, known_hosts=None, add_to_known_hosts=False, pkey=None, look_for_keys=False, allow_agent=False, sshproxy_host=None, sshproxy_port=22, sshproxy_user=None, sshproxy_password=None, sshproxy_force_password_auth=False, sshproxy_key_filename=None, sshproxy_pkey=None, sshproxy_passphrase=None, sshproxy_look_for_keys=False, sshproxy_allow_agent=False, sshproxy_tunnel=None, ssh_rootdir=os.path.join(_LOCAL_HOME, _X2GO_SSH_ROOTDIR), session_instance=None, logger=None, loglevel=log.loglevel_DEFAULT, ): """\ Initialize an X2GoSSHProxy instance. Use an instance of this class to tunnel X2Go requests through a proxying SSH server (i.e. to subLANs that are separated by firewalls or to private IP subLANs that are NATted behind routers). @param username: login user name to be used on the SSH proxy host @type username: C{str} @param password: user's password on the SSH proxy host, with private key authentication it will be used to unlock the key (if needed) @type password: C{str} @param passphrase: a passphrase to use for unlocking a private key in case the password is already needed for two-factor authentication @type passphrase: {str} @param key_filename: name of a SSH private key file @type key_filename: C{str} @param pkey: a private DSA/RSA key object (as provided by Paramiko/SSH) @type pkey: C{RSA/DSA key instance} @param force_password_auth: enforce password authentication even if a key(file) is present @type force_password_auth: C{bool} @param look_for_keys: look for key files with standard names and try those if any can be found @type look_for_keys: C{bool} @param allow_agent: try authentication via a locally available SSH agent @type allow_agent: C{bool} @param local_host: bind SSH tunnel to the C{local_host} IP socket address (default: localhost) @type local_host: C{str} @param local_port: IP socket port to bind the SSH tunnel to (default; 22022) @type local_port: C{int} @param remote_host: remote endpoint of the SSH proxying/forwarding tunnel (default: localhost) @type remote_host: C{str} @param remote_port: remote endpoint's IP socket port for listening SSH daemon (default: 22) @type remote_port: C{int} @param known_hosts: full path to a custom C{known_hosts} file @type known_hosts: C{str} @param add_to_known_hosts: automatically add host keys of unknown SSH hosts to the C{known_hosts} file @type add_to_known_hosts: C{bool} @param hostname: alias for C{local_host} @type hostname: C{str} @param port: alias for C{local_port} @type port: C{int} @param sshproxy_host: alias for C{hostname} @type sshproxy_host: C{str} @param sshproxy_port: alias for C{post} @type sshproxy_port: C{int} @param sshproxy_user: alias for C{username} @type sshproxy_user: C{str} @param sshproxy_password: alias for C{password} @type sshproxy_password: C{str} @param sshproxy_passphrase: alias for C{passphrase} @type sshproxy_passphrase: C{str} @param sshproxy_key_filename: alias for C{key_filename} @type sshproxy_key_filename: C{str} @param sshproxy_pkey: alias for C{pkey} @type sshproxy_pkey: C{RSA/DSA key instance} (Paramiko) @param sshproxy_force_password_auth: alias for C{force_password_auth} @type sshproxy_force_password_auth: C{bool} @param sshproxy_look_for_keys: alias for C{look_for_keys} @type sshproxy_look_for_keys: C{bool} @param sshproxy_allow_agent: alias for C{allow_agent} @type sshproxy_allow_agent: C{bool} @param sshproxy_tunnel: a string of the format <local_host>:<local_port>:<remote_host>:<remote_port> which will override---if used---the options: C{local_host}, C{local_port}, C{remote_host} and C{remote_port} @type sshproxy_tunnel: C{str} @param ssh_rootdir: local user's SSH base directory (default: ~/.ssh) @type ssh_rootdir: C{str} @param session_instance: the L{X2GoSession} instance that builds up this SSH proxying tunnel @type session_instance: L{X2GoSession} instance @param logger: you can pass an L{X2GoLogger} object to the L{X2GoSSHProxy} constructor @type logger: L{X2GoLogger} instance @param loglevel: if no L{X2GoLogger} object has been supplied a new one will be constructed with the given loglevel @type loglevel: int @raise X2GoSSHProxyAuthenticationException: if the SSH proxy caused a C{paramiko.AuthenticationException} @raise X2GoSSHProxyException: if the SSH proxy caused a C{paramiko.SSHException} """ if logger is None: self.logger = log.X2GoLogger(loglevel=loglevel) else: self.logger = copy.deepcopy(logger) self.logger.tag = __NAME__ if hostname and hostname in (types.UnicodeType, types.StringType): hostname = [hostname] if hostname and hostname in (types.ListType, types.TupleType): hostname = random.choice(list(hostname)) self.hostname, self.port, self.username = hostname, port, username if sshproxy_port: self.port = sshproxy_port # translate between X2GoSession options and paramiko.SSHCLient.connect() options # if <hostname>:<port> is used for sshproxy_host, then this <port> is used if sshproxy_host: if sshproxy_host and type(sshproxy_host) in (types.UnicodeType, types.StringType): sshproxy_host = [sshproxy_host] if type(sshproxy_host) in (types.ListType, types.TupleType): sshproxy_host = random.choice(list(sshproxy_host)) if sshproxy_host.find(':'): self.hostname = sshproxy_host.split(':')[0] try: self.port = int(sshproxy_host.split(':')[1]) except IndexError: pass else: self.hostname = sshproxy_host if sshproxy_user: self.username = sshproxy_user if sshproxy_password: password = sshproxy_password if sshproxy_passphrase: passphrase = sshproxy_passphrase if sshproxy_force_password_auth: force_password_auth = sshproxy_force_password_auth if sshproxy_key_filename: key_filename = sshproxy_key_filename if sshproxy_pkey: pkey = sshproxy_pkey if sshproxy_look_for_keys: look_for_keys = sshproxy_look_for_keys if sshproxy_allow_agent: allow_agent = sshproxy_allow_agent if sshproxy_tunnel: self.local_host, self.local_port, self.remote_host, self.remote_port = sshproxy_tunnel.split(':') self.local_port = int(self.local_port) self.remote_port = int(self.remote_port) else: if local_host and type(local_host) in (types.UnicodeType, types.StringType): local_host = [local_host] if local_host and type(local_host) in (types.ListType, types.TupleType): local_host = random.choice(list(local_host)) if remote_host and type(remote_host) in (types.UnicodeType, types.StringType): remote_host = [remote_host] if remote_host and type(remote_host) in (types.ListType, types.TupleType): remote_host = random.choice(remote_host) print "LOCAL_HOST: ", local_host self.local_host = local_host self.local_port = int(local_port) self.remote_host = remote_host self.remote_port = int(remote_port) # allow more trailing whitespace tolerance in hostnames self.hostname = self.hostname.strip() self.local_host = self.local_host.strip() self.remote_host = self.remote_host.strip() # do not use explicitly given keys if look_for_keys has got activated if look_for_keys: key_filename = None pkey = None if key_filename and "~" in key_filename: key_filename = os.path.expanduser(key_filename) if password and (passphrase is None): passphrase = password # enforce IPv4 for localhost addresses!!! _hostname = self.hostname if _hostname in ('localhost', 'localhost.localdomain'): _hostname = '127.0.0.1' if self.local_host in ('localhost', 'localhost.localdomain'): self.local_host = '127.0.0.1' if self.remote_host in ('localhost', 'localhost.localdomain'): self.remote_host = '127.0.0.1' if username is None: username = _CURRENT_LOCAL_USER if type(password) not in (types.StringType, types.UnicodeType): password = '' self._keepalive = True self.session_instance = session_instance self.client_instance = None if self.session_instance is not None: self.client_instance = self.session_instance.get_client_instance() self.ssh_rootdir = ssh_rootdir paramiko.SSHClient.__init__(self) self.known_hosts = known_hosts if self.known_hosts: utils.touch_file(self.known_hosts) self.load_host_keys(self.known_hosts) if not add_to_known_hosts and session_instance: self.set_missing_host_key_policy(checkhosts.X2GoInteractiveAddPolicy(caller=self, session_instance=session_instance)) if add_to_known_hosts: self.set_missing_host_key_policy(paramiko.AutoAddPolicy()) try: if key_filename or pkey or look_for_keys or allow_agent or (password and force_password_auth): try: if password and force_password_auth: self.connect(_hostname, port=self.port, username=self.username, password=password, key_filename=None, pkey=None, look_for_keys=False, allow_agent=False, ) elif (key_filename and os.path.exists(os.path.normpath(key_filename))) or pkey: self.connect(_hostname, port=self.port, username=self.username, key_filename=key_filename, pkey=pkey, allow_agent=False, look_for_keys=False, ) else: self.connect(_hostname, port=self.port, username=self.username, key_filename=None, pkey=None, look_for_keys=look_for_keys, allow_agent=allow_agent, ) except (paramiko.PasswordRequiredException, paramiko.SSHException), e: self.close() if type(e) == paramiko.SSHException and str(e).startswith('Two-factor authentication requires a password'): self.logger('SSH proxy host requests two-factor authentication', loglevel=log.loglevel_NOTICE) raise x2go_exceptions.X2GoSSHProxyException(str(e)) if passphrase is None: try: if not password: password = None if (key_filename and os.path.exists(os.path.normpath(key_filename))) or pkey: try: self.connect(_hostname, port=self.port, username=self.username, password=password, passphrase=passphrase, key_filename=key_filename, pkey=pkey, allow_agent=False, look_for_keys=False, ) except TypeError: self.connect(_hostname, port=self.port, username=self.username, password=passphrase, key_filename=key_filename, pkey=pkey, allow_agent=False, look_for_keys=False, ) else: try: self.connect(_hostname, port=self.port, username=self.username, password=password, passphrase=passphrase, key_filename=None, pkey=None, look_for_keys=look_for_keys, allow_agent=allow_agent, ) except TypeError: self.connect(_hostname, port=self.port, username=self.username, password=passphrase, key_filename=None, pkey=None, look_for_keys=look_for_keys, allow_agent=allow_agent, ) except x2go_exceptions.AuthenticationException, auth_e: raise x2go_exceptions.X2GoSSHProxyAuthenticationException(str(auth_e)) else: if type(e) == paramiko.SSHException: raise x2go_exceptions.X2GoSSHProxyException(str(e)) elif type(e) == paramiko.PasswordRequiredException: raise x2go_exceptions.X2GoSSHProxyPasswordRequiredException(str(e)) except x2go_exceptions.AuthenticationException: self.close() raise x2go_exceptions.X2GoSSHProxyAuthenticationException('all authentication mechanisms with SSH proxy host failed') except x2go_exceptions.SSHException: self.close() raise x2go_exceptions.X2GoSSHProxyAuthenticationException('with SSH proxy host password authentication is required') except: raise # since Paramiko 1.7.7.1 there is compression available, let's use it if present... t = self.get_transport() if x2go._paramiko.PARAMIKO_FEATURE['use-compression']: t.use_compression(compress=False) t.set_keepalive(5)
def init_packages(): """ Download requirements """ print("Downloading python packages") os.system("python -m pip install -r requirements.txt") # try: # os.system("python -m pip install -r src\\requirements.txt") # except Exception: # pass if __name__ == "__main__": init_packages() touch_file() if len(sys.argv) < 3: print(USAGE_MESSAGE.format(ROLL)) exit(-1) PATH_SLIDES = sys.argv[1] PATH_FRAMES = sys.argv[2] PATH_FRAMES = os.path.abspath(PATH_FRAMES) PATH_SLIDES = os.path.abspath(PATH_SLIDES) slides = os.listdir(PATH_SLIDES) frames = os.listdir(PATH_FRAMES) slider = [] framer = []
def finalize(aoid,d): touch_file(join(d,'.loaded'))