コード例 #1
0
    def add_file(self, filepath):
        """ Add the given file to the archive.

        :param filepath: The file to add.
        """
        archive_path = path.make_path(os.path.basename(os.path.dirname(filepath)), os.path.basename(filepath))
        self.archive_file.add(filepath, arcname=archive_path)
コード例 #2
0
ファイル: mdepparse.py プロジェクト: adamcobabe/mrv
	def addFromFiles( self, mafiles, parse_all_paths = False,
					to_os_path = lambda f: make_path(f).expandvars(),
					os_path_to_db_key = lambda f: f):
		"""Parse the dependencies from the given maya ascii files and add them to
		this graph
		
		:note: the more files are given, the more efficient the method can be
		:param parse_all_paths: if True, default False, all paths found in the file will be used.
			This will slow down the parsing as the whole file will be searched for references
			instead of just the header of the file
		:param to_os_path: functor returning an MA file from given posssibly parsed file
			that should be existing on the system parsing the files.
			The passed in file could also be an mb file ( which cannot be parsed ), thus it
			would be advantageous to return a corresponding ma file
			This is required as references can have environment variables inside of them
		:param os_path_to_db_key: converts the given path as used in the filesystem into
			a path to be used as key in the database. It should be general.
			Ideally, os_path_to_db_key is the inverse as to_os_path.
		:note: if the parsed path contain environment variables you must start the
			tool such that these can be resolved by the system. Otherwise files might
			not be found
		:todo: parse_all_paths still to be implemented"""
		files_parsed = set()					 # assure we do not duplicate work
		for mafile in mafiles:
			depfiles = [ mafile.strip() ]
			while depfiles:
				curfile = to_os_path( depfiles.pop() )

				# ASSURE MA FILE
				if os.path.splitext( curfile )[1] != ".ma":
					log.info( "Skipped non-ma file: %s" % curfile )
					continue
				# END assure ma file

				if curfile in files_parsed:
					continue

				curfiledepends = self._parseDepends( curfile, parse_all_paths )
				files_parsed.add( curfile )

				# create edges
				curfilestr = str( curfile )
				valid_depends = list()
				for depfile in curfiledepends:
					print depfile
					# only valid files may be adjusted - we keep them as is otherwise
					dbdepfile = to_os_path( depfile )
					print dbdepfile
					if os.path.exists( dbdepfile ):
						valid_depends.append( depfile )				# store the orig path - it will be converted later
						dbdepfile = os_path_to_db_key( dbdepfile )		# make it db key path
					else:
						dbdepfile = depfile								# invalid - revert it
						self._addInvalid( depfile )						# store it as invalid, no further processing

					self.add_edge( dbdepfile, os_path_to_db_key( curfilestr ) )

				# add to stack and go on
				depfiles.extend( valid_depends )
コード例 #3
0
    def add_file(self, filepath):
        """ Add the given file to the archive.

        :param filepath: The file to add.
        """
        archive_path = path.make_path(
            os.path.basename(os.path.dirname(filepath)),
            os.path.basename(filepath))
        self.archive_file.add(filepath, arcname=archive_path)
コード例 #4
0
    def _dump_windows():
        if not path.is_directory(path.make_path('C:/', 'Program Files', 'Hobart', 'Bin')):
            raise OSError('Serial flash not found and cannot be read!')

        dump_filepath = 'C:/Program Files/Hobart/Bin/manufacturing_dump.bin'

        # arguments = ('C:/Program Files/Hobart/Bin/SPIFlashTest.exe', 'd', '100000', dump_filepath)
        # shell_command(arguments)

        return dump_filepath
コード例 #5
0
ファイル: file.py プロジェクト: teliduxing004/PythonUtilities
def list_files(filepath):
    """ List only files under the given directory (Generator expression).

    :param filepath: The path to list.
    :raise InvalidDirectoryError: IF the path given is not a directory.
    """
    filenames = list_directory(filepath)

    for file_name in filenames:
        full_path = path.make_path(filepath, file_name)
        if path.is_file(full_path):
            yield full_path
コード例 #6
0
ファイル: file.py プロジェクト: TheKewlStore/PythonUtilities
def list_files(filepath):
    """ List only files under the given directory (Generator expression).

    :param filepath: The path to list.
    :raise InvalidDirectoryError: IF the path given is not a directory.
    """
    filenames = list_directory(filepath)

    for file_name in filenames:
        full_path = path.make_path(filepath, file_name)
        if path.is_file(full_path):
            yield full_path
コード例 #7
0
ファイル: util.py プロジェクト: mrv-developers/mrv
def list_submodules(path):
    """
    :return: set(submodule_name, ...) list of submodule names that could 
        be imported using __import__
    :param path: module path containing the submodules"""
    file_package = make_path(path).dirname()
    # convert it to a string, unicode ( on windows ) is not handled by the __import__
    # statement
    cut_ext = lambda f: str(os.path.splitext(os.path.basename(f))[0])
    modules = set()
    for glob in ("*.py", "*.pyc"):
        modules.update(set(map(cut_ext, file_package.files(glob))))
    # END for each filetype to import
    return modules
コード例 #8
0
ファイル: file.py プロジェクト: teliduxing004/PythonUtilities
def find_hobart_database(directory):
    """ Find a hobart compatible database in the given directory, if one exists.

    :param directory: The directory to search for a database in.
    :raise NoDatabaseError: If no hobart compatible database is found.
    :raise InvalidDirectoryError: If the directory specified does not exist.
    :return: The path to the database found.
    """
    if not path.is_directory(directory):
        raise exceptions.InvalidDirectoryError(directory)

    hobart_database_name = 'dbft?.db'
    hobart_glob = path.make_path(directory, hobart_database_name)
    results = glob.glob(hobart_glob)

    if not results or not len(results):
        raise exceptions.NoDatabaseError(directory)

    return results[-1]
コード例 #9
0
ファイル: file.py プロジェクト: TheKewlStore/PythonUtilities
def find_hobart_database(directory):
    """ Find a hobart compatible database in the given directory, if one exists.

    :param directory: The directory to search for a database in.
    :raise NoDatabaseError: If no hobart compatible database is found.
    :raise InvalidDirectoryError: If the directory specified does not exist.
    :return: The path to the database found.
    """
    if not path.is_directory(directory):
        raise exceptions.InvalidDirectoryError(directory)

    hobart_database_name = 'dbft?.db'
    hobart_glob = path.make_path(directory, hobart_database_name)
    results = glob.glob(hobart_glob)

    if not results or not len(results):
        raise exceptions.NoDatabaseError(directory)

    return results[-1]
コード例 #10
0
    def __init__(self, *args, start=(30.28, 59.91), finish=(30.34, 59.97), n_points=3, charge=0.6, **kwargs):
        super(ScooterAgent, self).__init__(*args, **kwargs)

        self._api = LedgerApi('127.0.0.1', 8100)
        self._entity = Entity()

        self.speed = 0.0005


        self._api.sync(self._api.tokens.wealth(self._entity, 5000000))
        self._address = Address(self._entity)

        with open("../02_full_contract.etch", "r") as fb:
            self._source = fb.read()

        # Create contract
        self._contract = SmartContract(self._source)

        # Deploy contract
        self._api.sync(self._api.contracts.create(self._entity, self._contract, 2456766))


        with open('contract.txt','r') as ff:
            self.digest = ff.readline().split('\n')[0]
            self.owner = ff.readline()

        self._loop = asyncio.get_event_loop()

        self.provider = Entity()
        self.scooter = Entity()

        self.path = make_path(start, finish, n_points, 0.01)
        self.charge = charge

        self._contract.action(self._api, 'addProvider', 2456, [self._entity, self.provider],
                              Address(self.provider), self._address)

        self._contract.action(self._api, 'addScooter', 2456, [self.provider], Address(self.scooter),
                              Address(self.provider), int(start[1]*1000), int(start[0]*1000), 100, 1, 15)
コード例 #11
0
ファイル: file.py プロジェクト: teliduxing004/PythonUtilities
def hobart_directory():
    if windows_platform():
        return make_path('C:', 'Program Files', 'Hobart')
    else:
        return make_path('usr', 'local', 'hobart')
コード例 #12
0
ファイル: file.py プロジェクト: TheKewlStore/PythonUtilities
def hobart_directory():
    if windows_platform():
        return make_path('C:', 'Program Files', 'Hobart')
    else:
        return make_path('usr', 'local', 'hobart')
コード例 #13
0
    def _dump_linux():
        if not path.is_directory(path.make_path('/', 'dev', 'mtd3block3')):
            raise OSError('Serial flash not found and cannot be read!')

        return path.make_path('/', 'dev', 'mtd3')
コード例 #14
0
ファイル: mdepparse.py プロジェクト: kthulhu/mrv
    def addFromFiles(self,
                     mafiles,
                     parse_all_paths=False,
                     to_os_path=lambda f: make_path(f).expandvars(),
                     os_path_to_db_key=lambda f: f):
        """Parse the dependencies from the given maya ascii files and add them to
		this graph
		
		:note: the more files are given, the more efficient the method can be
		:param parse_all_paths: if True, default False, all paths found in the file will be used.
			This will slow down the parsing as the whole file will be searched for references
			instead of just the header of the file
		:param to_os_path: functor returning an MA file from given posssibly parsed file
			that should be existing on the system parsing the files.
			The passed in file could also be an mb file ( which cannot be parsed ), thus it
			would be advantageous to return a corresponding ma file
			This is required as references can have environment variables inside of them
		:param os_path_to_db_key: converts the given path as used in the filesystem into
			a path to be used as key in the database. It should be general.
			Ideally, os_path_to_db_key is the inverse as to_os_path.
		:note: if the parsed path contain environment variables you must start the
			tool such that these can be resolved by the system. Otherwise files might
			not be found
		:todo: parse_all_paths still to be implemented"""
        files_parsed = set()  # assure we do not duplicate work
        for mafile in mafiles:
            depfiles = [mafile.strip()]
            while depfiles:
                curfile = to_os_path(depfiles.pop())

                # ASSURE MA FILE
                if os.path.splitext(curfile)[1] != ".ma":
                    log.info("Skipped non-ma file: %s" % curfile)
                    continue
                # END assure ma file

                if curfile in files_parsed:
                    continue

                curfiledepends = self._parseDepends(curfile, parse_all_paths)
                files_parsed.add(curfile)

                # create edges
                curfilestr = str(curfile)
                valid_depends = list()
                for depfile in curfiledepends:
                    print depfile
                    # only valid files may be adjusted - we keep them as is otherwise
                    dbdepfile = to_os_path(depfile)
                    print dbdepfile
                    if os.path.exists(dbdepfile):
                        valid_depends.append(
                            depfile
                        )  # store the orig path - it will be converted later
                        dbdepfile = os_path_to_db_key(
                            dbdepfile)  # make it db key path
                    else:
                        dbdepfile = depfile  # invalid - revert it
                        self._addInvalid(
                            depfile
                        )  # store it as invalid, no further processing

                    self.add_edge(dbdepfile, os_path_to_db_key(curfilestr))

                # add to stack and go on
                depfiles.extend(valid_depends)
コード例 #15
0
ファイル: util.py プロジェクト: mrv-developers/mrv
def list_subpackages(path):
    """:return: list of sub-package names""" 
    return [str(p.basename()) for p in make_path(path).dirname().dirs() if p.files("__init__.py?")]