Python os.path.expanduser() Examples

The following are code examples for showing how to use os.path.expanduser(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: spqrel_tools   Author: LCAS   File: asr.py    MIT License 6 votes vote down vote up
def onSpeechDetected(self, value):
        print "speechdetected=", value
        if value == 1:
            if self.USE_GOOGLE:
                if not self.recording:
                    #try:
                    #    self.AUDIO_FILE_DIR = self.memory_proxy.getData("NAOqibag/CurrentLogFolder") + "/asr_logs/"
                    #except:
                    self.AUDIO_FILE_DIR = expanduser('~') + '/bags/no_data/asr_logs/'
                    if not os.path.exists(self.AUDIO_FILE_DIR):
                        os.makedirs(self.AUDIO_FILE_DIR)
                    self.AUDIO_FILE_PATH = self.AUDIO_FILE_DIR + 'SPQReL_mic_'

                    #self.audio_recorder.stopMicrophonesRecording()
                    self.AUDIO_FILE = self.AUDIO_FILE_PATH + str(time.time())
                    self.audio_recorder.startMicrophonesRecording(self.AUDIO_FILE + ".wav", "wav", 44100, self.CHANNELS)
                    self.recording = True
                    print "Audio recorder started recording" 
Example 2
Project: FCOS_GluonCV   Author: DetectionTeamUCAS   File: market1501.py    Apache License 2.0 6 votes vote down vote up
def main():
    name = "Market-1501-v15.09.15"
    url = "http://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/"+name+".zip"
    root = osp.expanduser("~/.mxnet/datasets")
    if not os.path.exists(root):
        os.mkdir(root)
    fpath = osp.join(root, name+'.zip')
    exdir = osp.join(root, name)

    if os.path.exists(fpath):
        if not osp.isdir(exdir):
            extract(fpath)
            make_list(exdir)
            
    else:
        download(url, fpath, False)
        extract(fpath)
        make_list(exdir) 
Example 3
Project: adversarial_da_icvgip18   Author: abhinavagarwalla   File: gaze_sanity_check.py    MIT License 6 votes vote down vote up
def check_from_syn_to_real():
    img, vec = get_reference_real_vec()
    eye_c = np.array([55/2, 35/2])
    print("Original Vector: ", vec)
    cv2.line(img, tuple(eye_c), tuple(eye_c+(np.array(vec[:2])*80).astype(int)), (255,255,255), 3)
    im = Image.fromarray(img.reshape(35, 55))
    im.save(np.array_str(vec) + '_original.jpg')
    
    syn_data_path = expanduser('~') + '/domain_adaptation_datasets/eye_gaze/imgs_cropped/*.png'
    addrs = glob.glob(syn_data_path)
    labels = [ad.replace('imgs_cropped', 'imgs').replace('_cropped.png', '.json') for ad in addrs]

    minloss = 10.
    minaddr = None
    minlookvec = None
    for i in labels:
        look_vec = get_syn_img_lbl(i)
        l2loss = np.mean(np.abs(look_vec - vec))
        if l2loss < minloss:
            print("loss: ", l2loss, ", i: ", i, ", look:, vec: ", look_vec, vec, look_vec-vec)
            minloss = l2loss
            minaddr = i
            minlookvec = look_vec

    print("MinLoss, MinAddr, Minlookvec: ", minloss, minaddr, minlookvec) 
Example 4
Project: adversarial_da_icvgip18   Author: abhinavagarwalla   File: real_gaze_converter.py    MIT License 6 votes vote down vote up
def write_data(img_data_path):
    """ Divide dataset into training, validation and test sets and store them as TFRecords """

    patients = os.listdir(img_data_path)
    train_addrs = [glob.glob(img_data_path + i + '/*') for i in patients[0:int(0.75*len(patients))]]
    val_addrs = [glob.glob(img_data_path + i + '/*') for i in patients[int(0.75*len(patients)):int(0.90*len(patients))]]
    test_addrs = [glob.glob(img_data_path + i + '/*') for i in patients[int(0.9*len(patients)):]]

    n_shards = 8
    train_filenames = [expanduser("~") + '/domain_adaptation/eye_gaze/data/realMPII/{}_{:0>3}_{:0>3}.tfrecords'.format('train', i, n_shards-1) for i in range(n_shards)]
    val_filenames = [expanduser("~") + '/domain_adaptation/eye_gaze/data/realMPII/{}_{:0>3}_{:0>3}.tfrecords'.format('val', i, n_shards-1) for i in range(n_shards)]
    test_filenames = [expanduser("~") + '/domain_adaptation/eye_gaze/data/realMPII/{}_{:0>3}_{:0>3}.tfrecords'.format('test', i, n_shards-1) for i in range(n_shards)]

    #write_record(train_filenames[0], train_addrs[0], 'train')
    p = Pool(n_shards)
    p.map(write_record, train_filenames, train_addrs, ['train' for i in range(n_shards)])
    p.map(write_record, val_filenames, val_addrs, ['val' for i in range(n_shards/2)])
    p.map(write_record, test_filenames, test_addrs, ['test' for i in range(n_shards/2)])
    sys.stdout.flush() 
Example 5
Project: tldr.py   Author: lord63   File: config.py    MIT License 6 votes vote down vote up
def get_config():
    """Get the configurations from .tldrrc and return it as a dict."""
    config_path = path.join(
        (os.environ.get('TLDR_CONFIG_DIR') or path.expanduser('~')),
        '.tldrrc')
    if not path.exists(config_path):
        sys.exit("Can't find config file at: {0}. You may use `tldr init` "
                 "to init the config file.".format(config_path))

    with io.open(config_path, encoding='utf-8') as f:
        try:
            config = yaml.safe_load(f)
        except yaml.scanner.ScannerError:
            sys.exit("The config file is not a valid YAML file.")

    supported_colors = ['black', 'red', 'green', 'yellow', 'blue',
                        'magenta', 'cyan', 'white']
    if not set(config['colors'].values()).issubset(set(supported_colors)):
        sys.exit("Unsupported colors in config file: {0}.".format(
            ', '.join(set(config['colors'].values()) - set(supported_colors))))
    if not path.exists(config['repo_directory']):
        sys.exit("Can't find the tldr repo, check the `repo_directory` "
                 "setting in config file.")

    return config 
Example 6
Project: pyplis   Author: jgliss   File: inout.py    GNU General Public License v3.0 6 votes vote down vote up
def data_search_dirs():
    """Get basic search directories for package data files.

    Data files are searched for in `~/my_pyplis`, `./data` and, if set,
    in the `PYPLIS_DATADIR` environment variable.
    """
    from pyplis import __dir__
    import os
    usr_dir = expanduser(join('~', 'my_pyplis'))
    if not exists(usr_dir):
        mkdir(usr_dir)
    try:
        env = os.environ["PYPLIS_DATADIR"]
        return (usr_dir, join(__dir__, "data"), env)
    except KeyError:
        return (usr_dir, join(__dir__, "data")) 
Example 7
Project: ansible-azure-openshift   Author: drhelius   File: azure_rm.py    MIT License 6 votes vote down vote up
def _get_profile(self, profile="default"):
        path = expanduser("~")
        path += "/.azure/credentials"
        try:
            config = cp.ConfigParser()
            config.read(path)
        except Exception as exc:
            self.fail("Failed to access {0}. Check that the file exists and you have read "
                      "access. {1}".format(path, str(exc)))
        credentials = dict()
        for key in AZURE_CREDENTIAL_ENV_MAPPING:
            try:
                credentials[key] = config.get(profile, key, raw=True)
            except:
                pass

        if credentials.get('client_id') is not None or credentials.get('ad_user') is not None:
            return credentials

        return None 
Example 8
Project: ansible-azure-openshift   Author: drhelius   File: azure_rm.py    MIT License 6 votes vote down vote up
def _load_settings(self):
        basename = os.path.splitext(os.path.basename(__file__))[0]
        default_path = os.path.join(os.path.dirname(__file__), (basename + '.ini'))
        path = os.path.expanduser(os.path.expandvars(os.environ.get('AZURE_INI_PATH', default_path)))
        config = None
        settings = None
        try:
            config = cp.ConfigParser()
            config.read(path)
        except:
            pass

        if config is not None:
            settings = dict()
            for key in AZURE_CONFIG_SETTINGS:
                try:
                    settings[key] = config.get('azure', key, raw=True)
                except:
                    pass

        return settings 
Example 9
Project: RefineDet_MxNet   Author: DetectionTeamUCAS   File: market1501.py    Apache License 2.0 6 votes vote down vote up
def main():
    name = "Market-1501-v15.09.15"
    url = "http://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/"+name+".zip"
    root = osp.expanduser("~/.mxnet/datasets")
    if not os.path.exists(root):
        os.mkdir(root)
    fpath = osp.join(root, name+'.zip')
    exdir = osp.join(root, name)

    if os.path.exists(fpath):
        if not osp.isdir(exdir):
            extract(fpath)
            make_list(exdir)
            
    else:
        download(url, fpath, False)
        extract(fpath)
        make_list(exdir) 
Example 10
Project: vo_single_camera_sos   Author: ubuntuslave   File: pose_est_tools.py    GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, camera_model, show_3D_points = False, **kwargs):
        self.camera_model = camera_model
        self.show_3D_points = show_3D_points
        self.save_correspondence_images = kwargs.get("save_correspondence_images", False)
        self.results_path = kwargs.get("results_path", "~/temp")
        self.correspondence_images_path = ""
        if self.save_correspondence_images:
            self.correspondence_images_path = join(realpath(expanduser(self.results_path)), "final_correspondences_images")
            make_sure_path_exists(self.correspondence_images_path)
        self.T_C_wrt_S_init = tr.identity_matrix()
        self.T_C_curr_frame_wrt_S_est = tr.identity_matrix()
        self.xyz_homo_points_wrt_C_inliers = []  # XYZ homogeneous coordinates of inliers for the estimated pose
        self.rgb_points_inliers = []  # Colors for inlier points
        self.num_tracked_correspondences = 0  # RANSAC inliers of current tracking
        self.inlier_tracked_correspondences_ratio = 0.  # RANSAC inliers of current tracking
        self.number_of_cams = 1  # Just a default number that should be changed if needed
        self.T_Ckey_wrt_S_est_list = []  # This should only contain a list of keyframe poses
        self.set_global_parameters_for_tracking()  # This is done here because we are attempting to unify the trackers inheriting from this class 
Example 11
Project: sql-editor   Author: struts2spring   File: WorkspaceDao.py    MIT License 6 votes vote down vote up
def __init__(self, databaseFileName='_opal.sqlite'):
        '''
        Creating database for library.
        '''
        self.home = home = expanduser("~")
        databasePath = os.path.join(home, databaseFileName)
        logger.debug('databasePath: %s', databasePath)
        logger.debug('CreateDatabase')
        databasePath = os.path.join(home, databaseFileName)
        isDatabaseExist = os.path.exists(databasePath)

        databaseFilePath = f'sqlite:///{databasePath}'
        self.engine = create_engine(databaseFilePath , echo=True, connect_args={'check_same_thread': False})
        Session = sessionmaker(autoflush=True, autocommit=False, bind=self.engine)
        self.session = Session()
        
        os.makedirs(home, exist_ok=True)
        self.recreateDatabase()
#         Base.metadata.create_all(self.engine)
#         if not isDatabaseExist:
# #             os.mkdir(libraryPath)
#             self.creatingDatabase()
        os.chdir(home) 
Example 12
Project: screeps-stats   Author: screepers   File: settings.py    MIT License 6 votes vote down vote up
def getSettings():
    if not getSettings.settings:
        cwd = os.getcwd()
        path = cwd + '/.settings.yaml'

        if not os.path.isfile(path):
            path = cwd + '/.screeps_settings.yaml'

        if not os.path.isfile(path):
            path = expanduser('~') + '/.screeps_settings.yaml'

        if not os.path.isfile(path):
            path = '/vagrant/.screeps_settings.yaml'


        if not os.path.isfile(path):
            print 'no settings file found'
            sys.exit(-1)
            return False

        with open(path, 'r') as f:
            getSettings.settings = yaml.load(f)

    return getSettings.settings 
Example 13
Project: BlockchainPKI   Author: noahcoomer   File: client.py    Apache License 2.0 6 votes vote down vote up
def update_blockchain(self):
        '''
            Update blockchain to be current
        '''
        block_path = expanduser("~")
        block_path = os.path.join(block_path, ".BlockchainPKI/chain/")
        chain = None
        if os.path.exists(block_path):
            print("Loading local blockchain files...")
            # Need to implement this
        else:
            # Else make the block path and initialize a chain
            # Uncomment next line when serialization is finished
            # os.path.mkdir(block_path)
            chain = Blockchain()
        # Broadcast the last block of our current chain to let the network know we need blocks after this point
        # Uncomment next line before going live
        self.broadcast_transaction(chain.last_block)
        # receive until we are updated ???
        return chain 
Example 14
Project: rm-protection   Author: alanzchen   File: protect.py    MIT License 6 votes vote down vote up
def protect(protect_args=None):
    global c
    flags = ''
    option_end = False
    if not protect_args:
        protect_args = argv[1:]
    for arg in protect_args:
        if arg == '--':
            option_end = True
        elif (arg.startswith("-") and not option_end):
            flags = flags + arg[arg.rfind('-') + 1:]
        elif arg in c.invalid:
            pprint('"." and ".." may not be protected')
        else:
            path = abspath(expv(expu(arg)))
            evalpath = dirname(path) + "/." + basename(path) + c.suffix
            if not exists(path):
                pprint("Warning: " + path + " does not exist")
            with open(evalpath, "w") as f:
                question = input("Question for " + path + ": ")
                answer = input("Answer: ")
                f.write(question + "\n" + answer + "\n" + flags.upper()) 
Example 15
Project: fcos-gluon-cv   Author: Angzz   File: market1501.py    Apache License 2.0 6 votes vote down vote up
def main():
    name = "Market-1501-v15.09.15"
    url = "http://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/"+name+".zip"
    root = osp.expanduser("~/.mxnet/datasets")
    if not os.path.exists(root):
        os.mkdir(root)
    fpath = osp.join(root, name+'.zip')
    exdir = osp.join(root, name)

    if os.path.exists(fpath):
        if not osp.isdir(exdir):
            extract(fpath)
            make_list(exdir)
            
    else:
        download(url, fpath, False)
        extract(fpath)
        make_list(exdir) 
Example 16
Project: autolims   Author: scottbecker   File: custom_connection.py    MIT License 5 votes vote down vote up
def from_file(path):
        """Loads connection from file"""
        with open(expanduser(path), 'r') as f:
            cfg = json.loads(f.read())
            return CustomConnection(**cfg)    
        
        
    #custom version that prevents ssl verification 
Example 17
Project: mycroft-skill-tunein   Author: johnbartkiw   File: __init__.py    MIT License 5 votes vote down vote up
def apply_aliases(self, search_term):
        # Allow search terms to be expanded or aliased
        home = expanduser('~')
        alias_file = home + '/tunein_aliases.yaml'
        if path.exists(alias_file):
            with open(alias_file, 'r') as file:
                alias_list = yaml.load(file)
            if search_term in alias_list:
                search_term = alias_list[search_term]
        return search_term

    # Attempt to find the first active station matching the query string 
Example 18
Project: spqrel_tools   Author: LCAS   File: remote_speech_recognition.py    MIT License 5 votes vote down vote up
def start(self, *args, **kwargs):
        self.subscribe(
            event=RemoteSpeechRecognition.TD_EVENT,
            callback=self.text_done_callback
        )

        self.subscribe(
            event=RemoteSpeechRecognition.ASR_ENABLE,
            callback=self.enable_callback
        )

        print "[" + self.inst.__class__.__name__ + "] Subscribers:", self.memory.getSubscribers(
            RemoteSpeechRecognition.WR_EVENT)
        print "[" + self.inst.__class__.__name__ + "] Subscribers:", self.memory.getSubscribers(
            RemoteSpeechRecognition.TD_EVENT)
        print "[" + self.inst.__class__.__name__ + "] Subscribers:", self.memory.getSubscribers(
            RemoteSpeechRecognition.ASR_ENABLE)

        self.is_enabled = False

        print "[" + self.inst.__class__.__name__ + "] ASR disabled"

        if self.logging:
            self.AUDIO_FILE_DIR = expanduser('~') + '/bags/asr_logs/'
        else:
            self.AUDIO_FILE_DIR = '/tmp/asr_logs/'
        if not os.path.exists(self.AUDIO_FILE_DIR):
            os.makedirs(self.AUDIO_FILE_DIR)
        self.AUDIO_FILE_PATH = self.AUDIO_FILE_DIR + 'SPQReL_mic_'

        self._spin()

        if self.is_enabled == True:
            self.unsubscribe(RemoteSpeechRecognition.WR_EVENT)
        self.unsubscribe(RemoteSpeechRecognition.TD_EVENT)
        self.unsubscribe(RemoteSpeechRecognition.ASR_ENABLE)
        self.broker.shutdown() 
Example 19
Project: spqrel_tools   Author: LCAS   File: remote_speech_recognition.py    MIT License 5 votes vote down vote up
def enable_callback(self, *args, **kwargs):
        print 'ok'
        if args[1] == "0":
            if self.is_enabled:
                self.is_enabled = False
                self.audio_recorder.stopMicrophonesRecording()
                self.unsubscribe(RemoteSpeechRecognition.WR_EVENT)
                print "[" + self.inst.__class__.__name__ + "] ASR disabled"
            else:
                print "[" + self.inst.__class__.__name__ + "] ASR already disabled"
        else:
            if not self.is_enabled:
                try:
                    self.AUDIO_FILE_DIR = self.memory_proxy.getData("NAOqibag/CurrentLogFolder") + "/asr_logs/"
                except:
                    self.AUDIO_FILE_DIR = expanduser('~') + '/bags/no_data/asr_logs/'
                if not os.path.exists(self.AUDIO_FILE_DIR):
                    os.makedirs(self.AUDIO_FILE_DIR)
                self.AUDIO_FILE_PATH = self.AUDIO_FILE_DIR + 'SPQReL_mic_'
                self.is_enabled = True
                self.audio_recorder.stopMicrophonesRecording()
                self.AUDIO_FILE = self.AUDIO_FILE_PATH + str(time.time())
                self.audio_recorder.startMicrophonesRecording(self.AUDIO_FILE + ".wav")
                self.subscribe(
                    event=RemoteSpeechRecognition.WR_EVENT,
                    callback=self.word_recognized_callback
                )
                print "[" + self.inst.__class__.__name__ + "] ASR enabled"
            else:
                print "[" + self.inst.__class__.__name__ + "] ASR already enabled" 
Example 20
Project: spqrel_tools   Author: LCAS   File: local_speech_recognition.py    MIT License 5 votes vote down vote up
def start(self):
        self.td_sub = self.memory.subscriber(self.TD_EVENT)
        self.td_sub_id = self.td_sub.signal.connect(self.text_done_callback)


        self.enable_sub = self.memory.subscriber(self.ASR_ENABLE)
        self.enable_sub_id = self.enable_sub.signal.connect(self.enable_callback)

        self.wr_sub = self.memory.subscriber(self.WR_EVENT)
        self.wr_sub_id = self.wr_sub.signal.connect(self.word_recognized_callback)

        self.sd_sub = self.memory.subscriber(self.SD_EVENT)
        self.sd_sub_id = self.sd_sub.signal.connect(self.speech_detected_callback)
        #self.wr_sub_id = None
        time.sleep(3)

        print "[" + self.__class__.__name__ + "] Subscribers:", self.memory.getSubscribers(
            SpeechRecognition.WR_EVENT)
        print "[" + self.__class__.__name__ + "] Subscribers:", self.memory.getSubscribers(
            SpeechRecognition.TD_EVENT)
        print "[" + self.__class__.__name__ + "] Subscribers:", self.memory.getSubscribers(
            SpeechRecognition.ASR_ENABLE)

        self.is_enabled = True

        #print "[" + self.__class__.__name__ + "] ASR disabled"

        if self.USE_GOOGLE:
            if self.logging:
                self.AUDIO_FILE_DIR = expanduser('~') + '/bags/asr_logs/'
            else:
                self.AUDIO_FILE_DIR = '/tmp/asr_logs/'
            if not os.path.exists(self.AUDIO_FILE_DIR):
                os.makedirs(self.AUDIO_FILE_DIR)
            self.AUDIO_FILE_PATH = self.AUDIO_FILE_DIR + 'SPQReL_mic_'

        #if self.is_enabled:
        #    self.unsubscribe(SpeechRecognition.WR_EVENT)
        #self.unsubscribe(SpeechRecognition.TD_EVENT)
        #self.unsubscribe(SpeechRecognition.ASR_ENABLE)
        #self.broker.shutdown() 
Example 21
Project: spqrel_tools   Author: LCAS   File: local_speech_recognition.py    MIT License 5 votes vote down vote up
def enable_callback(self, msg):
        if msg == "0":
            if self.is_enabled:
                self.is_enabled = False
                if self.USE_GOOGLE:
                    self.audio_recorder.stopMicrophonesRecording()
                if self.wr_sub_id is not None:
                    self.wr_sub_id.disconnect()
                print "[" + self.__class__.__name__ + "] ASR disabled"
            else:
                print "[" + self.__class__.__name__ + "] ASR already disabled"
        else:
            if not self.is_enabled:
                if self.USE_GOOGLE:
                    #try:
                    #    self.AUDIO_FILE_DIR = self.memory_proxy.getData("NAOqibag/CurrentLogFolder") + "/asr_logs/"
                    #except:
                    self.AUDIO_FILE_DIR = expanduser('~') + '/bags/no_data/asr_logs/'
                    if not os.path.exists(self.AUDIO_FILE_DIR):
                        os.makedirs(self.AUDIO_FILE_DIR)
                    self.AUDIO_FILE_PATH = self.AUDIO_FILE_DIR + 'SPQReL_mic_'
                self.is_enabled = True

                if self.USE_GOOGLE:
                    self.audio_recorder.stopMicrophonesRecording()
                    self.AUDIO_FILE = self.AUDIO_FILE_PATH + str(time.time())
                    self.audio_recorder.startMicrophonesRecording(self.AUDIO_FILE + ".wav", "wav", 44100, self.CHANNELS)

                #self.subscribe(
                #    event=SpeechRecognition.WR_EVENT,
                #    callback=self.word_recognized_callback
                #)
                print "[" + self.__class__.__name__ + "] ASR enabled"
            else:
                print "[" + self.__class__.__name__ + "] ASR already enabled" 
Example 22
Project: FCOS_GluonCV   Author: DetectionTeamUCAS   File: label_read.py    Apache License 2.0 5 votes vote down vote up
def LabelList(ratio=1, root='~/.mxnet/datasets', name='market1501'):
    """Load the Label List for Market 1501 dataset.

    Parameters
    ----------
    ratio : float, default 1
        Split label into train and test.
    root : str, default '~/.mxnet/datasets'
        Path to the folder stored the dataset.
    name : str, default 'market1501'
        Which dataset is used. Only support market 1501 now.
    """
    root = osp.expanduser(root)

    if name == "market1501":
        path = osp.join(root, "Market-1501-v15.09.15")
        train_txt = osp.join(path, "train.txt")
        image_path = osp.join(path, "bounding_box_train")

        item_list = [(osp.join(image_path, line.split()[0]), int(line.split()[1]))
                     for line in open(train_txt).readlines()]
        random.shuffle(item_list)
        count = len(item_list)
        train_count = int(count * ratio)

        train_set = item_list[:train_count]
        valid_set = item_list[train_count:]

        return train_set, valid_set
    return None, None 
Example 23
Project: mealpy   Author: edmundmok   File: venv_update.py    MIT License 5 votes vote down vote up
def user_cache_dir():
    # stolen from pip.utils.appdirs.user_cache_dir
    from os import getenv
    from os.path import expanduser
    return getenv('XDG_CACHE_HOME', expanduser('~/.cache')) 
Example 24
Project: specio   Author: paris-saclay-cds   File: test_request.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_request():
    filename = 'file://' + join(DATA_PATH, 'data', 'spectra.foobar')
    R = Request(filename)
    assert R._uri_type == core.request.URI_FILENAME
    assert R.get_local_filename() == filename[7:]
    file_obj = R.get_file()
    assert file_obj.name == filename[7:]

    filename = join(DATA_PATH, 'data', 'spectra.foobar')
    R = Request(filename)
    assert R._uri_type == core.request.URI_FILENAME
    assert R.get_local_filename() == filename
    file_obj = R.get_file()
    assert file_obj.name == filename

    filename = join(DATA_PATH, 'data', 'spectra.foobar')
    file_obj = open(filename, 'rb')
    R = Request(file_obj)
    assert R.get_local_filename() == filename
    assert R.get_file().name == filename

    shutil.copy(filename, expanduser('~/'))
    filename = '~/spectra.foobar'
    R = Request(filename)
    assert R.filename == expanduser('~/spectra.foobar').replace('/', sep)
    os.remove(expanduser(filename))
    filename = join(DATA_PATH, 'data', 'spectra.foobar')
    R = Request(filename, some_kwarg='something')
    assert R.kwargs == {'some_kwarg': 'something'} 
Example 25
Project: adversarial_da_icvgip18   Author: abhinavagarwalla   File: gaze_sanity_check.py    MIT License 5 votes vote down vote up
def get_mat_real(lbl):
    img_data_path = expanduser('~') + '/domain_adaptation_datasets/MPIIGaze/Data/Normalized/'
    patients = os.listdir(img_data_path)
    addrs = [glob.glob(img_data_path + i + '/*') for i in patients]
    for idx in range(len(addrs)):
        for idx2 in range(len(addrs[idx])):
            imgs, look_vecs, l2loss = load_image_label(addrs[idx][idx2], lbl)
            print(imgs.shape, look_vecs.shape, l2loss.shape, l2loss)
            eye_c = np.array([55/2, 35/2])
            cv2.line(imgs, tuple(eye_c), tuple(eye_c+(np.array(look_vecs[:2])*80).astype(int)), (255,255,255), 3)
            im = Image.fromarray(imgs.reshape(35, 55))
            im.save(str(l2loss) + '_' + np.array_str(look_vecs) + '_' + np.array_str(lbl) + '.jpg') 
Example 26
Project: adversarial_da_icvgip18   Author: abhinavagarwalla   File: gaze_sanity_check.py    MIT License 5 votes vote down vote up
def get_reference_real_vec():
    data_arr = loadmat(expanduser('~') + '/domain_adaptation_datasets/MPIIGaze/Data/Normalized/p10/day12.mat')
    data = data_arr['data'][0][0][0][0][0]
    look_vec = data[0][10]
    img = imresize(data[1][10], (35, 55))
    return np.array(img), np.array(look_vec).astype(np.float32) 
Example 27
Project: adversarial_da_icvgip18   Author: abhinavagarwalla   File: gaze_converter.py    MIT License 5 votes vote down vote up
def write_para_record(addrs, labels, split='train', n_shards=10):
    train_filenames = [expanduser("~") + '/domain_adaptation/data/syn_data_4_april_2018_norm/{}_{:0>3}_{:0>3}.tfrecords'.format(split, i, n_shards-1) for i in range(n_shards)]
    addrs_split, labels_split = np.array_split(np.array(addrs), n_shards), np.array_split(np.array(labels), n_shards)
    # print(type(addrs_split), len(addrs_split), addrs_split[0].shape)
    p = Pool(n_shards)
    p.map(write_record, train_filenames, addrs_split, labels_split, [split for i in range(n_shards)])
    # write_record(train_filenames[0], addrs_split, labels_split, split)
    sys.stdout.flush() 
Example 28
Project: tldr.py   Author: lord63   File: cli.py    MIT License 5 votes vote down vote up
def init():
    """Init config file."""
    default_config_path = path.join(
        (os.environ.get('TLDR_CONFIG_DIR') or path.expanduser('~')),
        '.tldrrc')
    if path.exists(default_config_path):
        click.echo("There is already a config file exists, "
                   "skip initializing it.")
    else:
        repo_path = click.prompt("Input the tldr repo path(absolute path)")
        if not path.exists(repo_path):
            sys.exit("Repo path not exist, clone it first.")

        platform = click.prompt("Input your platform(linux, osx or sunos)")
        if platform not in ['linux', 'osx', 'sunos']:
            sys.exit("Platform should be in linux, osx or sunos.")

        colors = {
            "description": "blue",
            "usage": "green",
            "command": "cyan"
        }

        config = {
            "repo_directory": repo_path,
            "colors": colors,
            "platform": platform
        }
        with open(default_config_path, 'w') as f:
            f.write(yaml.safe_dump(config, default_flow_style=False))

        click.echo("Initializing the config file at {0}".format(
            default_config_path)) 
Example 29
Project: HardRLWithYoutube   Author: MaxSobolMark   File: run.py    MIT License 5 votes vote down vote up
def main(custom_args=[]):
    # configure logger, disable logging in child MPI processes (with rank > 0) 
    arg_parser = common_arg_parser()
    args, unknown_args = arg_parser.parse_known_args()
    extra_args = {}
    for arg in custom_args:
        if arg in vars(args).keys():
            vars(args)[arg] = custom_args[arg]
        else:
            extra_args[arg] = custom_args[arg]
    
    #extra_args = {k: parse(v) for k,v in parse_unknown_args(unknown_args).items()}

    
    if MPI is None or MPI.COMM_WORLD.Get_rank() == 0:
        rank = 0
        logger.configure(format_strs = ['stdout', 'tensorboard'])
    else:
        logger.configure(format_strs = ['stdout', 'tensorboard'])
        rank = MPI.COMM_WORLD.Get_rank()

    model, _ = train(args, extra_args)

    if args.save_path is not None and rank == 0:
        save_path = osp.expanduser(args.save_path)
        model.save(save_path)
    

    if args.play:
        logger.log("Running trained model")
        env = build_env(args)
        obs = env.reset()
        while True:
            actions = model.step(obs)[0]
            obs, _, done, _  = env.step(actions)
            env.render()
            done = done.any() if isinstance(done, np.ndarray) else done

            if done:
                obs = env.reset() 
Example 30
Project: MyDotfiles   Author: Sup3r-Us3r   File: commands_full.py    GNU General Public License v3.0 5 votes vote down vote up
def execute(self):
        import os.path
        match = self.PATH_RE.match(self.arg(1))
        if match:
            path = os.path.normpath(os.path.expanduser(match.group(1)))
            self.shift()
        elif self.fm.thisdir:
            path = self.fm.thisdir.path
        else:
            path = None

        if path:
            name = self.arg(1)
            name, value, _ = self.parse_setting_line()
            self.fm.set_option_from_string(name, value, localpath=path) 
Example 31
Project: MyDotfiles   Author: Sup3r-Us3r   File: commands_full.py    GNU General Public License v3.0 5 votes vote down vote up
def execute(self):
        from os.path import join, expanduser, lexists
        from os import makedirs

        dirname = join(self.fm.thisdir.path, expanduser(self.rest(1)))
        if not lexists(dirname):
            makedirs(dirname)
        else:
            self.fm.notify("file/directory exists!", bad=True) 
Example 32
Project: MyDotfiles   Author: Sup3r-Us3r   File: commands_full.py    GNU General Public License v3.0 5 votes vote down vote up
def execute(self):
        from os.path import join, expanduser, lexists

        fname = join(self.fm.thisdir.path, expanduser(self.rest(1)))
        if not lexists(fname):
            open(fname, 'a').close()
        else:
            self.fm.notify("file/directory exists!", bad=True) 
Example 33
Project: bitpay-brick   Author: javgh   File: config.py    MIT License 5 votes vote down vote up
def read_api_key():
    api_key_file = expanduser('~') + '/' + API_KEY_FILE
    if not isfile(api_key_file):
        return None
    with open(api_key_file, 'r') as f:
        api_key = f.read()
    return api_key.strip() 
Example 34
Project: bitpay-brick   Author: javgh   File: test_bitpayprovider.py    MIT License 5 votes vote down vote up
def read_test_api_key():
    api_key_file = expanduser('~') + '/' + TEST_API_KEY_FILE
    if not isfile(api_key_file):
        return None
    with open(api_key_file, 'r') as f:
        api_key = f.read()
    return api_key.strip() 
Example 35
Project: aladdin   Author: fivestars-os   File: helm.py    MIT License 5 votes vote down vote up
def helm_home(self):
        return join(expanduser("~"), '.helm') 
Example 36
Project: aws_shortcuts   Author: sunil-saini   File: host.py    GNU General Public License v3.0 5 votes vote down vote up
def get_home_directory():
    return expanduser("~") 
Example 37
Project: omesa   Author: cmry   File: database.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self):
        """Load backend."""
        self.db = FileBackend(expanduser("~/.omesa/db")) 
Example 38
Project: omesa   Author: cmry   File: database.py    GNU General Public License v3.0 5 votes vote down vote up
def _query(self, f, q):
        try:
            out = f(*q)
        except KeyError:
            self.db = FileBackend(expanduser("~/.omesa/db"))
            f = self.db.filter
            out = f(*q)
        return out 
Example 39
Project: RefineDet_MxNet   Author: DetectionTeamUCAS   File: label_read.py    Apache License 2.0 5 votes vote down vote up
def LabelList(ratio=1, root='~/.mxnet/datasets', name='market1501'):
    """Load the Label List for Market 1501 dataset.

    Parameters
    ----------
    ratio : float, default 1
        Split label into train and test.
    root : str, default '~/.mxnet/datasets'
        Path to the folder stored the dataset.
    name : str, default 'market1501'
        Which dataset is used. Only support market 1501 now.
    """
    root = osp.expanduser(root)

    if name == "market1501":
        path = osp.join(root, "Market-1501-v15.09.15")
        train_txt = osp.join(path, "train.txt")
        image_path = osp.join(path, "bounding_box_train")

        item_list = [(osp.join(image_path, line.split()[0]), int(line.split()[1]))
                     for line in open(train_txt).readlines()]
        random.shuffle(item_list)
        count = len(item_list)
        train_count = int(count * ratio)

        train_set = item_list[:train_count]
        valid_set = item_list[train_count:]

        return train_set, valid_set
    return None, None 
Example 40
Project: dired   Author: kublaios   File: prompt.py    MIT License 5 votes vote down vote up
def start(msg, window, path, callback):
    """
    Starts the prompting process.
    """
    if not path.endswith(os.sep):
        path += os.sep
    path = expanduser(path)
    map_window_to_ctx[window.id()] = PromptContext(msg, path, callback)
    window.run_command('dired_prompt') 
Example 41
Project: dired   Author: kublaios   File: prompt.py    MIT License 5 votes vote down vote up
def run(self):
        ctx = map_window_to_ctx.get(self.window.id())
        if not ctx:
            return

        path = expanduser(ctx.path)
        path, prefix = self._parse_split(path)
        if path is None:
            print('Invalid:', ctx.path)
            return

        completions = [ n for n in os.listdir(path) if n.startswith(prefix) and isdir(join(path, n)) ]

        if len(completions) == 0:
            sublime.status_message('No matches')
            self._close_completions(ctx)
            return

        if len(completions) == 1:
            ctx.path = join(path, completions[0]) + os.sep
            self.window.run_command('dired_prompt')
            self._close_completions(ctx)
            return

        common = os.path.commonprefix(completions)
        if common and common > prefix:
            ctx.path = join(path, common)
            self.window.run_command('dired_prompt')
            self._close_completions(ctx)
            return

        # There are multiple possibilities.  Display a completion view.

        if not ctx.completion_view:
            ctx.completion_view = self.window.new_file()
            ctx.completion_view.set_scratch(True)
            ctx.completion_view.set_name('*completions*')

        ctx.completion_view.run_command('dired_show_completions', { "completions": completions })
        self.window.focus_view(ctx.completion_view) 
Example 42
Project: NiujiaoDebugger   Author: MrSrc   File: macosx.py    GNU General Public License v3.0 5 votes vote down vote up
def readSystemPreferences():
    """
    Fetch the macOS system preferences.
    """
    if platform != 'darwin':
        return None

    plist_path = expanduser('~/Library/Preferences/.GlobalPreferences.plist')
    try:
        with open(plist_path, 'rb') as plist_file:
            return plistlib.load(plist_file)
    except OSError:
        return None 
Example 43
Project: readysetstem-api   Author: readysetstem   File: testing_log.py    Apache License 2.0 5 votes vote down vote up
def _log_name(self):
        log_dir = expanduser('~/rstem_logs/')
        symlink_name = log_dir + 'testlog.txt'
        log_file_name = 'testlog.' + str(int(time.time())) + '.txt'
        return (log_dir, symlink_name, log_file_name) 
Example 44
Project: smaslennikov.github.io   Author: smaslennikov   File: grep.py    MIT License 5 votes vote down vote up
def get_home():
    home = weechat.config_string(weechat.config_get('logger.file.path'))
    home = path.abspath(path.expanduser(home))
    return home.replace('%h', weechat.info_get('weechat_dir', '')) 
Example 45
Project: smaslennikov.github.io   Author: smaslennikov   File: grep.py    MIT License 5 votes vote down vote up
def get_file_by_pattern(pattern, all=False):
    """Returns the first log whose path matches 'pattern',
    if all is True returns all logs that matches."""
    if not pattern: return []
    #debug('get_file_by_filename: searching for %s.' %pattern)
    # do envvar expandsion and check file
    file = path.expanduser(pattern)
    file = path.expandvars(file)
    if path.isfile(file):
        return [file]
    # lets see if there's a matching log
    global home_dir
    file = path.join(home_dir, pattern)
    if path.isfile(file):
        return [file]
    else:
        from fnmatch import fnmatch
        file = []
        file_list = dir_list(home_dir)
        n = len(home_dir)
        for log in file_list:
            basename = log[n:]
            if fnmatch(basename, pattern):
                file.append(log)
        #debug('get_file_by_filename: got %s.' %file)
        if not all and file:
            file.sort()
            return [ file[-1] ]
        return file 
Example 46
Project: smaslennikov.github.io   Author: smaslennikov   File: grep.py    MIT License 5 votes vote down vote up
def get_home():
    home = weechat.config_string(weechat.config_get('logger.file.path'))
    home = path.abspath(path.expanduser(home))
    return home.replace('%h', weechat.info_get('weechat_dir', '')) 
Example 47
Project: smaslennikov.github.io   Author: smaslennikov   File: grep.py    MIT License 5 votes vote down vote up
def get_file_by_pattern(pattern, all=False):
    """Returns the first log whose path matches 'pattern',
    if all is True returns all logs that matches."""
    if not pattern: return []
    #debug('get_file_by_filename: searching for %s.' %pattern)
    # do envvar expandsion and check file
    file = path.expanduser(pattern)
    file = path.expandvars(file)
    if path.isfile(file):
        return [file]
    # lets see if there's a matching log
    global home_dir
    file = path.join(home_dir, pattern)
    if path.isfile(file):
        return [file]
    else:
        from fnmatch import fnmatch
        file = []
        file_list = dir_list(home_dir)
        n = len(home_dir)
        for log in file_list:
            basename = log[n:]
            if fnmatch(basename, pattern):
                file.append(log)
        #debug('get_file_by_filename: got %s.' %file)
        if not all and file:
            file.sort()
            return [ file[-1] ]
        return file 
Example 48
Project: Reinforcement_Learning_for_Traffic_Light_Control   Author: quantumiracle   File: run.py    Apache License 2.0 5 votes vote down vote up
def main(args, extra_args, save_path):
    # configure logger, disable logging in child MPI processes (with rank > 0)

    # arg_parser = common_arg_parser()
    # args, unknown_args = arg_parser.parse_known_args()
    # extra_args = parse_cmdline_kwargs(unknown_args)

    if MPI is None or MPI.COMM_WORLD.Get_rank() == 0:
        rank = 0
        logger.configure()
    else:
        logger.configure(format_strs=[])
        rank = MPI.COMM_WORLD.Get_rank()

    model, env = train(args, extra_args)
    # env.close()

    # if args.save_path is not None and rank == 0:
    #     save_path = osp.expanduser(args.save_path)
    model.save(save_path)

    if args.play:
        logger.log("Running trained model")
        print()
        # env = build_env(args)
        obs = env.reset()
        def initialize_placeholders(nlstm=128,**kwargs):
            return np.zeros((args.num_env or 1, 2*nlstm)), np.zeros((1))
        state, dones = initialize_placeholders(**extra_args)
        while True:
            actions, _, state, _ = model.step(obs,S=state, M=dones)
            obs, _, done, _ = env.step(actions)
            env.render()
            done = done.any() if isinstance(done, np.ndarray) else done

            if done:
                obs = env.reset()

        env.close() 
Example 49
Project: Reinforcement_Learning_for_Traffic_Light_Control   Author: quantumiracle   File: run.py    Apache License 2.0 5 votes vote down vote up
def main(args, extra_args, save_path):
    # configure logger, disable logging in child MPI processes (with rank > 0)

    # arg_parser = common_arg_parser()
    # args, unknown_args = arg_parser.parse_known_args()
    # extra_args = parse_cmdline_kwargs(unknown_args)

    if MPI is None or MPI.COMM_WORLD.Get_rank() == 0:
        rank = 0
        logger.configure()
    else:
        logger.configure(format_strs=[])
        rank = MPI.COMM_WORLD.Get_rank()

    model, env = train(args, extra_args)
    # env.close()

    # if args.save_path is not None and rank == 0:
    #     save_path = osp.expanduser(args.save_path)
    model.save(save_path)

    if args.play:
        logger.log("Running trained model")
        print()
        # env = build_env(args)
        obs = env.reset()
        def initialize_placeholders(nlstm=128,**kwargs):
            return np.zeros((args.num_env or 1, 2*nlstm)), np.zeros((1))
        state, dones = initialize_placeholders(**extra_args)
        while True:
            actions, _, state, _ = model.step(obs,S=state, M=dones)
            obs, _, done, _ = env.step(actions)
            env.render()
            done = done.any() if isinstance(done, np.ndarray) else done

            if done:
                obs = env.reset()

        env.close() 
Example 50
Project: Reinforcement_Learning_for_Traffic_Light_Control   Author: quantumiracle   File: run.py    Apache License 2.0 5 votes vote down vote up
def main(args, extra_args, save_path):
    # configure logger, disable logging in child MPI processes (with rank > 0)

    # arg_parser = common_arg_parser()
    # args, unknown_args = arg_parser.parse_known_args()
    # extra_args = parse_cmdline_kwargs(unknown_args)

    if MPI is None or MPI.COMM_WORLD.Get_rank() == 0:
        rank = 0
        logger.configure()
    else:
        logger.configure(format_strs=[])
        rank = MPI.COMM_WORLD.Get_rank()

    model, env = train(args, extra_args)
    # env.close()

    # if args.save_path is not None and rank == 0:
    #     save_path = osp.expanduser(args.save_path)
    model.save(save_path)

    if args.play:
        logger.log("Running trained model")
        print()
        # env = build_env(args)
        obs = env.reset()
        def initialize_placeholders(nlstm=128,**kwargs):
            return np.zeros((args.num_env or 1, 2*nlstm)), np.zeros((1))
        state, dones = initialize_placeholders(**extra_args)
        while True:
            actions, _, state, _ = model.step(obs,S=state, M=dones)
            obs, _, done, _ = env.step(actions)
            env.render()
            done = done.any() if isinstance(done, np.ndarray) else done

            if done:
                obs = env.reset()

        # env.close()