def objects(): Project = rt.modules.tickets.Project Ticket = rt.modules.tickets.Ticket TicketStates = rt.modules.tickets.TicketStates prj = Project(name="Lino") yield prj settings.SITE.loading_from_dump = True for ln in TICKETS.splitlines(): ln = ln.strip() if ln: a = ln.split(':') state = TicketStates.accepted a2 = [] for i in a: if '[closed]' in i: state = TicketStates.closed i = i.replace('[closed]', '') a2.append(i.strip()) num = a2[0][1:] title = a2[1] import lino fn = Path(lino.__file__).parent.parent.child('docs', 'tickets') fn = fn.child(num + '.rst') kw = dict() kw.update(created=datetime.datetime.fromtimestamp(fn.ctime())) kw.update(modified=datetime.datetime.fromtimestamp(fn.mtime())) kw.update(id=int(num), summary=title, project=prj, state=state) logger.info("%s %s", fn, kw['modified']) kw.update(description=fn.read_file()) # fd = open(fn) yield Ticket(**kw)
def objects(): Project = rt.models.tickets.Project Ticket = rt.models.tickets.Ticket TicketStates = rt.models.tickets.TicketStates prj = Project(name="Lino") yield prj settings.SITE.loading_from_dump = True for ln in TICKETS.splitlines(): ln = ln.strip() if ln: a = ln.split(':') state = TicketStates.accepted a2 = [] for i in a: if '[closed]' in i: state = TicketStates.closed i = i.replace('[closed]', '') a2.append(i.strip()) num = a2[0][1:] title = a2[1] import lino fn = Path(lino.__file__).parent.parent.child('docs', 'tickets') fn = fn.child(num + '.rst') kw = dict() kw.update(created=datetime.datetime.fromtimestamp(fn.ctime())) kw.update(modified=datetime.datetime.fromtimestamp(fn.mtime())) kw.update(id=int(num), summary=title, project=prj, state=state) logger.info("%s %s", fn, kw['modified']) kw.update(description=fn.read_file()) # fd = open(fn) yield Ticket(**kw)
print("\n*** Expand, Expand User and Expand Vars") print(Path("~").expand_user()) # Expands ~ to a absolute path name print(Path("$HOME").expand_vars()) # Expands system variables print(Path("/home/luke/..").norm()) # Expands .. and . notation print(Path("$HOME/..").expand()) # Expands system variables, ~ and also .. # Expands system variable and ~. Will also normalise the path ( remove redundant # .. . incorrect slashes and correct capitalisation on case sensitive file systems. Calls os.path.normpath # File Attributes and permissions print("\n*** File Attributes and permissions") # noinspection PyArgumentList print(here.atime()) # Last access time; seconds past epcoh # noinspection PyArgumentList print(here.ctime()) # Last permission or ownership modification; windows is creation time; # noinspection PyArgumentList print(here.isfile()) # Is a file; symbolic links are followed. print(here.isdir()) # Is a directory; symbolic links are followed. # noinspection PyArgumentList print(here.islink()) # Is a symbolic link # noinspection PyArgumentList print(here.ismount()) # Is a mount point; ie the parent is on a different device. # noinspection PyArgumentList print(here.exists()) # File exists; symbolic links are followed. # noinspection PyArgumentList print(here.lexists()) # Same as exists but symbolic links are not followed. # noinspection PyArgumentList print(here.size()) # File size in bytes. print(Path("/foo").isabsolute()) # Is absolute and not relative path
print("\n*** Expand, Expand User and Expand Vars") print(Path("~").expand_user()) # Expands ~ to a absolute path name print(Path("$HOME").expand_vars()) # Expands system variables print(Path("/home/luke/..").norm()) # Expands .. and . notation print(Path("$HOME/..").expand()) # Expands system variables, ~ and also .. # Expands system variable and ~. Will also normalise the path ( remove redundant # .. . incorrect slashes and correct capitalisation on case sensitive file systems. Calls os.path.normpath # File Attributes and permissions print("\n*** File Attributes and permissions") # noinspection PyArgumentList print(here.atime()) # Last access time; seconds past epcoh # noinspection PyArgumentList print(here.ctime() ) # Last permission or ownership modification; windows is creation time; # noinspection PyArgumentList print(here.isfile()) # Is a file; symbolic links are followed. print(here.isdir()) # Is a directory; symbolic links are followed. # noinspection PyArgumentList print(here.islink()) # Is a symbolic link # noinspection PyArgumentList print(here.ismount() ) # Is a mount point; ie the parent is on a different device. # noinspection PyArgumentList print(here.exists()) # File exists; symbolic links are followed. # noinspection PyArgumentList print(here.lexists()) # Same as exists but symbolic links are not followed. # noinspection PyArgumentList print(here.size()) # File size in bytes.
def __get_image_tag(self, image): """ Get a path to a image file and return the tags to sort this image :param image: (str or unipath.Path) path to an image file :return: (tuple) with the tags to sort the image """ # load sorting methods criteria = [self.sort] if self.sub_sorts: criteria.extend(self.sub_sorts) full_tags = list() # find all tags for criterion in criteria: # method for size if criterion == 'size': image_properties = dimensions(str(image)) tag = '{}x{}'.format(image_properties[0], image_properties[1]) full_tags.append(self.__image_tag(tag)) # method for date if criterion == 'date': # set possible date exif keys keys = ['Image DateTime', 'EXIF DateTimeDigitized', 'GPS GPSDate'] # fetch the key values with open(image, 'r') as file_handler: exif = process_file(file_handler) for key in keys: tag = exif.get(key, False) if tag: break if not tag: file_path = Path(image) tag = strftime('%Y:%m:%d', localtime(file_path.ctime())) # create sub tags tag = str(tag) if tag != 'Undefined Date': if len(tag.strip()) > 10: date_tag = datetime.strptime(tag, '%Y:%m:%d %H:%M:%S') else: date_tag = datetime.strptime(tag, '%Y:%m:%d') for sub_tag in ['%Y', '%m', '%d']: formatted = date_tag.strftime(sub_tag) full_tags.append(self.__image_tag(formatted, True)) else: full_tags.append(self.__image_tag(tag)) # method for origin if criterion == 'origin': # fetch the key values with open(image, 'r') as file_handler: # get info exif = process_file(file_handler) model = exif.get('Image Model', False) software = exif.get('Image Software', False) make = exif.get('Image Make', False) # if software is just a version number, skip it regex = compile('[^a-zA-Z]+') test = str(software) if len(regex.sub('', test.replace('Camera', ''))) == 0: software = False # generate tag if model and software: tag = '{} - {}'.format(model, software) elif model: tag = str(model) elif software: tag = str(software) elif make: tag = str(make) else: tag = 'Undefined Origin' # append tag full_tags.append(self.__image_tag(tag)) return tuple(full_tags)