from __future__ import print_functionimport os # Load the library module# Script Name : script_count.py# Author : Craig Richards# Created : 27th February 2012# Last Modified : 20th July 2012# Version : 1.3# Modifications : 1.1 - 28-02-2012 - CR - Changed inside github and development functions, so instead of if os.name = "posix" do this else do this etc# : I used os.path.join, so it condensed 4 lines down to 1# : 1.2 - 10-05-2012 - CR - Added a line to include PHP scripts.# : 1.3 - 20-07-2012 - CR - Added the line to include Batch scripts# Description : This scans my scripts directory and gives a count of the different types of scriptspath = os.getenv("scripts") # Set the variable path by getting the value from the OS environment variable scriptsdropbox = os.getenv("dropbox") # Set the variable dropbox by getting the value from the OS environment variable dropboxdef clear_screen(): # Function to clear the screenif os.name == "posix": # Unix/Linux/MacOS/BSD/etcos.system('clear') # Clear the Screenelif os.name in ("nt", "dos", "ce"): # DOS/Windowsos.system('CLS') # Clear the Screendef count_files(path,extensions): # Start of the function to count the files in the scripts directory, it counts the extension when passed belowcounter = 0 # Set the counter to 0for root, dirs, files in os.walk(path): # Loop through all the directories in the given pathfor file in files: # For all the filescounter += file.endswith(extensions) # Count the filesreturn counter # Return the countdef github(): # Start of the function just to count the files in the github directorygithub_dir = os.path.join(dropbox, 'github') # Joins the paths to get the github directory - 1.1github_count = sum((len(f) for _, _, f in os.walk(github_dir))) # Get a count for all the files in the directoryif github_count > 5: # If the number of files is greater then 5, then print the following messagesprint('\nYou have too many in here, start uploading !!!!!')print('You have: ' + str(github_count) + ' waiting to be uploaded to github!!')elif github_count == 0: # Unless the count is 0, then print the following messagesprint('\nGithub directory is all Clear')else: # If it is any other number then print the following message, showing the number outstanding.print('\nYou have: ' + str(github_count) + ' waiting to be uploaded to github!!')def development(): # Start of the function just to count the files in the development directorydev_dir = os.path.join(path, 'development') # Joins the paths to get the development directory - 1.1dev_count = sum((len(f) for _, _, f in os.walk(dev_dir))) # Get a count for all the files in the directoryif dev_count > 10: # If the number of files is greater then 10, then print the following messagesprint('\nYou have too many in here, finish them or delete them !!!!!')print('You have: ' + str(dev_count) + ' waiting to be finished!!')elif dev_count == 0: # Unless the count is 0, then print the following messagesprint('\nDevelopment directory is all clear')else:print('\nYou have: ' + str(dev_count) + ' waiting to be finished!!') # If it is any other number then print the following message, showing the number outstanding.clear_screen() # Call the function to clear the screenprint('\nYou have the following :\n')print('AutoIT:\t' + str(count_files(path, '.au3'))) # Run the count_files function to count the files with the extension we passprint('Batch:\t' + str(count_files(path, ('.bat', ',cmd')))) # 1.3print('Perl:\t' + str(count_files(path, '.pl')))print('PHP:\t' + str(count_files(path, '.php'))) # 1.2print('Python:\t' + str(count_files(path, '.py')))print('Shell:\t' + str(count_files(path, ('.ksh', '.sh', '.bash'))))print('SQL:\t' + str(count_files(path, '.sql')))github() # Call the github functiondevelopment() # Call the development function
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。