def full_scan_steps(steps_report): """ # Bug warning- subsequent scans of the same filename with different time offsets are ignored, as the pickled file already contains time-offset timestamps. @param steps_report: filename of steps report @type steps_report: str @return: list @rtype: list[(datetime, datetime, datetime)] """ steps_report = getFullFilename(steps_report) cache = _get_cache_name(steps_report) if path_exists(cache) and _cache_valid(steps_report, cache): tests = unpickle_info(cache) else: steps_report = getFullFilename(steps_report) steps = extract_raw_steps(steps_report) tests = extract_test_steps(steps) tests = parse_test_dates(tests) pickle_info(tests, cache) return tests
def full_open_data_report(csv_report): """ Open the data report and create a DataReport instance from the file. The result is also cached in a .pickle file for intra-runtime persistance. Attempt first to see if a corresponding .pickle cache file exists for the same report upon being called, and if the cache is considered 'recent'. To be recent, the .pickle file must have been modified more recently than both the script and the corresponding .csv data report. This function will probably bug out if filenames passed are identical, even if paths weren't. @param csv_report: csv_report of data report @type csv_report: str @return: DataReport for report @rtype: DataReport """ csv_report = getFullFilename(csv_report) cache = _get_cache_name(csv_report) if path_exists(cache) and _cache_valid(csv_report, cache): batch = unpickle_info(cache) else: csv_report = getFullFilename(csv_report) batch = DataReport(csv_report) pickle_info(batch, cache) return batch
def test_get_full_filename_dir_no_ctxt(self): """ Search for a filename eg Foo/bar.txt with input "Foo/bar" @return: @rtype: """ for file in self.files: if not exists(file): raise self.failureException("Temp directory unexpectedly absent") base, name = split(file) name, ext = splitext(name) name = name.rstrip("\\/") expected = normpath(file) # noinspection PyTypeChecker result = getFullFilename(name, temp_dir) self.assertEqual(expected, result) # noinspection PyTypeChecker result2 = getFullFilename(name) self.assertEqual(expected, result2)
def test_get_lib_path_partial_name_noext(self): """ @return: @rtype: """ td = len(temp_dir) files = [splitext(f[td:])[0] for f in self.files] for path, expected in zip(files, self.files): base, name = split(path) # test inner function direct_result = _get_lib_path_parital_qualname(name, base, (temp_dir,)) self.assertEqual(expected, direct_result) # test public interface full_result = getFullFilename(path, temp_dir) self.assertEqual(expected, full_result) # results should be the same self.assertEqual(full_result, direct_result) # splitext returns '\' in front of name. remove that and assert again. noslash = _get_lib_path_parital_qualname(name, base.lstrip("\\/"), (temp_dir,)) self.assertEqual(noslash, full_result)
def test_get_full_filename_name_only_ext(self): """ The most common case @return: @rtype: """ for file in self.files: base, name = split(file) expected = normpath(file) result = getFullFilename(name, temp_dir) self.assertEqual(expected, result) result2 = getFullFilename(name) self.assertEqual(expected, result2)
def ProcessFile(self, filename): """ @param filename: filename to process @type filename: str @return: None @rtype: None """ filename = getFullFilename(filename) self._filename = filename self._create_data()
def _set_filename(self, filename): """ @param filename: filename to parse @type filename: str @return: full_filename, for convenience. @rtype: str """ full_filename = getFullFilename(filename) self._filename = split(full_filename)[1] self._full_filename = full_filename return full_filename
def test_get_full_filename_no_directory_with_drive(self): """ When sending in the filename with no directory, get the correct filepath @return: @rtype: """ for file in self.files: if not exists(file): raise self.failureException("Temp directory unexpectedly absent") name, ext = splitext(file) expected = normpath(file) result = getFullFilename(name, temp_dir) self.assertEqual(expected, result) result2 = getFullFilename(name) self.assertEqual(expected, result2)
def test_get_full_filename_exact(self): """ When inputing an exact file, get the exact filename back. @return: None @rtype: None """ for file in self.files: if not exists(file): raise self.failureException("Temp directory unexpectedly absent") expected = normpath(file) result = getFullFilename(file, temp_dir) self.assertEqual(expected, result)
def xlBook2(filepath=None, new=False, visible=True, search=False, xl=None): """Get win32com workbook object from filepath. If workbook is open, get active object. If workbook is not open, create a new instance of xl and open the workbook in that instance. If filename is not found, see if user specified default filename error behavior as returning new workbook. If not, raise error. If so, return new workbook Warning: returns error in some circumstances if dialogs or certain areas like formula bar in the desired Excel instance have focus. @param filepath: valid filepath @type filepath: str | None @param visible: xl instance visible to user? turn off to do heavy processing before showing @type visible: bool @param new: open in a new window @type new: bool @return: the newly opened xl workbook instance @rtype: (typehint.ExcelApplication, typehint.ExcelWorkbook) Update 1/15/2014- Lots of refactoring to make it really clean and such. Or so I tried. Update 1/29/2014- this function is now converted to abstract internal function. Interfaced moved to new function with same name. This function still contains logic. Update 1/31/2014- renamed function xlBook2, now public. """ if xl is None: xl = Excel(new, visible) if not filepath: wb = __ensure_wb(xl) return xl, wb _base, name = _split(filepath) no_ext_name, ext = _splitext(name) # First try to see if passed name of open workbook # xl can be a pain, so try with and without ext. wbs = xl.Workbooks possible_names = ( filepath.lstrip("\\/"), no_ext_name, name ) if wbs.Count: for fname in possible_names: try: wb = wbs(fname) except: continue else: v_print("\'%s\' found, returning existing workbook." % filepath) wb.Activate() return xl, wb # Workbook wasn't open, get filepath and open it. # This may take a *long* time. try: if search: v_print("Searching for file...") filepath = getFullFilename(filepath, hint=xl.DefaultFilePath) except FileNotFoundError as e: # cleanup if filepath wasn't found. if new: xl.Quit() else: xl.Visible = True raise xlLibError("Couldn't find path '%s', check that it is correct." % filepath) from e try: wb = wbs.Open(filepath, Notify=False) except: if new: xl.Quit() else: xl.Visible = True else: v_print("Filename \'%s\' found.\nReturning newly opened workbook." % filepath) wb.Activate() return xl, wb raise xlLibError("Unknown error occurred. \nCheck filename: %s " "If the target file is open, ensure\nno dialogs are open." % filepath)