當前位置: 首頁>>代碼示例>>Python>>正文


Python FileManager.FileManager類代碼示例

本文整理匯總了Python中FileManager.FileManager的典型用法代碼示例。如果您正苦於以下問題:Python FileManager類的具體用法?Python FileManager怎麽用?Python FileManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了FileManager類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: manager

 def manager(self,rule, ruledef):
     from MatchManager import Matching
     from SearchManager import SearchManager
     from Trigger import Trigger
     from FileManager import FileManager
        
     Matching = Matching(rule, ruledef)
     Trigger = Trigger()
     FileManager = FileManager()
        
     log_location = self.log_check(rule)
     log = FileManager.read_logfile(log_location)
     logfile = log
     endPoint = len(logfile)
     
     while True:
         if endPoint > self.startAt:     
             Searching = SearchManager(Matching.matchlist, rule, logfile)
             Trigger.perform_action(Searching.action, rule)
         
         print 'start at begin: ' ,  self.startAt
         self.startAt = endPoint
         print 'startat = ', self.startAt
         print 'endpoint = ', endPoint
         interval = self.interval_check(rule)
         print 'Sleeping for ' + str(interval) + ' seconds'
         time.sleep(interval)
         print 'Searching in the new rule file'
         
         log_location = self.log_check(rule)
         log = FileManager.read_logfile(log_location)
         del logfile[:]
         for line in range (self.startAt, len(log)):
             logfile.append(log[line])
         endPoint = len(log)
開發者ID:Christiaand,項目名稱:SecurityMonitor_Chris,代碼行數:35,代碼來源:Monitor.py

示例2: VerifyEmail

 def VerifyEmail(self, string):
     fm = FileManager()
     match = re.match(r'\b[\w.-][email protected][\w.-]+.\w{2,4}\b', string)
     if match and fm.isUnique(string,2):
         return True
     else:
         return False
開發者ID:Alejandro-Frech,項目名稱:PythonClientServer,代碼行數:7,代碼來源:Validations.py

示例3: take_photo

def take_photo():
    file_settings = FileSettings()

    logging.basicConfig(
        filename=file_settings.log_file(),
        format='%(asctime)s %(levelname)s: %(message)s',
        level=logging.INFO)
    logging.debug('Starting take_photo')
    try:
        logging.debug('Creating FileManager')
        file_mgr = FileManager(file_settings.project_dir)
        logging.debug('Getting file path')
        file_name_path = file_mgr.get_file_path()
        logging.debug('Photo file path name: %s', file_name_path)
    except:
        # Got an error trying to create the directory.
        # NEXT file_name_path isn't set on an exception.  What exception
        #      message is raised?  Print that?  Yes, need to debug the error.
        # NEXT Create a unit (or behavioral test) to check this logic - does
        #      it need to be put into a separate module?
        logging.error('Failed to create: %s', os.path.dirname(file_name_path))
        return

    logging.info('Taking photo with file path: %s', file_name_path)

    camera_settings = CameraSettings()
    # Camera is mounted upside down in the weatherproof housing
    # Need to rotate 180 degrees so photo is right side up
    camera_settings.rotation = 180

    take_and_save_photo(camera_settings, file_name_path)
開發者ID:tomhotch,項目名稱:timelapse,代碼行數:31,代碼來源:take_photo.py

示例4: build

	def build(self):
		fileManager = FileManager()
		
		cities = [dir for dir in os.listdir(self.source) if os.path.isdir(os.path.join(self.source, dir))]
		for city in cities:
			city_path = os.path.join(self.source, city)
			self.logger.info("%s ..."% city)
			files = [os.path.splitext(os.path.normcase(file))[0] for file in os.listdir(city_path) if os.path.splitext(file)[1] == '.json']
			for file in files:
				json_file = os.path.join(city_path, "%s.json"% file)
				geojson_file = os.path.join(city_path, "%s.geojson"% file)
				js_geojson_file = os.path.join(city_path, "%s.js"% file)
				self.logger.info("%s.json"% file)
				if not os.path.isfile(geojson_file) or not os.path.isfile(js_geojson_file):
					f = open(json_file, 'r')
					loaded_json = json.load(f)
					f.close()
					
					loaded_geojson = self.builder.build_geojson(loaded_json)

					fileManager.write_geojson(loaded_geojson, self.source, city, file)
					self.logger.info(" => %s.geojson"% file)
					
					fileManager.write_js_geojson(loaded_geojson, self.source, city, file)
					self.logger.info(" => %s.js"% file)
開發者ID:ComplexCity,項目名稱:capture,代碼行數:25,代碼來源:GeojsonBuilding.py

示例5: test_get_datetime

 def test_get_datetime(self):
     f = FileManager()
     year, month, day, hour, minute, second = f._get_datetime()
     # TODO: Should I mock the python now function to test for specific
     # values?
     # Checks that the year is between 2016 and 2099.  2099 is somewhat
     # arbitrary - the test will work for many years ... probably more
     # than is necessary.
     self.assertIn(
         year, range(2016, 2100),
         "FileManger get_datetime returns a valid year")
     self.assertIn(
         month, range(1, 13),
         "FileManger get_datetime returns a valid month")
     self.assertIn(
         day, range(1, 32),
         "FileManger get_datetime returns a valid day")
     self.assertIn(
         hour, range(1, 25),
         "FileManger get_datetime returns a valid hour")
     self.assertIn(
         minute, range(0, 60),
         "FileManger get_datetime returns a valid minute")
     self.assertIn(
         second, range(0, 60),
         "FileManger get_datetime returns a valid second")
開發者ID:tomhotch,項目名稱:timelapse,代碼行數:26,代碼來源:test_FileManager.py

示例6: VerifyCedula

 def VerifyCedula(self, string):
     match = re.match(r'\d{4}-\d{4}-\d{5}', string)
     fm = FileManager()
     if match and  fm.isUnique(string,3):
         return  True
     else:
         return  False
開發者ID:Alejandro-Frech,項目名稱:PythonClientServer,代碼行數:7,代碼來源:Validations.py

示例7: Monitor

 def Monitor(self):
     from FileManager import FileManager
     FileManager = FileManager()
     rules = FileManager.get_rules()
     ruledef = FileManager.get_ruledef()
             
     for rule in range (len(rules)):
         print rules[rule]
         thread = Thread( target=self.manager, args=(rules[rule], ruledef))
         thread.start() 
開發者ID:Christiaand,項目名稱:SecurityMonitor_Chris,代碼行數:10,代碼來源:Monitor.py

示例8: negativeFeaturesSingleCat

	def negativeFeaturesSingleCat(self,category):
		## PREPROCESSING PERCORSI IMMAGINI
		fm = FileManager()

		X_negative = []
		#for i in range(0,len(listDir)):
		file_negative = self.root+category+"/"+category+"_" + self.detector + "_" + self.extractor + ".csv"
		if not os.path.isfile(file_negative):
			self.creaFileFeatures(category)
		else:
			X = fm.csvToArray(file_negative)
			X_negative = X_negative + X
		return X_negative		
開發者ID:massi92,項目名稱:DIP-Project_MGFF,代碼行數:13,代碼來源:FeaturesFile.py

示例9: loadResources

 def loadResources(self):
     loader = AssetLoader('images')
     if BossEnemy.walking_images[Enemy.INDEX_DOWN] is None:
         path = os.path.join(
             BossEnemy.WALKING_PATH, BossEnemy.WALKING_DOWN_PATH)
         prefix_path = os.path.join(
             BossEnemy.PREFIX_PATH, BossEnemy.WALKING_DOWN_PATH)
         fM = FileManager(path, file_ext='.png', create_dir=False)
         BossEnemy.walking_images[Enemy.INDEX_DOWN] = \
             loader.load_images(fM.get_files(prefix_path=prefix_path))
     if BossEnemy.walking_images[Enemy.INDEX_UP] is None:
         path = os.path.join(
             BossEnemy.WALKING_PATH, BossEnemy.WALKING_UP_PATH)
         prefix_path = os.path.join(
             BossEnemy.PREFIX_PATH, BossEnemy.WALKING_UP_PATH)
         fM = FileManager(path, file_ext='.png', create_dir=False)
         BossEnemy.walking_images[Enemy.INDEX_UP] = \
             loader.load_images(fM.get_files(prefix_path=prefix_path))
     if BossEnemy.walking_images[Enemy.INDEX_LEFT] is None:
         path = os.path.join(
             BossEnemy.WALKING_PATH, BossEnemy.WALKING_LEFT_PATH)
         prefix_path = os.path.join(
             BossEnemy.PREFIX_PATH, BossEnemy.WALKING_LEFT_PATH)
         fM = FileManager(path, file_ext='.png', create_dir=False)
         BossEnemy.walking_images[Enemy.INDEX_LEFT] = \
             loader.load_images(fM.get_files(prefix_path=prefix_path))
     if BossEnemy.walking_images[Enemy.INDEX_RIGHT] is None:
         path = os.path.join(
             BossEnemy.WALKING_PATH, BossEnemy.WALKING_RIGHT_PATH)
         prefix_path = os.path.join(
             BossEnemy.PREFIX_PATH, BossEnemy.WALKING_RIGHT_PATH)
         fM = FileManager(path, file_ext='.png', create_dir=False)
         BossEnemy.walking_images[Enemy.INDEX_RIGHT] = \
             loader.load_images(fM.get_files(prefix_path=prefix_path))
開發者ID:elanas,項目名稱:TheCrazySix,代碼行數:34,代碼來源:BossEnemy.py

示例10: main

def main():
	captor = AqiCaptor(logger)
	file_manager = FileManager()

	try:
		try:
			locations = file_manager.get_locations(source)
		except IOError:
			raise InitError("File %s is missing"% file_manager.get_locations_path(source))
		except ValueError:
			raise InitError("The %s file does not contain any correct JSON object"% file_manager.get_locations_path(source))
			
		for city, location in locations.iteritems():
			logger.warning("- Capting for %s"% city)
			my_date = datetime.now().strftime('%y-%m-%d-%H')
			loaded_json = captor.get_data(location)
			try:
				file_manager.write_json(loaded_json, source, city, my_date)
			except IOError:
				raise InitError("Folder %s is missing"% file_manager.get_folder_path(source, city))
		
		return 0

	except InitError as e:
		logger.critical("%s: %s"% (type(e).__name__, e))
		return 1
	except requests.exceptions.RequestException as e:
		logger.critical("%s: %s"% (type(e).__name__, e))
		return 2
	except Exception as e:
		logger.critical(e, exc_info=True)
		return 3
開發者ID:ComplexCity,項目名稱:capture,代碼行數:32,代碼來源:AqiCapture.py

示例11: featuresCategories

	def featuresCategories(self):
		#recupera tutte le categorie, senza distinzione fra positive e negative
		#usando un numero incrementale per l'assegnazione delle categorie
		fm = FileManager()
		X_train = []
		y_train = []
		assoc = dict()
		listCategories = fm.listNoHiddenDir(self.root)
		index = 1
		for cat in listCategories:
			file_positive = self.root+cat+"/"+cat+"_" + self.detector + "_" + self.extractor + ".csv"
			X_cat = fm.csvToArray(file_positive)
			X_train = X_train + X_cat
			y_train = y_train + [index]*len(X_cat)
			assoc[cat] = index
			index = index + 1

		return X_train,y_train,assoc
開發者ID:massi92,項目名稱:DIP-Project_MGFF,代碼行數:18,代碼來源:FeaturesFile.py

示例12: read_all_values_to_rotate

 def read_all_values_to_rotate(self):
     """
     This method read all the data required by the final user to rotate an image
     Return:
     input_values.- List with all the inputs inserted by the user
                    [Image path,  degrees, New name of the image]
                    If some value inserted is invalid, the method returns a empty list
     """
     file_manager = FileManager()
     input_values = []
     image_path = self.read_image_path()
     if (file_manager.validate_type_of_image(image_path) == True):
         degrees = self.read_degrees_to_rotate_image()
         if (degrees != 9999):
             new_image_name = self.read_name_to_save_image_rotate()
             input_values = [image_path, degrees, new_image_name]
             return input_values
         else:
             return input_values
     else:
         return input_values
開發者ID:edson-gonzales,項目名稱:PymageC,代碼行數:21,代碼來源:PymageMain.py

示例13: test_get_file_path

    def test_get_file_path(self):

        # Successful cases
        root_dir = os.path.join("temp")
        try:
            f = FileManager(root_dir)
            file_path = f.get_file_path()

            # TODO: The regex path check is unix specific.  Is there
            # a way to have a regexp check for os path separator?
            path, basename = os.path.split(file_path)
            self.assertRegexpMatches(
                path, "\d\d\d\d/\d\d/\d\d", "Verify path format is yyyy/mm/dd")

            self.assertRegexpMatches(
                basename, "\d\d\d\d-\d\d-\d\d_\d\d-\d\d-\d\d.jpg",
                "Verify file name format is year-month-day_hour-minute-second.jpg")

        finally:
            # Clean up - remove directories created just for this test
            os.removedirs(os.path.dirname(file_path))
            self.assertFalse(
                os.path.isdir(root_dir),
                "Verify test directory does not exist after clean up")

        # Error Cases
        # Create a directory that can't be written to
        unwritable_dir = "unwritable"
        TEST_UMASK = 0o222
        orig_umask = os.umask(TEST_UMASK)
        os.makedirs(unwritable_dir)

        try:
            # Make sure we get an exception if creating the directory fails
            f = FileManager(unwritable_dir)
            self.assertRaises(OSError, f.get_file_path )

        finally:
            os.umask(orig_umask)
            os.removedirs(unwritable_dir)
開發者ID:tomhotch,項目名稱:timelapse,代碼行數:40,代碼來源:test_FileManager.py

示例14: main

def main():
	try:
		logger.warning("Capting Archdaily...")
		
		now = datetime.now().strftime('%y-%m-%d')
		loaded_json = ArchdailyCaptor().get_data()
		
		logger.info("Building the GeoJSON...")
		loaded_geojson = ArchdailyGeojsonBuilder().build_geojson(loaded_json)
		
		logger.info("Writing GeoJSON...")
		file_manager = FileManager()
		try:
			file_manager.write_geojson(loaded_geojson, source, None, now)
			file_manager.write_js_geojson(loaded_geojson, source, None, now)
		except IOError:
			raise InitError("The folder %s is missing"% file_manager.get_folder_path(source))
		
		logger.warning("New GeoJSON written for Archdaily: %d locations"% len(loaded_json))
		return 0
	
	except InitError as e:
		logger.critical("%s: %s"% (type(e).__name__, e))
		return 1
	except requests.exceptions.RequestException as e:
		logger.critical(e, exc_info=True)
		return 2
	except Exception as e:
		logger.critical(e, exc_info=True)
		return 3
開發者ID:ComplexCity,項目名稱:capture,代碼行數:30,代碼來源:ArchdailyCapture.py

示例15: read_all_values_to_export_an_image_file_to_another_format

    def read_all_values_to_export_an_image_file_to_another_format(self):
        """
        This method read all the data required by the final user to export an image
        to another format.
        The formats that are supported by the application are: jpg, bmp and png

        Return: List with all the inputs inserted by the user
                [Image path,  new format]
                If some value inserted is invalid, the method returns a empty list
        """
        file_manager = FileManager()
        input_values = []
        image_path = self.read_image_path()
        if (file_manager.validate_type_of_image(image_path) == True):
            new_format = self.read_format_to_export_an_image()
            if (new_format != "Incorrect format"):
                input_values = [image_path, new_format]
                return input_values
            else:
                return input_values
        else:
            return input_values
開發者ID:edson-gonzales,項目名稱:PymageC,代碼行數:22,代碼來源:PymageMain.py


注:本文中的FileManager.FileManager類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。