def __init__(self, file_name, mode='r'): # random_number for temporary file name random_number = random.randint( 1152921504606846976, 18446744073709551615) # temporary file self.temp_file_path = os.path.join(persepolis_tmp, str(random_number)) # r = read mode , w = write mode , a = append mode self.mode = mode self.file_name = file_name # Creating a lock file # lock file prevents accessing a file simoltaneously # If mode is 'w' or 'a' (write or append) , all changes is saving in a temporary file and after closing, original file replaced by temporary file # If mode is 'r' (Read) , original file is copying in temp_file_path and # then content of temporary file is reading. self.lock_file = self.file_name + ".lock" while os.path.isfile(self.lock_file) == True: sleep(0.1) osCommands.touch(self.lock_file) if self.mode == "w": self.f = open(self.temp_file_path, "w") elif self.mode == "a": shutil.copy(str(self.file_name), str(self.temp_file_path)) self.f = open(self.temp_file_path, "a") else: shutil.copy(str(self.file_name), str(self.temp_file_path)) self.f = open(self.temp_file_path, "r")
def __init__(self, file_name, mode='r'): # random_number for temporary file name random_number = random.randint(1152921504606846976, 18446744073709551615) # temporary file self.temp_file_path = os.path.join(persepolis_tmp, str(random_number)) # r = read mode , w = write mode , a = append mode self.mode = mode self.file_name = file_name # Creating a lock file # lock file prevents accessing a file simoltaneously # If mode is 'w' or 'a' (write or append) , all changes is saving in a temporary file and after closing, original file replaced by temporary file # If mode is 'r' (Read) , original file is copying in temp_file_path and # then content of temporary file is reading. self.lock_file = self.file_name + ".lock" while os.path.isfile(self.lock_file) == True: sleep(0.1) osCommands.touch(self.lock_file) if self.mode == "w": self.f = open(self.temp_file_path, "w") elif self.mode == "a": shutil.copy(str(self.file_name), str(self.temp_file_path)) self.f = open(self.temp_file_path, "a") else: shutil.copy(str(self.file_name), str(self.temp_file_path)) self.f = open(self.temp_file_path, "r")
if len(plugin_list) != 0: # import PluginsDB from persepolis.scripts.data_base import PluginsDB # create an object for PluginsDB plugins_db = PluginsDB() # add plugin_list to plugins_table in plugins.db file. plugins_db.insertInPluginsTable(plugin_list) # Job is done! close connections. plugins_db.closeConnections() # notify that a link is added! plugin_ready = os.path.join(persepolis_tmp, 'persepolis-plugin-ready') osCommands.touch(plugin_ready) # start persepolis in system tray start_in_tray = True def main(): # if lock_file is existed , it means persepolis is still running! if lock_file_validation: # run mainwindow # set color_scheme and style # see palettes.py and setting.py persepolis_download_manager = PersepolisApplication(sys.argv)
# You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # from persepolis.scripts.useful_tools import determineConfigFolder from persepolis.scripts import osCommands import logging import os # config_folder config_folder = determineConfigFolder() # log file address log_file = os.path.join(str(config_folder), 'persepolisdm.log') if not (os.path.isfile(log_file)): osCommands.touch(log_file) # define logging object logObj = logging.getLogger("Persepolis") logObj.setLevel(logging.INFO) # create a file handler handler = logging.FileHandler(log_file) handler.setLevel(logging.INFO) # create a logging format formatter = logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s') handler.setFormatter(formatter) # add the handlers to the logger
# from persepolis.scripts.useful_tools import determineConfigFolder from persepolis.scripts import osCommands import logging import os # config_folder config_folder = determineConfigFolder() # log file address log_file = os.path.join(str(config_folder), 'persepolisdm.log') if not(os.path.isfile(log_file)): osCommands.touch(log_file) # define logging object logObj = logging.getLogger("Persepolis Download Manager") logObj.setLevel(logging.INFO) # create a file handler handler = logging.FileHandler(log_file) handler.setLevel(logging.INFO) # create a logging format formatter = logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s') handler.setFormatter(formatter) # add the handlers to the logger
persepolis_shutdown = os.path.join(persepolis_tmp, 'shutdown') # shutil.rmtree(persepolis_shutdown, ignore_errors=True, onerror=None) # creating folders for folder in [ config_folder, download_info_folder, persepolis_tmp, category_folder, queue_info_folder, persepolis_shutdown ]: osCommands.makeDirs(folder) # creating files for file in [ queues_list, download_list_file, download_list_file_active, single_downloads_list_file ]: osCommands.touch(file) # lock files perventing to access a file simultaneously # removing lock files in starting persepolis pattern_folder_list = [ config_folder, download_info_folder, category_folder, queue_info_folder ] for folder in pattern_folder_list: pattern = os.path.join(str(folder), '*.lock') for file in glob.glob(pattern): osCommands.remove(file) from persepolis.scripts import logger # refresh logs!
from persepolis.scripts.osCommands import touch import logging import os # config_folder config_folder = determineConfigFolder() # create a directory if it does not exist if not os.path.exists(config_folder): os.makedirs(config_folder) # log file address log_file = os.path.join(str(config_folder), 'persepolisdm.log') if not os.path.isfile(log_file): touch(log_file) # define logging object logObj = logging.getLogger("Persepolis") logObj.setLevel(logging.INFO) # create a file handler handler = logging.FileHandler(log_file) handler.setLevel(logging.INFO) # create a logging format formatter = logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s') handler.setFormatter(formatter) # add the handlers to the logger
if args.headers: add_link_dictionary['header'] = "".join(args.headers) if args.name: add_link_dictionary['out'] = "".join(args.name) # when flashgot calls persepolis then persepolis is creating a request file in /tmp folder . this file contains download informations # persepolis mainwindow checks /tmp for flashgot request file every 2 seconds ( see CheckFlashgot class in mainwindow.py ) # when requset received by CheckFlashgot, a popup window (AddLinkWindow) is coming up and window is getting additional download informations from user (port , proxy , ...) and download starts and request file deleted if ('link' in add_link_dictionary): # adding add_link_dictionary to persepolis-flashgot flashgot_file = os.path.join(persepolis_tmp, 'persepolis-flashgot') f = open(flashgot_file, "a") f.writelines(str(add_link_dictionary) + '\n') f.close() flashgot_ready = os.path.join(persepolis_tmp, 'persepolis-flashgot-ready') osCommands.touch(flashgot_ready) def main(): if lock_file_validation: # if lock_file is existed , it means persepolis is still running! # setting color_scheme and style # see palettes.py and setting.py persepolis_download_manager = PersepolisApplication(sys.argv) # setting organization name and domain and apllication name QCoreApplication.setOrganizationName('persepolis_download_manager') QCoreApplication.setApplicationName('persepolis') # Persepolis setting persepolis_download_manager.setting = QSettings()