示例#1
0
文件: Plan.py 项目: Tapyr/tapyr
def _main (cmd) :
    year      = cmd.year
    path      = sos.path.join (sos.expanded_path (cmd.diary), "%4.4d" % year)
    Y         = CAL.Year      (year)
    file_name = sos.path.join (path, cmd.filename)
    sort      = cmd.sort
    read_plan   (Y, file_name)
    if cmd.add_appointment :
        sort  = len (cmd.argv)
        for a in cmd.argv :
            if app_pat.match (a.strip ()) :
                _add_appointment (Y, app_pat, cmd.holidays_too)
            else :
                print ("%s doesn't match an appointment" % a)
    if cmd.Show :
        for a in cmd.argv :
            if app_pat.match (a.strip ()) :
                print (a)
                pat_match = app_pat
                day, month, year, time = _date_time (Y, pat_match)
                for D in _day_generator (pat_match, day, month, year, Y) :
                    print ("   ", D)
            else :
                print ("%s doesn't match an appointment" % a)
    if sort :
        Y.sort_appointments ()
        write_plan (Y, file_name, cmd.replace)
示例#2
0
文件: pdf.py 项目: Tapyr/tapyr
def _main (cmd) :
    year      = cmd.year
    head      = cmd.head
    tail      = cmd.tail
    path      = sos.path.join (sos.expanded_path (cmd.diary), "%4.4d" % year)
    Y         = CAL.Year  (year)
    file_name = sos.path.join (path, cmd.filename)
    pdf_name  = Filename (cmd.pdf or ("plan_%s.pdf" % year), ".pdf").name
    head      = cmd.head or 1
    tail      = cmd.tail or 12
    if cmd.monthly :
        Plan  = [PDF_Plan_Month, PDF_Plan_Month_L] [bool (cmd.landscape)]
    elif cmd.Yearly :
        Plan  = [PDF_Plan_Year, PDF_Plan_Year_L] [bool (cmd.landscape)]
    else :
        Plan  = [PDF_Plan_Week, PDF_Plan_Week_L] [bool (cmd.landscape)]
        head  = cmd.head or 0
        tail  = cmd.tail or -1
        wd    = Y.weeks [0].number
        if tail < 0 :
            tail += len (Y.weeks)
        head -= wd
        tail += 1 - wd
    CAL.read_plan (Y, file_name)
    Plan \
        ( Y, pdf_name, head, tail
        , xl  = cmd.XL
        , yl  = cmd.YL
        , xo  = cmd.XO
        , yo  = cmd.YO
        )
示例#3
0
def _main (cmd) :
    """Find all external imports of a package"""
    nop = sos.expanded_path (cmd.package)
    if sos.path.exists (nop) :
        if not sos.path.isdir (nop) :
            nop = sos.path.dirname (nop)
        pkg_path    = sos.path.abspath (nop)
        _, pkg_name = sos.path.split   (pkg_path)
    else :
        try :
            pkg = __import__ (nop)
        except Exception as exc :
            print \
                ( "%s is not the name or path of a proper python package\n  %s"
                % (nop, exc)
                )
            raise SystemExit (9)
        pkg_name = pkg.__name__
        pkg_path = sos.path.dirname (pkg.__file__)
    imports = external_imports (pkg_name, pkg_path)
    result  = set ()
    if cmd.Package_Namespaces :
        result.update (package_namespace_imports (imports))
    if cmd.Site_Packages :
        result.update (site_package_imports (imports))
    if not (cmd.Package_Namespaces or cmd.Site_Packages) :
        result = imports
    print (* sorted (result))
示例#4
0
文件: Plan.py 项目: xiaochang91/tapyr
def _main(cmd):
    year = cmd.year
    path = sos.path.join(sos.expanded_path(cmd.diary), "%4.4d" % year)
    Y = CAL.Year(year)
    file_name = sos.path.join(path, cmd.filename)
    sort = cmd.sort
    read_plan(Y, file_name)
    if cmd.add_appointment:
        sort = len(cmd.argv)
        for a in cmd.argv:
            if app_pat.match(a.strip()):
                _add_appointment(Y, app_pat, cmd.holidays_too)
            else:
                print("%s doesn't match an appointment" % a)
    if cmd.Show:
        for a in cmd.argv:
            if app_pat.match(a.strip()):
                print(a)
                pat_match = app_pat
                day, month, year, time = _date_time(Y, pat_match)
                for D in _day_generator(pat_match, day, month, year, Y):
                    print("   ", D)
            else:
                print("%s doesn't match an appointment" % a)
    if sort:
        Y.sort_appointments()
        write_plan(Y, file_name, cmd.replace)
示例#5
0
def _main(cmd):
    year = cmd.year
    head = cmd.head
    tail = cmd.tail
    path = sos.path.join(sos.expanded_path(cmd.diary), "%4.4d" % year)
    Y = CAL.Year(year)
    file_name = sos.path.join(path, cmd.filename)
    pdf_name = Filename(cmd.pdf or ("plan_%s.pdf" % year), ".pdf").name
    head = cmd.head or 1
    tail = cmd.tail or 12
    if cmd.monthly:
        Plan = [PDF_Plan_Month, PDF_Plan_Month_L][bool(cmd.landscape)]
    elif cmd.Yearly:
        Plan = [PDF_Plan_Year, PDF_Plan_Year_L][bool(cmd.landscape)]
    else:
        Plan = [PDF_Plan_Week, PDF_Plan_Week_L][bool(cmd.landscape)]
        head = cmd.head or 0
        tail = cmd.tail or -1
        wd = Y.weeks[0].number
        if tail < 0:
            tail += len(Y.weeks)
        head -= wd
        tail += 1 - wd
    CAL.read_plan(Y, file_name)
    Plan \
        ( Y, pdf_name, head, tail
        , xl  = cmd.XL
        , yl  = cmd.YL
        , xo  = cmd.XO
        , yo  = cmd.YO
        )
示例#6
0
def load_config_file (file_name, globals, locals = None) :
    if locals is None :
        locals = globals
    fname = sos.expanded_path (file_name)
    try :
        with open (fname) as f :
            config = f.read ()
    except IOError :
        pass
    else :
        exec (config, globals, locals)
    return locals
示例#7
0
def load_config_file(file_name, globals, locals=None):
    if locals is None:
        locals = globals
    fname = sos.expanded_path(file_name)
    try:
        with open(fname) as f:
            config = f.read()
    except IOError:
        pass
    else:
        exec(config, globals, locals)
    return locals
示例#8
0
def _main (cmd) :
    font   = ImageFont.load_default ()
    color  = cmd.color
    fmt    = cmd.format
    ext    = fmt.lower ()
    if ext == "jpeg" :
        ext = "jpg"
    holder = cmd.photographer
    x_off  = cmd.x_off
    y_off  = cmd.y_off
    year   = cmd.year
    i_size = cmd.i_size, cmd.i_size
    t_size = cmd.t_size, cmd.t_size
    td     = sos.expanded_path (cmd.target_dir)
    with TFL.temp_dir () as temp_dir :
        if cmd.add_to_dir :
            if not sos.path.isdir (td) :
                print ("Making directory %s" % (td, ))
                sos.mkdir_p (td)
            for src in cmd.argv [1:] :
                src, name = src.split ("=")
                if not name :
                    name = src
                name = Filename (name).base
                imp  = sos.path.join (td, "%s_im.%s" % (name, ext))
                thp  = sos.path.join (td, "%s_th.%s" % (name, ext))
                convert_one \
                    ( src, name, i_size, t_size, holder, year, font, imp, thp
                    , fmt, color, x_off, y_off
                    , temp_dir
                    )
        else :
            td_im = sos.path.join (td, "im")
            td_th = sos.path.join (td, "th")
            for x in td_im, td_th :
                if not sos.path.isdir (x) :
                    print ("Making directory %s" % (x, ))
                    sos.mkdir_p (x)
            pid  = cmd.start_pid
            for src in sorted (sos.expanded_globs (* cmd.argv [1:])) :
                pid  += 1
                name  = "%04d.%s" % (pid, ext)
                imp   = sos.path.join (td_im, name)
                thp   = sos.path.join (td_th, name)
                convert_one \
                    ( src, name, i_size, t_size, holder, year, font, imp, thp
                    , fmt, color, x_off, y_off
                    , temp_dir
                    )
示例#9
0
def _main (cmd) :
    font   = ImageFont.load_default ()
    color  = cmd.color
    fmt    = cmd.format
    ext    = fmt.lower ()
    if ext == "jpeg" :
        ext = "jpg"
    holder = cmd.photographer
    x_off  = cmd.x_off
    y_off  = cmd.y_off
    year   = cmd.year
    i_size = cmd.i_size, cmd.i_size
    t_size = cmd.t_size, cmd.t_size
    td     = sos.expanded_path (cmd.target_dir)
    with TFL.temp_dir () as temp_dir :
        if cmd.add_to_dir :
            if not sos.path.isdir (td) :
                print ("Making directory %s" % (td, ))
                sos.mkdir_p (td)
            for src in cmd.argv [1:] :
                src, name = src.split ("=")
                if not name :
                    name = src
                name = Filename (name).base
                imp  = sos.path.join (td, "%s_im.%s" % (name, ext))
                thp  = sos.path.join (td, "%s_th.%s" % (name, ext))
                convert_one \
                    ( src, name, i_size, t_size, holder, year, font, imp, thp
                    , fmt, color, x_off, y_off
                    , temp_dir
                    )
        else :
            td_im = sos.path.join (td, "im")
            td_th = sos.path.join (td, "th")
            for x in td_im, td_th :
                if not sos.path.isdir (x) :
                    print ("Making directory %s" % (x, ))
                    sos.mkdir_p (x)
            pid  = cmd.start_pid
            for src in sorted (sos.expanded_globs (* cmd.argv [1:])) :
                pid  += 1
                name  = "%04d.%s" % (pid, ext)
                imp   = sos.path.join (td_im, name)
                thp   = sos.path.join (td_th, name)
                convert_one \
                    ( src, name, i_size, t_size, holder, year, font, imp, thp
                    , fmt, color, x_off, y_off
                    , temp_dir
                    )
示例#10
0
文件: Year.py 项目: Tapyr/tapyr
def _main (cmd) :
    year = cmd.year
    path = sos.path.join (sos.expanded_path (cmd.path), "%4.4d" % year)
    Y    = Year (year)
    pfil = sos.path.join (path, cmd.Plan)
    vfil = sos.path.join (path, cmd.View)
    if cmd.create or cmd.diary :
        if not sos.path.isdir (path) :
            sos.mkdir (path)
        if cmd.diary :
            create_diary (Y, path)
        if cmd.create :
            if cmd.Plan :
                write_year (Y.as_plan, pfil, cmd.force)
            if cmd.View :
                write_year (Y.as_cal,  vfil, cmd.force)
示例#11
0
def _main (cmd) :
    year = cmd.year
    path = sos.path.join (sos.expanded_path (cmd.path), "%4.4d" % year)
    Y    = Year (year)
    pfil = sos.path.join (path, cmd.Plan)
    vfil = sos.path.join (path, cmd.View)
    if cmd.create or cmd.diary :
        if not sos.path.isdir (path) :
            sos.mkdir (path)
        if cmd.diary :
            create_diary (Y, path)
        if cmd.create :
            if cmd.Plan :
                write_year (Y.as_plan, pfil, cmd.force)
            if cmd.View :
                write_year (Y.as_cal,  vfil, cmd.force)
示例#12
0
 def _read_auth_mig(self, cao, scope, mig_auth_file=None):
     if mig_auth_file is None:
         mig_auth_file = cao.mig_auth_file
     try:
         f = open(sos.expanded_path(mig_auth_file), "rb")
     except IOError as exc:
         print \
             ( "Couldn't open", mig_auth_file, "due to exception\n    "
             , exc
             )
     else:
         with contextlib.closing(f):
             cargo = f.read()
         mig = pyk.pickle.loads(cargo)
         scope.Auth.Account.apply_migration(mig)
         if cao.verbose:
             print("Loaded authorization objects from", mig_auth_file)
示例#13
0
 def _read_auth_mig (self, cao, scope, mig_auth_file = None) :
     if mig_auth_file is None :
         mig_auth_file = cao.mig_auth_file
     try :
         f = open (sos.expanded_path (mig_auth_file), "rb")
     except IOError as exc :
         print \
             ( "Couldn't open", mig_auth_file, "due to exception\n    "
             , exc
             )
     else :
         with contextlib.closing (f) :
             cargo = f.read ()
         mig = pyk.pickle.loads (cargo)
         scope.Auth.Account.apply_migration (mig)
         if cao.verbose :
             print ("Loaded authorization objects from", mig_auth_file)
示例#14
0
文件: Alias.py 项目: JPilarr/tapyr
 def add_alias_file (self, name) :
     path = sos.expanded_path (name)
     if sos.path.exists (path) :
         with open (path) as f :
             buffer = pyk.decoded (f.read ())
         self.add_alias_buffer (buffer)
示例#15
0
文件: Alias.py 项目: Tapyr/tapyr
 def add_alias_file (self, name) :
     path = sos.expanded_path (name)
     if sos.path.exists (path) :
         with open (path) as f :
             buffer = pyk.decoded (f.read ())
         self.add_alias_buffer (buffer)
示例#16
0
文件: App_Test.py 项目: Tapyr/tapyr
 def __init__ (self, file_name, encodings = ()) :
     self.file_name = sos.expanded_path (file_name)
     self.encodings = encodings
示例#17
0
文件: App_Test.py 项目: Tapyr/tapyr
 def head_args (self, * args) :
     return args + (sos.expanded_path (self.file_name), )
示例#18
0
 def __init__(self, file_name, encodings=()):
     self.file_name = sos.expanded_path(file_name)
     self.encodings = encodings
示例#19
0
 def head_args(self, *args):
     return args + (sos.expanded_path(self.file_name), )