#!/usr/bin/python3

# ## {R2D2919B742E} ##
# ###########################################################################
# What if magic existed?
# What if a place existed where your every thought and dream come to life.
# There is only one catch: it has to be written down.
# Such a place exists, it is called programming.
#    - Scott Taylor Reph, RightThumb.com
# ###########################################################################
# ## {C3P0D40fAe8B} ##
##################################################
import sys, time
##################################################
import _rightThumb._construct as __
appDBA=__.clearFocus(__name__,__file__);__.appReg=appDBA;
def focus(parentApp='',childApp='',reg=True):
    global appDBA;f=__.appName(appDBA,parentApp,childApp);
    if reg:__.appReg=f;
    return f
import _rightThumb._base3 as _
fieldSet=_.l.vars(focus(),__name__,__file__,appDBA)
_.load()
##################################################
_v = __.imp('_rightThumb._vars')
_str = __.imp('_rightThumb._string')
##################################################
def sw():
    pass

# __.setting('require-list',['Pipe','Files','Plus'])
__.setting('require-list',[])
__.setting('receipt-log')
__.setting('receipt-file')
__.setting('myFileLocations-skip-validation',False)
__.setting('require-pipe',False)
__.setting('require-pipe||file',False)
__.setting('pre-error',False)
__.setting('switch-raw',[])


_.appInfo[focus()] = {
    # 'app': '8facG-jo0Cxk',
    'file': 'vps-cfarm-files.py',
    'liveAppName': __.thisApp( __file__ ),
    'description': 'Changes the world',
        # _.ail(1,'subject')+
        # _.aib('one')+
    'categories': [
                        'DEFAULT',
                ],
    'usage': [
                        # 'epy another',
                        # 'e nmap',
                        # '',
    ],
    'relatedapps': [
                        # 'p another -file file.txt',
                        # '',
    ],
    'prerequisite': [
                        # 'p another -file file.txt',
                        # '',
    ],
    'examples': [
                        _.hp('p thisApp -file file.txt'),
                        _.linePrint(label='simple',p=0),
                        '',
    ],
    'columns': [
                       # { 'name': 'name', 'abbreviation': 'n' },
                       # { 'name': '{1}', 'abbreviation': '{0}', 'sort': '{2}' },
    ],
    'aliases': [
                       # 'this',
                       # 'app',
    ],
    'notes': [
                       # {},
    ],
}

_.appData[focus()] = {
        'start': __.startTime,
        'uuid': '',
        'audit': [],
        'pipe': False,
        'data': {
                    'field': {'sent': [], 'received': [] }, # { 'label': '', 'context': [],  }
                    'table': {'sent': [], 'received': [] },
        },
    }


def triggers():
    _.switches.trigger( 'Files', _.myFileLocations, vs=True )
    _.switches.trigger( 'Ago', _.timeAgo )
    _.switches.trigger( 'Folder', _.myFolderLocations )
    _.switches.trigger( 'URL', _.urlTrigger )
    _.switches.trigger( 'Duration', _.timeFuture )

_.l.conf('clean-pipe',True)
_.l.sw.register( triggers, sw )

########################################################################################


########################################################################################
# START

__.var=_.dot()
__.var.files=[]
os=__.imp('os.path.isfile')
def script(path):
    if os.path.isfile(path) and path.endswith('.md'):
        if not path in __.var.files: __.var.files.append(path);


__.var.html='''
<ul>
    ITEMS
</ul>
'''
__.var.li='''
<li> <a href="md-bamf.php?f=RPATH1">RPATH2</a></li>
'''
# __.var.li='''
# <li> <a href="https://eyeformeta.com/apps/clients/cat-farm/bamf-md.php?f=RPATH1">RPATH2</a></li>
# '''
last_path=''
def rpath2(path):
    if not '/' in path:
        return path
    global last_path
    parts=path.split('/')
    parts.reverse()
    file=parts.pop(0)
    parts.reverse()
    folder='/'.join(parts)
    folder2=folder.replace('/',' > ')
    path2=path.replace('/',' > ')
    if not folder == last_path:
        last_path=folder
        return '<span style="color: crimson;">'+folder2+' > </span>'+file+''
    else:
        return '<span style="color: aqua;">'+folder2+' > </span>'+file+''
    #     spacer=''
    #     for ch in folder2+' >':
    #         spacer+='_'
    # return spacer+file
def action():
    _.fo(r=1,script=script)
    li=''
    fo=os.getcwd()+os.sep
    __.var.files.sort()
    for p in __.var.files:
        rpath=p.replace(fo,'')
        li+=__.var.li.replace('RPATH1',rpath).replace('RPATH2',rpath2(rpath))
    html=__.var.html.replace('ITEMS',li)
    _.pr(html)


os=__.imp('os.getcwd')
os=__.imp('os.sep')

########################################################################################
if __name__ == '__main__':
    action()
    __.isExit()




