From the API:

        Returns the 10 most recent files accepted by the 'magic' file selection
        algorithm. Currently any files with 10 or more likes are magic.

        Returns:
            List of SharedFile objects
3858
def get_magic_shake(self, before=None, after=None):
        
        if before and after:
            raise Exception("You cannot specify both before and after keys")

        endpoint = '/api/magicfiles'

        if before:
            endpoint += '/before/{key}'.format(key=before)
        elif after:
            endpoint += '/after/{key}'.format(key=after)

        data = self._make_request("GET", endpoint=endpoint)
        return [SharedFile.NewFromJSON(sf) for sf in data['magicfiles']]
814165
def get_last(self, num=10):
        
        max_item = self.get_max_item()
        urls = [urljoin(self.item_url, F"{i}.json") for i in range(
            max_item - num + 1, max_item + 1)]
        result = self._run_async(urls=urls)
        return [Item(r) for r in result if r]
172848
def files(self):
        
        # maybe replace with a trie at some point? see has_file FIXME
        already_seen = set()
        filenames = []

        for el in self.xml.xpath("//class"):
            filename = el.attrib['filename']
            if filename in already_seen:
                continue
            already_seen.add(filename)
            filenames.append(filename)

        return filenames
1022835
def get_associated(self, retrieve=False):

		'''
		
		'''

		if self.exists and hasattr(self.rdf.triples, 'pcdm') and hasattr(self.rdf.triples.pcdm, 'hasRelatedFile'):
			files = [ self.repo.parse_uri(uri) for uri in self.rdf.triples.pcdm.hasRelatedFile ]

			# return
			return files

		else:
			return []
1092035
def files(self):
        
        ios_names = [info.name for info in self._ios_to_add.keys()]
        return set(self.files_to_add + ios_names)
103664
def last_modified():
    
    files = model.FileFingerprint.select().order_by(
        orm.desc(model.FileFingerprint.file_mtime))
    for file in files:
        return file.file_mtime, file.file_path
    return None, None
36581
def get_all_filelist(data_dir):
    

    all_meta = []
    all_table = []
    all_element = []
    all_component = []

    special = ['METADATA.json', 'REFERENCES.json']

    for root, dirs, files in os.walk(data_dir):
        for basename in files:
            if basename in special:
                continue

            fpath = os.path.join(root, basename)
            fpath = os.path.relpath(fpath, data_dir)

            if basename.endswith('.metadata.json'):
                all_meta.append(fpath)
            elif basename.endswith('.table.json'):
                all_table.append(fpath)
            elif basename.endswith('.element.json'):
                all_element.append(fpath)
            elif basename.endswith('.json'):
                all_component.append(fpath)

    return (all_meta, all_table, all_element, all_component)
1347344
def __add_recent_file(self, fname):
        """"""
        if fname is None:
            return
        if fname in self.recent_files:
            self.recent_files.remove(fname)
        self.recent_files.insert(0, fname)
        if len(self.recent_files) > self.get_option('max_recent_files'):
            self.recent_files.pop(-1)
365465
def newest_file(file_iterable):
  
  return max(file_iterable, key=lambda fname: os.path.getmtime(fname))
218382
def most_visited_pages_stats():
    
    stats = {'more_than_10': [], 'less_than_10': {}}

    counter = Counter(list(RequestLog.objects.values_list('url', flat=True)))
    most_visited_pages = counter.most_common()
    bounds = (10000, 1000, 100, 10)
    subsets = [[] for _ in bounds]

    for u, c in most_visited_pages:
        if url_is_ignored(u):
            continue
        if c >= bounds[0]:
            subsets[0].append([u, c])
        elif c < bounds[-1]:
            subsets[-1].append([u, c])
        else:
            for i, bound in enumerate(bounds[:-1]):
                if bound > c >= bounds[i+1]:
                    subsets[i+1].append([u, c])
                    break

    stats['more_than_10'] = [
        {'bound': bound, 'subset': subset}
        for bound, subset in zip(bounds[:-1], subsets[:-1])]

    for subset in subsets[:-1]:
        for uc in subset:
            if url_is_project(uc[0]):
                if url_is_asset(uc[0]):
                    uc.append(ASSET)
                else:
                    uc.append(PROJECT)
            else:
                if url_is_asset(uc[0]):
                    uc.append(OLD_ASSET)
                elif url_is_common_asset(uc[0]):
                    uc.append(COMMON_ASSET)
                elif url_is_old_project(uc[0]):
                    uc.append(OLD_PROJECT)
                elif url_is_false_negative(uc[0]):
                    uc.append(FALSE_NEGATIVE)
                else:
                    uc.append(SUSPICIOUS)

    occurrences = {name: {'distinct': 0, 'total': 0}
                   for name in set(URL_TYPE.keys()) - {IGNORED}}

    for u, c in subsets[-1]:
        if url_is_project(u):
            if url_is_asset(u):
                occurrences[ASSET]['distinct'] += 1
                occurrences[ASSET]['total'] += c
            else:
                occurrences[PROJECT]['distinct'] += 1
                occurrences[PROJECT]['total'] += c
        else:
            if url_is_asset(u):
                occurrences[OLD_ASSET]['distinct'] += 1
                occurrences[OLD_ASSET]['total'] += c
            elif url_is_common_asset(u):
                occurrences[COMMON_ASSET]['distinct'] += 1
                occurrences[COMMON_ASSET]['total'] += c
            elif url_is_old_project(u):
                occurrences[OLD_PROJECT]['distinct'] += 1
                occurrences[OLD_PROJECT]['total'] += c
            elif url_is_false_negative(u):
                occurrences[FALSE_NEGATIVE]['distinct'] += 1
                occurrences[FALSE_NEGATIVE]['total'] += c
            else:
                occurrences[SUSPICIOUS]['distinct'] += 1
                occurrences[SUSPICIOUS]['total'] += c

    stats['less_than_10'] = occurrences

    return stats
333443
def get_project_filenames(self):
        """"""
        recent_files = []
        if self.current_active_project:
            recent_files = self.current_active_project.get_recent_files()
        elif self.latest_project:
            recent_files = self.latest_project.get_recent_files()
        return recent_files
911560
def get_potential_files(self, ignore_list):
        
        exclude_prefix = self.taskid == tasks.suffixes.get(tasks.REALS_TASK, '') and 'fk' or None
        filenames = [filename for filename in
                     self.directory_context.get_listing(self.taskid, exclude_prefix=exclude_prefix)
                     if filename not in ignore_list and
                     filename not in self._done and
                     filename not in self._already_fetched]

        # if the extension is .mpc. then we look for the largest numbered MPC file.
        # look for the largest numbered MPC file only.
        if self.taskid == tasks.suffixes.get(tasks.TRACK_TASK, ''):
            basenames = {}
            for filename in filenames:
                fullname = os.path.splitext(filename)[0]
                if fullname in basenames:
                    continue
                basename = os.path.splitext(fullname)[0]
                # only do the 'maximum' search when the 2nd extension is an integer value
                try:
                    idx = int(filename.split('.')[-2])
                    if idx > basenames.get(basename, 0):
                        basenames[basename] = idx
                except:
                    # since we failed, just keep the file in the list
                    basenames[fullname] = ''
            filenames = []
            for basename in basenames:
                # sometimes the version is empty, so no '.' is needed
                version = basenames[basename]
                version = len(str(version)) > 0 and ".{}".format(version) or version
                filenames.append("{}{}{}".format(basename, version, self.taskid))
                # print basename, basenames[basename], filenames[-1]
        return filenames
973665
def _get_data_files(self):
        
        files = super()._get_data_files()
        # We don’t really want to duplicate logic used in the original
        # implementation, but we can back out what it did with commonpath -
        # should be something ending in opentrons
        build_base = os.path.commonpath([f[2] for f in files])
        # We want a list of paths to only files relative to ../shared-data
        to_include = get_shared_data_files()
        destination = os.path.join(build_base, DEST_BASE_PATH)
        # And finally, tell the system about our files
        files.append(('opentrons', SHARED_DATA_PATH,
                      destination, to_include))
        return files
1208650
def get_last_upload_results(self):
        
        if os.path.isfile(constants.last_upload_results_file):
            logger.debug('Last upload file %s found, reading results.', constants.last_upload_results_file)
            with open(constants.last_upload_results_file, 'r') as handler:
                return handler.read()
        else:
            logger.debug('Last upload file %s not found, cannot read results', constants.last_upload_results_file)
            return False
216369
def get_file_list(self):
        
        if os.path.isdir(self.root_path):
            return [os.path.join(self.root_path, f) for f in os.listdir(self.root_path)
                    if os.path.isfile(os.path.join(self.root_path, f))]
        else:
            return [self.root_path]
739526
def _get_next_files(self):
        
        fnlist = self.__files[:16]
        self.__files = self.__files[16:]
        return fnlist
48116
def list_files(self):
        
        output = []
        tmp = {}

        files = self.aserver_api.package(self.username, self.notebook)['files']

        for f in files:
            if f['basename'] in tmp:
                tmp[f['basename']].append(f)
            else:
                tmp[f['basename']] = [f]

        for basename, versions in tmp.items():
            try:
                output.append(max(versions, key=lambda x: int(x['version'])))
            except ValueError:
                output.append(
                    max(versions, key=lambda x: mktime(parse(x['upload_time']).timetuple()))
                )
            except:
                output.append(versions[-1])

        return output