def rmtree(path, ignore_errors=False, onerror=None): ''' shutil.rmtree often fails with access denied. On Windows this happens when a file is readonly. On Linux this can happen when a directory doesn't have the appropriate permissions (Ex: chmod 200) and many other cases. ''' def force_removal(func, path, excinfo): ''' This is the only way to ensure that readonly files are deleted by rmtree on Windows. See: http://bugs.python.org/issue19643 ''' # Due to the way 'onerror' is implemented in shutil.rmtree, errors # encountered while listing directories cannot be recovered from. So if # a directory cannot be listed, shutil.rmtree assumes that it is empty # and it tries to call os.remove() on it which fails. This is just one # way in which this can fail, so for robustness we just call 'rm' if we # get an OSError while trying to remove a specific path. # See: http://bugs.python.org/issue8523 try: os.chmod(path, stat.S_IWRITE) func(path) except OSError: shell_call('rm -rf ' + path) # We try to not use `rm` because on Windows because it's about 20-30x slower if not onerror: shutil_rmtree(path, ignore_errors, onerror=force_removal) else: shutil_rmtree(path, ignore_errors, onerror)
def test_init(self): cvs: ControlVersionSystem = ControlVersionSystem(['init', '123']) self.assertEqual("Initialized Edu-cvs repository in " + os_getcwd(), cvs.process_cvs_command()) shutil_rmtree(cvs._changes_codec._CVS_DIR_PATH)
def test_jqpc_simple_pie_chart__not_absolute_source_path_expect_failure(): """ Tests: test_jqpc_simple_pie_chart__not_absolute_source_path_expect_failure """ print( '::: TEST: test_jqpc_simple_pie_chart__not_absolute_source_path_expect_failure()' ) scripts_pie_chart_path = 'scripts_pie_chart_test_jqpc_simple_pie_chart__not_absolute_source_path_expect_failure' if path_exists(scripts_pie_chart_path): shutil_rmtree(scripts_pie_chart_path) js_css_resources_header, jqplotchart_script, html_chart_insert_tag = jqpc_simple_pie_chart( absolute_source_dir_path=scripts_pie_chart_path, script_src_tag_dir_path=path_abspath(scripts_pie_chart_path), chart_id='example_id', class_str='', chart_title='JqPyCharts simple_pie_chart', chart_data_matrix=[('Fat', 200, '#EAA228', ''), ('Protein', 21, '#4bb2c5', ''), ('Carbohydrate', 10, '#c5b47f', '')], highlighter_prefix='', background='#fffdf6', legend_font_px=15, data_label_threshold=9.0, width_px=480, height_px=300, margin_top_px=0, margin_bottom_px=0, margin_right_px=0, margin_left_px=0) if path_exists(scripts_pie_chart_path): shutil_rmtree(scripts_pie_chart_path)
def test_jqpc_simple_bar_horizontal_chart_ok2(): """ Tests: test_jqpc_simple_bar_horizontal_chart_ok2 """ print('::: TEST: test_jqpc_simple_bar_horizontal_chart_ok2()') scripts_bar_chart_path = path_join(SCRIPT_PATH, 'scripts_bar_chart_test_jqpc_simple_bar_horizontal_chart_ok2') if path_exists(scripts_bar_chart_path): shutil_rmtree(scripts_bar_chart_path) js_css_resources_header, jqplotchart_script, html_chart_insert_tag = jqpc_simple_bar_chart( absolute_source_dir_path=scripts_bar_chart_path, script_src_tag_dir_path=path_relpath(scripts_bar_chart_path), chart_id='example_id', class_str='whatever', chart_title='JqPyCharts simple_bar_chart', chart_x_label='', chart_x_label_fontdict=None, chart_ticks_fontdict=None, chart_data_matrix=[ ('Fat', 200, '#EAA228', ''), ('Protein', 21, '#4bb2c5', ''), ('Carbohydrate', 10, '#c5b47f', '') ], highlighter_prefix='Gram', background='#fffdf6', horizontal=True, draw_grid_lines=False, width_px=550, height_px=300, margin_top_px=0, margin_bottom_px=0, margin_right_px=0, margin_left_px=0) for resource_name in [ 'jquery.min.js', 'jquery.jqplot.min.js', 'jqplot.canvasAxisLabelRenderer.min.js', 'jqplot.categoryAxisRenderer.min.js', 'jqplot.canvasTextRenderer.min.js', 'jqplot.barRenderer.min.js', 'jqplot.pointLabels.min.js', 'jquery.jqplot.min.css']: resource_dir_path__abspath = path_join(scripts_bar_chart_path, resource_name) resource_dir_path__relpath = path_relpath(resource_dir_path__abspath) if resource_dir_path__abspath[-2:] == 'js': check_line = '<script type="text/javascript" src="{}"></script>'.format(resource_dir_path__relpath) ok_(check_line in js_css_resources_header, msg=None) elif resource_dir_path__abspath[-3:] == 'css': check_line = '<link rel="stylesheet" type="text/css" href="{}">'.format(resource_dir_path__relpath) ok_(check_line in js_css_resources_header, msg=None) else: raise Err('test_jqpc_simple_bar_horizontal_chart_ok2', [ '`resource_name`: <{}> must end with <.js> or <.css>'.format(resource_name) ]) if path_exists(scripts_bar_chart_path): shutil_rmtree(scripts_bar_chart_path)
def test_jqpc_simple_bar_chart_ok2(): """ Tests: test_jqpc_simple_bar_chart_ok2 """ print('::: TEST: test_jqpc_simple_bar_chart_ok2()') scripts_bar_chart_path = path_join(SCRIPT_PATH, 'scripts_bar_chart_test_jqpc_simple_bar_chart_ok2') if path_exists(scripts_bar_chart_path): shutil_rmtree(scripts_bar_chart_path) js_css_resources_header, jqplotchart_script, html_chart_insert_tag = jqpc_simple_bar_chart( absolute_source_dir_path=scripts_bar_chart_path, script_src_tag_dir_path=path_relpath(scripts_bar_chart_path), chart_id='example_id', class_str='whatever', chart_title='JqPyCharts simple_bar_chart', chart_x_label='', chart_x_label_fontdict=None, chart_ticks_fontdict=None, chart_data_matrix=[ ('Fat', 200, '#EAA228', ''), ('Protein', 21, '#4bb2c5', ''), ('Carbohydrate', 10, '#c5b47f', '') ], highlighter_prefix='Gram', background='#fffdf6', horizontal=False, draw_grid_lines=False, width_px=550, height_px=300, margin_top_px=0, margin_bottom_px=0, margin_right_px=0, margin_left_px=0) for resource_name in [ 'jquery.min.js', 'jquery.jqplot.min.js', 'jqplot.canvasAxisLabelRenderer.min.js', 'jqplot.categoryAxisRenderer.min.js', 'jqplot.canvasTextRenderer.min.js', 'jqplot.barRenderer.min.js', 'jqplot.pointLabels.min.js', 'jquery.jqplot.min.css']: resource_dir_path__abspath = path_join(scripts_bar_chart_path, resource_name) resource_dir_path__relpath = path_relpath(resource_dir_path__abspath) if resource_dir_path__abspath[-2:] == 'js': check_line = '<script type="text/javascript" src="{}"></script>'.format(resource_dir_path__relpath) ok_(check_line in js_css_resources_header, msg=None) elif resource_dir_path__abspath[-3:] == 'css': check_line = '<link rel="stylesheet" type="text/css" href="{}">'.format(resource_dir_path__relpath) ok_(check_line in js_css_resources_header, msg=None) else: raise Err('test_jqpc_simple_bar_chart_ok2', [ '`resource_name`: <{}> must end with <.js> or <.css>'.format(resource_name) ]) if path_exists(scripts_bar_chart_path): shutil_rmtree(scripts_bar_chart_path)
def test_no_committed_dir(self): shutil_rmtree(self._changes_codec._CVS_DIR_PATH) with self.assertRaises(OSError) as occurred_err: self._changes_codec._get_last_commit_number() self.assertEqual(occurred_err.exception.args[0], 'Cannot scan "committed/" for last commit number')
def test_jqpc_simple_pie_chart__expect_failure1(): """ Tests: test_jqpc_simple_pie_chart__expect_failure1: chart_id with spaces """ print('::: TEST: test_jqpc_simple_pie_chart__expect_failure1()') scripts_pie_chart_path = path_join( SCRIPT_PATH, 'scripts_pie_chart_test_jqpc_simple_pie_chart__expect_failure1') if path_exists(scripts_pie_chart_path): shutil_rmtree(scripts_pie_chart_path) js_css_resources_header, jqplotchart_script, html_chart_insert_tag = jqpc_simple_pie_chart( absolute_source_dir_path=scripts_pie_chart_path, script_src_tag_dir_path=path_relpath(scripts_pie_chart_path), chart_id='example_id wrong can not have spaces', class_str='', chart_title='JqPyCharts simple_pie_chart', chart_data_matrix=[('Fat', 200, '#EAA228', 'Fat: 200 g'), ('Protein', 21, '#4bb2c5', None), ('Carbohydrate', 10, '#c5b47f', 'Carbohydrate: 10 g')], highlighter_prefix='', background='#fffdf6', legend_font_px=15, data_label_threshold=9.0, width_px=480, height_px=300, margin_top_px=0, margin_bottom_px=0, margin_right_px=0, margin_left_px=0) for resource_name in [ 'jquery.min.js', 'jquery.jqplot.min.js', 'jqplot.highlighter.min.js', 'jqplot.canvasTextRenderer.min.js', 'jqplot.pieRenderer.min.js', 'jquery.jqplot.min.css' ]: resource_dir_path__abspath = path_join(scripts_pie_chart_path, resource_name) resource_dir_path__relpath = path_relpath(resource_dir_path__abspath) if resource_dir_path__abspath[-2:] == 'js': check_line = '<script type="text/javascript" src="{}"></script>'.format( resource_dir_path__relpath) ok_(check_line in js_css_resources_header, msg=None) elif resource_dir_path__abspath[-3:] == 'css': check_line = '<link rel="stylesheet" type="text/css" href="{}">'.format( resource_dir_path__relpath) ok_(check_line in js_css_resources_header, msg=None) else: raise Err('test_jqpc_simple_pie_chart__expect_failure1', [ '`resource_name`: <{}> must end with <.js> or <.css>'.format( resource_name) ]) if path_exists(scripts_pie_chart_path): shutil_rmtree(scripts_pie_chart_path)
def test_no_edu_cvs_dir(self): shutil_rmtree(self._changes_codec._CVS_DIR_PATH) with self.assertRaises(CodecException) as exc_handle: self._changes_codec.cvs_add(_TEMP_PATH_1) self.assertEqual(exc_handle.exception.args, ('add: init repo first', )) self._changes_codec.cvs_init()
def adminServletDeleteUser(request, response, toDeleteUserID): """ This function... @param {Request} request, the request object @param {Response} response, the response object """ try: #**************************************************************** # Step 0.CHECK IF VALID USER SESSION #**************************************************************** logging.info("STEP0 - CHECK IF VALID USER....") userID = request.cookies.get('userID') sessionToken = request.cookies.get('sessionToken') userName = request.cookies.get('userName') UserSessionManager().isValidAdminUser(userID, userName, sessionToken) if toDeleteUserID == "0": response.setContent({"success": False}) else: jobDAOInstance = JobDAO() filesDAOInstance = FileDAO() userDAOInstance = UserDAO() logging.info("STEP1 - CLEANING DATA FOR " + toDeleteUserID + "...") #**************************************************************** # Step 1. DELETE ALL JOBS FOR THE USER #**************************************************************** allJobs = jobDAOInstance.findAll( otherParams={"userID": toDeleteUserID}) jobID = "" for jobInstance in allJobs: jobID = jobInstance.getJobID() logging.info("STEP2 - REMOVING " + jobID + " FROM DATABASE...") jobDAOInstance.remove(jobInstance.getJobID(), otherParams={"userID": toDeleteUserID}) #**************************************************************** # Step 3. DELETE ALL FILES FOR THE USER #**************************************************************** logging.info("STEP3 - REMOVING ALL FILES FROM DATABASE...") filesDAOInstance.removeAll(otherParams={"userID": toDeleteUserID}) logging.info("STEP3 - REMOVING ALL FILES FROM USER DIRECTORY...") if os_path.isdir(CLIENT_TMP_DIR + toDeleteUserID): shutil_rmtree(CLIENT_TMP_DIR + toDeleteUserID) #**************************************************************** # Step 4. DELETE THE USER INSTANCE FROM DATABASE #**************************************************************** logging.info("STEP6 - REMOVING ALL FILES FROM DATABASE...") userDAOInstance.remove(int(toDeleteUserID)) response.setContent({"success": True}) except Exception as ex: handleException(response, ex, __file__, "adminServletDeleteUser") finally: return response
def run(self): dump_logger = getLogger('dumpscraper') # Let's invoke the getscore runner and tell him to work on training data dump_logger.info("Calculating dump score...") running = getscore.DumpScraperGetscore(self.settings, self.parentArgs) running.run() # First of all let's feed the classifier with the training data training = scipy_genfromtxt(self.settings['data_dir'] + "/" + "training/features.csv", delimiter=",", skip_header=1, usecols=(0, 1, 2)) target = scipy_genfromtxt(self.settings['data_dir'] + "/" + "training/features.csv", delimiter=",", skip_header=1, usecols=(-2)) clf = sklearn.neighbors.KNeighborsClassifier(10, weights='uniform') clf.fit(training, target) trash_count = hash_count = plain_count = 0 cleared = [] with open(self.settings['data_dir'] + "/" + 'features.csv', 'rb') as csvfile: reader = csv_reader(csvfile) for line in reader: if line[0] == 'Trash score': continue features = np_array(line[0:3]) features = features.reshape(1, -1) label = clf.predict(features) if label == 0: folder = 'trash' trash_count += 1 elif label == 1: folder = 'hash' hash_count += 1 elif label == 2: folder = 'plain' plain_count += 1 target_file = self.settings['data_dir'] + "/" + 'organized/' + folder + "/" + line[-1] target_dir = path.dirname(target_file) # If asked for a clean run, let's delete the entire folder before copying any file if self.parentArgs.clean and target_dir not in cleared and path.exists(target_dir): cleared.append(target_dir) shutil_rmtree(target_dir) if not path.exists(target_dir): makedirs(target_dir) shutil_copyfile(self.settings['data_dir'] + "/" + 'raw/' + line[-1], target_file) dump_logger.info("Trash files: " + str(trash_count)) dump_logger.info("Hash files: " + str(hash_count)) dump_logger.info("Plain files: " + str(plain_count)) dump_logger.info("Operation completed")
def work(self): if os_path_exists(self.profilesDir): shutil_rmtree(self.profilesDir) os_makedirs(self.profilesDir) stuInfos = self.getStuInfo(self.infoPath) dates, stuDatas = self.getDatasFromDing(self.excelsDir, stuInfos) self.generateEveryoneProfile(self.profilesDir, stuInfos, dates, stuDatas) self._finished.emit()
def test_not_a_file(self): os_mkdir(_TEMP_PATH_1) cvs_add_result: Tuple[str, str] = self._changes_codec.cvs_add(_TEMP_PATH_1) self.assertEqual(cvs_add_result, ('not a file', _TEMP_PATH_1)) self.assertFalse(os_path_exists(self._changes_codec._STAGED_PATH)) shutil_rmtree(_TEMP_PATH_1)
def test_jqpc_write__resource_dict__expect_failure1(): """ Tests: test_jqpc_write__resource_dict__expect_failure1 """ print('::: TEST: test_jqpc_write__resource_dict__expect_failure1()') out_dir_path = path_join(SCRIPT_PATH, 'out_dir_test_jqpc_write__resource_dict__expect_failure1') if path_exists(out_dir_path): shutil_rmtree(out_dir_path) jqpc_write__resource_dict('wrong_name', out_dir_path, force=True) if path_exists(out_dir_path): shutil_rmtree(out_dir_path)
def test_jqpc_write__resource_dict__expect_failure2(): """ Tests: test_jqpc_write__resource_dict__expect_failure2 """ print('::: TEST: test_jqpc_write__resource_dict__expect_failure2()') out_dir_path = path_join( SCRIPT_PATH, 'out_dir_test_jqpc_write__resource_dict__expect_failure2') if path_exists(out_dir_path): shutil_rmtree(out_dir_path) jqpc_write__resource_dict('wrong' '-name', out_dir_path, force=False) if path_exists(out_dir_path): shutil_rmtree(out_dir_path)
def test_clean_created_dirs(): """ Tests: test_clean_created_dirs: this is just a helper to clean the dirs created in the tests """ print('::: TEST: test_clean_created_dirs()') for dir_name in [ 'out_dir_path_test_jqpc_write__resource_dict_ok1', 'out_dir_test_jqpc_write__resource_dict__expect_failure1', 'out_dir_test_jqpc_write__resource_dict__expect_failure2', 'out_dir_test_jqpc_write__selected_resources_ok1', 'out_dir_test_jqpc_write__selected_resources__expect_failure1']: clean_path = path_join(SCRIPT_PATH, dir_name) if path_exists(clean_path): shutil_rmtree(clean_path)
def test_jqpc_write__selected_resources__expect_failure1(): """ Tests: test_jqpc_write__selected_resources__expect_failure1 """ print('::: TEST: test_jqpc_write__selected_resources__expect_failure1()') out_dir_path = path_join(SCRIPT_PATH, 'out_dir_test_jqpc_write__selected_resources__expect_failure1') if path_exists(out_dir_path): shutil_rmtree(out_dir_path) list_of_resource_names = ['excanvas.min.js', 'jqplot.highlighter.min.js', 'wrong_resource_name'] jqpc_write__selected_resources('jqplot_scripts', list_of_resource_names, out_dir_path, force=False) if path_exists(out_dir_path): shutil_rmtree(out_dir_path)
def test_add_success(self): cvs: ControlVersionSystem = ControlVersionSystem(['init']) cvs.process_cvs_command() temp_path: str = os_path_join(cvs._changes_codec._CVS_DIR_PATH, '123') open(temp_path, 'w').close() cvs = ControlVersionSystem(['add', temp_path]) self.assertEqual('success: ' + temp_path, cvs.process_cvs_command()) shutil_rmtree(cvs._changes_codec._CVS_DIR_PATH)
def test_jqpc_write__resource_dict_ok1(): """ Tests: test_jqpc_write__resource_dict_ok1 """ print('::: TEST: test_jqpc_write__resource_dict_ok1()') out_dir_path = path_join(SCRIPT_PATH, 'out_dir_path_test_jqpc_write__resource_dict_ok1') if path_exists(out_dir_path): shutil_rmtree(out_dir_path) jqpc_write__resource_dict('jqplot_scripts', out_dir_path, force=False) jqpc_write__resource_dict('jqplot_scripts', out_dir_path, force=True) jqpc_write__resource_dict('jqplot_scripts', out_dir_path, force=False) if path_exists(out_dir_path): shutil_rmtree(out_dir_path)
def test_clean_created_dirs(): """ Tests: test_clean_created_dirs: this is just a helper to clean the dirs created in the tests """ print('::: TEST: test_clean_created_dirs()') for dir_name in [ 'out_dir_path_test_jqpc_write__resource_dict_ok1', 'out_dir_test_jqpc_write__resource_dict__expect_failure1', 'out_dir_test_jqpc_write__resource_dict__expect_failure2', 'out_dir_test_jqpc_write__selected_resources_ok1', 'out_dir_test_jqpc_write__selected_resources__expect_failure1' ]: clean_path = path_join(SCRIPT_PATH, dir_name) if path_exists(clean_path): shutil_rmtree(clean_path)
def fetch_input_file(self, file): if not os.path.isdir(self.input_cache_dir): os.mkdir(self.input_cache_dir) #url = 'https://www.metanetx.org/cgi-bin/mnxget/mnxref/' url = 'ftp://ftp.vital-it.ch/databases/metanetx/MNXref/3.2/' # 3xCommon + rpReader if file in [ 'reac_xref.tsv', 'chem_xref.tsv', 'chem_prop.tsv', 'comp_xref.tsv' ]: urllib_request_urlretrieve(url + file, self.input_cache_dir + '/' + file) #TODO: need to add this file to the git or another location if file in ['rr_compounds.tsv', 'rxn_recipes.tsv']: urllib_request_urlretrieve( 'https://retrorules.org/dl/this/is/not/a/secret/path/rr02', self.input_cache_dir + '/rr02_more_data.tar.gz') tar = tarfile_open(self.input_cache_dir + '/rr02_more_data.tar.gz', 'r:gz') tar.extractall(self.input_cache_dir) tar.close() shutil_move(self.input_cache_dir + '/rr02_more_data/compounds.tsv', self.input_cache_dir + '/rr_compounds.tsv') shutil_move( self.input_cache_dir + '/rr02_more_data/rxn_recipes.tsv', self.input_cache_dir) os.remove(self.input_cache_dir + 'rr02_more_data.tar.gz') shutil_rmtree(self.input_cache_dir + 'rr02_more_data') if file == 'rules_rall.tsv': urllib_request_urlretrieve( 'https://retrorules.org/dl/preparsed/rr02/rp3/hs', self.input_cache_dir + '/retrorules_rr02_rp3_hs.tar.gz') tar = tarfile_open( self.input_cache_dir + '/retrorules_rr02_rp3_hs.tar.gz', 'r:gz') tar.extractall(self.input_cache_dir) tar.close() shutil_move( self.input_cache_dir + '/retrorules_rr02_rp3_hs/retrorules_rr02_flat_all.tsv', self.input_cache_dir + '/rules_rall.tsv') os.remove(self.input_cache_dir + '/retrorules_rr02_rp3_hs.tar.gz') shutil_rmtree(self.input_cache_dir + '/retrorules_rr02_rp3_hs')
def test_jqpc_write__resource_dict_ok1(): """ Tests: test_jqpc_write__resource_dict_ok1 """ print('::: TEST: test_jqpc_write__resource_dict_ok1()') out_dir_path = path_join( SCRIPT_PATH, 'out_dir_path_test_jqpc_write__resource_dict_ok1') if path_exists(out_dir_path): shutil_rmtree(out_dir_path) jqpc_write__resource_dict('jqplot_scripts', out_dir_path, force=False) jqpc_write__resource_dict('jqplot_scripts', out_dir_path, force=True) jqpc_write__resource_dict('jqplot_scripts', out_dir_path, force=False) if path_exists(out_dir_path): shutil_rmtree(out_dir_path)
def test_clean_created_dirs(): """ Tests: test_clean_created_dirs: this is just a helper to clean the dirs created in the tests """ print('::: TEST: test_clean_created_dirs()') for dir_name in [ 'scripts_pie_chart_test_jqpc_simple_pie_chart_ok1', 'scripts_pie_chart_test_jqpc_simple_pie_chart_ok2', 'scripts_pie_chart_test_jqpc_simple_pie_chart_ok3', 'scripts_pie_chart_test_jqpc_simple_pie_chart_ok4', 'scripts_pie_chart_test_jqpc_simple_pie_chart_ok5', 'scripts_pie_chart_test_jqpc_simple_pie_chart__expect_failure1', 'scripts_pie_chart_test_jqpc_simple_pie_chart__not_absolute_source_path_expect_failure', ]: clean_path = path_join(SCRIPT_PATH, dir_name) if path_exists(clean_path): shutil_rmtree(clean_path)
def test_jqpc_simple_bar_chart__not_absolute_source_path_expect_failure(): """ Tests: test_jqpc_simple_bar_chart__not_absolute_source_path_expect_failure: """ print( '::: TEST: test_jqpc_simple_bar_chart__not_absolute_source_path_expect_failure()' ) scripts_bar_chart_path = 'scripts_pie_chart_test_jqpc_simple_bar_chart__not_absolute_source_path_expect_failure' if path_exists(scripts_bar_chart_path): shutil_rmtree(scripts_bar_chart_path) js_css_resources_header, jqplotchart_script, html_chart_insert_tag = jqpc_simple_bar_chart( absolute_source_dir_path=scripts_bar_chart_path, script_src_tag_dir_path=path_relpath(scripts_bar_chart_path), chart_id='example_id', class_str='', chart_title='JqPyCharts simple_bar_chart', chart_x_label={ 'fontFamily': 'Helvetica', 'fontSize': 14, 'textColor': '#000000' }, chart_x_label_fontdict=None, chart_ticks_fontdict={ 'fontFamily': 'Courier New', 'fontSize': 12, 'textColor': '#000000' }, chart_data_matrix=[('Fat', 200, '#EAA228', '200 g (57.7 %)'), ('Protein', 21, '#4bb2c5', '21 g (21.3 %)'), ('Carbohydrate', 10, '#c5b47f', '10 g (24.0 %)')], highlighter_prefix='Gram', background='#fffdf6', horizontal=False, draw_grid_lines=False, width_px=550, height_px=300, margin_top_px=0, margin_bottom_px=0, margin_right_px=0, margin_left_px=0) if path_exists(scripts_bar_chart_path): shutil_rmtree(scripts_bar_chart_path)
def main(self): checking_init(self.HOME) if not read_zshrc_omz(self.zsh_rc): title = f"Do you want to uninstall {package.info['name']}?" options = ["Yes", "No"] reply = pick(title, options, colorful=True, index=True) if reply is None or reply[0] == 1: printer("Whew! Thanks! :)", foreground=FG.GREEN) exit(0) rm_init_file_package(self.init_file) rm_source_zshrc(self.zsh_rc) else: title = f"What did you want to uninstall?" options = [ f"{package.info['name']}", f"{package.info['name']} and Oh My ZSH", "Cancel", ] reply = pick(title, options, colorful=True, index=True) if reply is None or reply[0] == 2: printer("Whew! Thanks! :)", foreground=FG.GREEN) exit(0) with contextlib_suppress(Exception): os_remove(self.theme_file) rm_init_file_package(self.init_file) change_theme_in_zshrc(self.zsh_rc, "robbyrussell") if reply[0] == 1: shutil_rmtree(self.omz_root, ignore_errors=True) with contextlib_suppress(Exception): shutil_copyfile( self.zsh_rc, f"{self.zsh_rc}-D{datetime.today().isoformat()}") with contextlib_suppress(Exception): os_remove(self.zsh_rc) snakypy_file_create("", f"{self.HOME}/.zshrc", force=True) reload_zsh() printer("Uninstall process finished.", foreground=FG.FINISH)
def test_clean_created_dirs(): """ Tests: test_clean_created_dirs: this is just a helper to clean the dirs created in the tests """ print('::: TEST: test_clean_created_dirs()') for dir_name in [ 'scripts_bar_chart_test_jqpc_simple_bar_chart_ok1', 'scripts_bar_chart_test_jqpc_simple_bar_chart_ok2', 'scripts_bar_chart_test_jqpc_simple_bar_chart_ok3', 'scripts_bar_chart_test_jqpc_simple_bar_chart_ok4', 'scripts_bar_chart_test_jqpc_simple_bar_chart_ok5', 'scripts_bar_chart_test_jqpc_simple_bar_chart_ok6', 'scripts_bar_chart_test_jqpc_simple_bar_chart__expect_failure1', 'scripts_pie_chart_test_jqpc_simple_bar_chart__not_absolute_source_path_expect_failure', ]: clean_path = path_join(SCRIPT_PATH, dir_name) if path_exists(clean_path): shutil_rmtree(clean_path)
def test_jqpc_write__selected_resources__expect_failure1(): """ Tests: test_jqpc_write__selected_resources__expect_failure1 """ print('::: TEST: test_jqpc_write__selected_resources__expect_failure1()') out_dir_path = path_join( SCRIPT_PATH, 'out_dir_test_jqpc_write__selected_resources__expect_failure1') if path_exists(out_dir_path): shutil_rmtree(out_dir_path) list_of_resource_names = [ 'excanvas.min.js', 'jqplot.highlighter.min.js', 'wrong_resource_name' ] jqpc_write__selected_resources('jqplot_scripts', list_of_resource_names, out_dir_path, force=False) if path_exists(out_dir_path): shutil_rmtree(out_dir_path)
def test_jqpc_write__selected_resources_ok1(): """ Tests: test_jqpc_write__selected_resources_ok1 """ print('::: TEST: test_jqpc_write__selected_resources_ok1()') out_dir_path = path_join( SCRIPT_PATH, 'out_dir_test_jqpc_write__selected_resources_ok1') if path_exists(out_dir_path): shutil_rmtree(out_dir_path) list_of_resource_names = [ 'excanvas.min.js', 'jqplot.highlighter.min.js', 'jquery.jqplot.min.css' ] jqpc_write__selected_resources('jqplot_scripts', list_of_resource_names, out_dir_path, force=False) for file_name in list_of_resource_names: ok_(path_exists(path_join(out_dir_path, file_name)), msg=None) list_of_resource_names = [ 'excanvas.min.js', 'jqplot.highlighter.min.js', 'jquery.jqplot.min.css' ] jqpc_write__selected_resources('jqplot_scripts', list_of_resource_names, out_dir_path, force=False) list_of_resource_names = [ 'excanvas.min.js', 'jqplot.highlighter.min.js', 'jquery.jqplot.min.css' ] jqpc_write__selected_resources('jqplot_scripts', list_of_resource_names, out_dir_path, force=True) if path_exists(out_dir_path): shutil_rmtree(out_dir_path)
def test_jqpc_simple_bar_chart__not_absolute_source_path_expect_failure(): """ Tests: test_jqpc_simple_bar_chart__not_absolute_source_path_expect_failure: """ print('::: TEST: test_jqpc_simple_bar_chart__not_absolute_source_path_expect_failure()') scripts_bar_chart_path = 'scripts_pie_chart_test_jqpc_simple_bar_chart__not_absolute_source_path_expect_failure' if path_exists(scripts_bar_chart_path): shutil_rmtree(scripts_bar_chart_path) js_css_resources_header, jqplotchart_script, html_chart_insert_tag = jqpc_simple_bar_chart( absolute_source_dir_path=scripts_bar_chart_path, script_src_tag_dir_path=path_relpath(scripts_bar_chart_path), chart_id='example_id', class_str='', chart_title='JqPyCharts simple_bar_chart', chart_x_label={'fontFamily': 'Helvetica', 'fontSize': 14, 'textColor': '#000000'}, chart_x_label_fontdict=None, chart_ticks_fontdict={'fontFamily': 'Courier New', 'fontSize': 12, 'textColor': '#000000'}, chart_data_matrix=[ ('Fat', 200, '#EAA228', '200 g (57.7 %)'), ('Protein', 21, '#4bb2c5', '21 g (21.3 %)'), ('Carbohydrate', 10, '#c5b47f', '10 g (24.0 %)') ], highlighter_prefix='Gram', background='#fffdf6', horizontal=False, draw_grid_lines=False, width_px=550, height_px=300, margin_top_px=0, margin_bottom_px=0, margin_right_px=0, margin_left_px=0) if path_exists(scripts_bar_chart_path): shutil_rmtree(scripts_bar_chart_path)
def test_jqpc_write__selected_resources_ok1(): """ Tests: test_jqpc_write__selected_resources_ok1 """ print('::: TEST: test_jqpc_write__selected_resources_ok1()') out_dir_path = path_join(SCRIPT_PATH, 'out_dir_test_jqpc_write__selected_resources_ok1') if path_exists(out_dir_path): shutil_rmtree(out_dir_path) list_of_resource_names = ['excanvas.min.js', 'jqplot.highlighter.min.js', 'jquery.jqplot.min.css'] jqpc_write__selected_resources('jqplot_scripts', list_of_resource_names, out_dir_path, force=False) for file_name in list_of_resource_names: ok_(path_exists(path_join(out_dir_path, file_name)), msg=None) list_of_resource_names = ['excanvas.min.js', 'jqplot.highlighter.min.js', 'jquery.jqplot.min.css'] jqpc_write__selected_resources('jqplot_scripts', list_of_resource_names, out_dir_path, force=False) list_of_resource_names = ['excanvas.min.js', 'jqplot.highlighter.min.js', 'jquery.jqplot.min.css'] jqpc_write__selected_resources('jqplot_scripts', list_of_resource_names, out_dir_path, force=True) if path_exists(out_dir_path): shutil_rmtree(out_dir_path)
def cleanDirectories(self, remove_output=False, remove_input=False): if os_path.exists(self.getTemporalDir()): shutil_rmtree(self.getTemporalDir()) if remove_input and os_path.exists(self.getInputDir()): shutil_rmtree(self.getInputDir()) if remove_output and os_path.exists(self.getOutputDir()): shutil_rmtree(self.getOutputDir()) return self
] for tag in tags: print(tag) if (not (tags.has('PoCExternal') or tags.has('PoCInternal'))): tags.add('PoCExternal') from pathlib import Path from shutil import rmtree as shutil_rmtree if tags.has('PoCCleanUp'): buildDirectory = Path("_build") if (buildDirectory.exists()): print("Removing old build directory '{0!s}'...".format(buildDirectory)) shutil_rmtree(str(buildDirectory)) else: print("Removing old build directory '{0!s}'... [SKIPPED]".format(buildDirectory)) pyInfrastructureDirectory = Path("pyIPCMI") print("Removing created files from '{0!s}'...".format(pyInfrastructureDirectory)) for path in pyInfrastructureDirectory.iterdir(): if (path.name.endswith(".rst") and (path.name != (pyInfrastructureDirectory / "index.rst"))): print(" {0!s}".format(path)) path.unlink() print() autodoc_member_order = "bysource" # Extract Python documentation and generate ReST files.
def run(self): need_normal_clean = True exclude_files = [ 'benchmark_it.c', 'disassemble_it.c', 'line_memory_profile_it.c', 'profile_it.c', 'speed_it.c', 'utils.c', '_version.c', ] remove_files = [] remove_dirs = [] # remove ONLY: `build/sphinx` if self.onlydocs: need_normal_clean = False dir_path = path_join(ROOT_PACKAGE_PATH, 'build', 'sphinx') if path_exists(dir_path): remove_dirs.append(dir_path) # remove also: DIRS: `build, dist, cover, *.egg-info, *._pyxbld` # and FILES in MAIN_PACKAGE_PATH: `*.so, *.c` and cython annotate html if self.all: need_normal_clean = True for dir_ in {'build', 'dist', 'cover'}: dir_path = path_join(ROOT_PACKAGE_PATH, dir_) if path_exists(dir_path): remove_dirs.append(dir_path) for root, dirs_w, files_w in os_walk(ROOT_PACKAGE_PATH): for dir_ in dirs_w: if '_pyxbld' in dir_ or 'egg-info' in dir_: remove_dirs.append(path_join(root, dir_)) # remove FILES in MAIN_PACKAGE_PATH: `*.so, *.c` and cython annotate html for root, dirs_w, files_w in os_walk(MAIN_PACKAGE_PATH): for file_ in files_w: if file_ not in exclude_files: if path_splitext(file_)[-1] in {'.so', '.c'}: remove_files.append(path_join(root, file_)) tmp_name, tmp_ext = path_splitext(file_) if tmp_ext == '.pyx': # Check if we have a html with the same name check_html_path = path_join(root, tmp_name + '.html') if path_isfile(check_html_path): remove_files.append(check_html_path) # remove also: all files defined in exclude_files if self.excludefiles: for root, dirs_w, files_w in os_walk(MAIN_PACKAGE_PATH): for file_ in files_w: if file_ in exclude_files: remove_files.append(path_join(root, file_)) # do the general clean if need_normal_clean: for file_ in {'.coverage', 'MANIFEST'}: if path_exists(file_): remove_files.append(file_) for root, dirs_w, files_w in os_walk(ROOT_PACKAGE_PATH): for file_ in files_w: if file_ not in exclude_files: if path_splitext(file_)[-1] in {'.pyc', '.pyo', '.pyd', '.o', '.orig'}: remove_files.append(path_join(root, file_)) for dir_ in dirs_w: if '__pycache__' in dir_: remove_dirs.append(path_join(root, dir_)) # REMOVE ALL SELECTED # noinspection PyBroadException try: for file_ in remove_files: if path_exists(file_): os_remove(file_) for dir_ in remove_dirs: if path_exists(dir_): shutil_rmtree(dir_) except Exception: pass
def run(self): need_normal_clean = True exclude_files = [ 'lconf_classes.c', 'structure_classes.c', 'main_code.c', 'transform.c', 'utilities.c', 'validator.c', '_version.c', ] remove_files = [] remove_dirs = [] # remove also: DIRS: `build, dist, cover, *._pyxbld, *.egg-info` # and FILES in MAIN_PACKAGE_PATH: `*.so, *.c` and cython annotate html if self.all: need_normal_clean = True for dir_ in {'build', 'dist', 'cover'}: dir_path = path_join(ROOT_PACKAGE_PATH, dir_) if path_exists(dir_path): remove_dirs.append(dir_path) for root, dirs_w, files_w in os_walk(ROOT_PACKAGE_PATH): for dir_ in dirs_w: if '_pyxbld' in dir_ or 'egg-info' in dir_: remove_dirs.append(path_join(root, dir_)) # remove FILES in MAIN_PACKAGE_PATH: `*.so, *.c` and cython annotate html for root, dirs_w, files_w in os_walk(MAIN_PACKAGE_PATH): for file_ in files_w: if file_ not in exclude_files: if path_splitext(file_)[-1] in {'.so', '.c'}: remove_files.append(path_join(root, file_)) tmp_name, tmp_ext = path_splitext(file_) if tmp_ext == '.pyx': # Check if we have a html with the same name check_html_path = path_join(root, tmp_name + '.html') if path_isfile(check_html_path): remove_files.append(check_html_path) # remove also: all files defined in exclude_files if self.excludefiles: for root, dirs_w, files_w in os_walk(MAIN_PACKAGE_PATH): for file_ in files_w: if file_ in exclude_files: remove_files.append(path_join(root, file_)) # do the general clean if need_normal_clean: for file_ in {'.coverage', 'MANIFEST'}: if path_exists(file_): remove_files.append(file_) for root, dirs_w, files_w in os_walk(ROOT_PACKAGE_PATH): for file_ in files_w: if file_ not in exclude_files: if path_splitext(file_)[-1] in {'.pyc', '.pyo', '.pyd', '.o', '.orig'}: remove_files.append(path_join(root, file_)) for dir_ in dirs_w: if '__pycache__' in dir_: remove_dirs.append(path_join(root, dir_)) # REMOVE ALL SELECTED try: for file_ in remove_files: if path_exists(file_): os_remove(file_) for dir_ in remove_dirs: if path_exists(dir_): shutil_rmtree(dir_) except Exception: pass
def tearDownClass(cls) -> None: shutil_rmtree(cls._changes_codec._CVS_DIR_PATH)
def run(self): need_normal_clean = True exclude_files = [ 'lconf_classes.c', 'lconf_structure_classes.c', 'main_code.c', 'transform.c', 'utils.c', 'validator.c', '_version.c', ] remove_files = [] remove_dirs = [] # remove ONLY: `build/sphinx` if self.onlydocs: need_normal_clean = False dir_path = path_join(ROOT_PACKAGE_PATH, 'build', 'sphinx') if path_exists(dir_path): remove_dirs.append(dir_path) # remove also: DIRS: `build, dist, cover, *._pyxbld, *.egg-info` # and FILES in MAIN_PACKAGE_PATH: `*.so, *.c` and cython annotate html if self.all: need_normal_clean = True for dir_ in {'build', 'dist', 'cover'}: dir_path = path_join(ROOT_PACKAGE_PATH, dir_) if path_exists(dir_path): remove_dirs.append(dir_path) for root, dirs_w, files_w in os_walk(ROOT_PACKAGE_PATH): for dir_ in dirs_w: if '_pyxbld' in dir_ or 'egg-info' in dir_: remove_dirs.append(path_join(root, dir_)) # remove FILES in MAIN_PACKAGE_PATH: `*.so, *.c` and cython annotate html for root, dirs_w, files_w in os_walk(MAIN_PACKAGE_PATH): for file_ in files_w: if file_ not in exclude_files: if path_splitext(file_)[-1] in {'.so', '.c'}: remove_files.append(path_join(root, file_)) tmp_name, tmp_ext = path_splitext(file_) if tmp_ext == '.pyx': # Check if we have a html with the same name check_html_path = path_join( root, tmp_name + '.html') if path_isfile(check_html_path): remove_files.append(check_html_path) # remove also: all files defined in exclude_files if self.excludefiles: for root, dirs_w, files_w in os_walk(MAIN_PACKAGE_PATH): for file_ in files_w: if file_ in exclude_files: remove_files.append(path_join(root, file_)) # do the general clean if need_normal_clean: for file_ in {'.coverage', 'MANIFEST'}: if path_exists(file_): remove_files.append(file_) for root, dirs_w, files_w in os_walk(ROOT_PACKAGE_PATH): for file_ in files_w: if file_ not in exclude_files: if path_splitext(file_)[-1] in { '.pyc', '.pyo', '.pyd', '.o', '.orig' }: remove_files.append(path_join(root, file_)) for dir_ in dirs_w: if '__pycache__' in dir_: remove_dirs.append(path_join(root, dir_)) # REMOVE ALL SELECTED # noinspection PyBroadException try: for file_ in remove_files: if path_exists(file_): os_remove(file_) for dir_ in remove_dirs: if path_exists(dir_): shutil_rmtree(dir_) except Exception: pass
# software, data, and/or physical and mental health. This software is # provided "as is" and any express or implied warranties, including, but # not limited to, the implied warranties of merchantability and fitness # for a particular purpose are disclaimed. In no event shall I or any # contributors be liable for any direct, indirect, incidental, special, # exemplary, or consequential damages (including, but not limited to, # procurement of substitute goods or services; loss of use, data, or # profits; or business interruption) however caused and on any theory of # liability, whether in contract, strict liability, or tort (including # negligence or otherwise) arising in any way out of the use of this # software, even if advised of the possibility of such damage. By using # this software you agree to these terms. # # Author: [email protected] # Date: 12th March 2017 from site import getsitepackages from shutil import rmtree as shutil_rmtree import os if __name__ == "__main__": # Anounce that going to remove modules print("Removing SpectrumTranslate from importable modules...") for packagedir in getsitepackages(): dirname = os.path.join(packagedir, "SpectrumTranslate") if(os.path.exists(dirname)): shutil_rmtree(dirname) print("Done")
def tearDown(self) -> None: if os_path_exists(self._changes_codec._CVS_DIR_PATH): shutil_rmtree(self._changes_codec._CVS_DIR_PATH)
def _rmtree(dir): # unlike dist_utils.dir_util.remove_tree, # shutil.rmtree does ignore all errors shutil_rmtree(dir, True)
def deleteDir(dirPath: str) -> None: if os_path.isdir(dirPath): shutil_rmtree(dirPath, ignore_errors=True) return
def gameInfoDownloadForAllPlayers(restoreMainPath): """ // 文件保存主目录 restoreMainPath // 一旦发生异常,则捕获并更新infoOfAllPlayers到本地 """ """ // 读取infoOfAllPlayers,若本地不存在,则新建并初始化 """ try: if (os_path_exists(restoreMainPath + "\infoOfAllPlayers.csv")): infoOfAllPlayers = pandas_read_csv(restoreMainPath + "\infoOfAllPlayers.csv") print("已读取本地球员基本信息") else: infoOfAllPlayers = filterDataForAllPlayers() infoOfAllPlayers["downloaded"] = "No" print("创建本地球员基本信息") for ii in range(0, len(infoOfAllPlayers)): restoreFilePathOfPlayer = restoreMainPath + "\\" + infoOfAllPlayers[ "playerName"][ii] if (infoOfAllPlayers["downloaded"][ii] == "No"): if (os_path_exists(restoreFilePathOfPlayer)): shutil_rmtree(restoreFilePathOfPlayer) print("{0}信息不完整,删除重建".format( infoOfAllPlayers["playerName"][ii])) if (os_mkdir(restoreFilePathOfPlayer) == False): print("文件夹{0}创建不成功".format(restoreFilePathOfPlayer)) raise Exception() """ // 获取球员所有赛季的统计信息链接页面 """ print("开始获取{0}信息".format(infoOfAllPlayers["playerName"][ii])) allSeasonWebLog = filterDataForallSeasonWebLog( infoOfAllPlayers["mainPageUrl"][ii]) for singleSeasonWebLog in allSeasonWebLog: res = requests_get(singleSeasonWebLog) strOfSeasonPage = res.text """ // 保存常规赛和季后赛每场比赛数据到本地 """ yearStr = singleSeasonWebLog[-5:-1] #有可能为无效链接,最后四位非数字 if (yearStr.isdigit()): filterDataForRegularSeason(strOfSeasonPage).to_csv(restoreFilePathOfPlayer + "\\" \ + "regularSeason" + singleSeasonWebLog[-5:-1] + ".csv") filterDataForPlayOffs(strOfSeasonPage).to_csv(restoreFilePathOfPlayer + "\\" \ + "playOffs" + singleSeasonWebLog[-5:-1] + ".csv") else: continue """ // 该球员信息保存成功 """ infoOfAllPlayers["downloaded"][ii] = "Yes" else: print("{0}信息已下载".format(infoOfAllPlayers["playerName"][ii])) continue except Exception as e: infoOfAllPlayers.to_csv(restoreMainPath + "\infoOfAllPlayers.csv") print(e) print("本地球员基本信息已更新") else: infoOfAllPlayers.to_csv(restoreMainPath + "\infoOfAllPlayers.csv") print("下载完成")
def rmtree(dir): return shutil_rmtree(dir)
] for tag in tags: print(tag) # if (not (tags.has('PoCExternal') or tags.has('PoCInternal'))): # tags.add('PoCExternal') from pathlib import Path from shutil import rmtree as shutil_rmtree if tags.has('PoCCleanUp'): buildDirectory = Path("_build") if (buildDirectory.exists()): print("Removing old build directory '{0!s}'...".format(buildDirectory)) shutil_rmtree(str(buildDirectory)) else: print("Removing old build directory '{0!s}'... [SKIPPED]".format(buildDirectory)) pyIPCMIDirectory = Path("pyIPCMI") print("Removing created files from '{0!s}'...".format(pyIPCMIDirectory)) for path in pyIPCMIDirectory.iterdir(): if (path.name.endswith(".rst") and (path.name != (pyIPCMIDirectory / "index.rst"))): print(" {0!s}".format(path)) path.unlink() print() autodoc_member_order = "bysource" # Extract Python documentation and generate ReST files.