<s> """<STR_LIT>""" <EOL> from hyde . plugin import Plugin <EOL> from datetime import datetime <EOL> from dateutil . parser import parse <EOL> import os . path <EOL> import subprocess <EOL> class VCSDatesPlugin ( Plugin ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , site , vcs_name = '<STR_LIT>' ) : <EOL> super ( VCSDatesPlugin , self ) . __init__ ( site ) <EOL> self . vcs_name = vcs_name <EOL> def begin_site ( self ) : <EOL> for node in self . site . content . walk ( ) : <EOL> for resource in node . resources : <EOL> created = None <EOL> modified = None <EOL> try : <EOL> created = resource . meta . created <EOL> modified = resource . meta . modified <EOL> except AttributeError : <EOL> pass <EOL> if created != self . vcs_name and modified != self . vcs_name : <EOL> continue <EOL> date_created , date_modified = self . get_dates ( resource ) <EOL> if created == "<STR_LIT>" : <EOL> created = date_created or datetime . utcfromtimestamp ( <EOL> os . path . getctime ( resource . path ) ) <EOL> created = created . replace ( tzinfo = None ) <EOL> resource . meta . created = created <EOL> if modified == "<STR_LIT>" : <EOL> modified = date_modified or resource . source . last_modified <EOL> modified = modified . replace ( tzinfo = None ) <EOL> resource . meta . modified = modified <EOL> def get_dates ( self ) : <EOL> """<STR_LIT>""" <EOL> return None , None <EOL> class GitDatesPlugin ( VCSDatesPlugin ) : <EOL> def __init__ ( self , site ) : <EOL> super ( GitDatesPlugin , self ) . __init__ ( site , '<STR_LIT>' ) <EOL> def get_dates ( self , resource ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> commits = subprocess . check_output ( [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> resource . path <EOL> ] ) . split ( "<STR_LIT:\n>" ) <EOL> commits = commits [ : - <NUM_LIT:1> ] <EOL> except subprocess . CalledProcessError : <EOL> self . logger . warning ( <EOL> "<STR_LIT>" % resource ) <EOL> commits = None <EOL> if commits : <EOL> created = parse ( commits [ - <NUM_LIT:1> ] . strip ( ) ) <EOL> modified = parse ( commits [ <NUM_LIT:0> ] . strip ( ) ) <EOL> else : <EOL> self . logger . warning ( "<STR_LIT>" % resource ) <EOL> created , modified = None , None <EOL> return created , modified <EOL> class MercurialDatesPlugin ( VCSDatesPlugin ) : <EOL> def __init__ ( self , site ) : <EOL> super ( MercurialDatesPlugin , self ) . __init__ ( site , '<STR_LIT>' ) <EOL> def get_dates ( self , resource ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> commits = subprocess . check_output ( [ <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> resource . path ] ) . split ( '<STR_LIT:\n>' ) <EOL> commits = commits [ : - <NUM_LIT:1> ] <EOL> except subprocess . CalledProcessError : <EOL> self . logger . warning ( "<STR_LIT>" <EOL> % resource ) <EOL> commits = None <EOL> if not commits : <EOL> self . logger . warning ( "<STR_LIT>" % resource ) <EOL> return None , None <EOL> created = parse ( commits [ - <NUM_LIT:1> ] . strip ( ) ) <EOL> modified = parse ( commits [ <NUM_LIT:0> ] . strip ( ) ) <EOL> return created , modified </s>
