Пример #1
0
    def runTest(self):
        cwd   = os.getcwd()
        home  = os.environ['HOME']

        assert normalizeFilename('foo.txt')   == os.path.join(cwd,  'foo.txt')
        assert normalizeFilename('~/foo.txt') == os.path.join(home, 'foo.txt')
        assert normalizeFilename('./foo.txt') == os.path.join(cwd,  'foo.txt')
Пример #2
0
def test_normalize():
    cwd   = os.getcwd()
    home  = os.environ['HOME']

    assert normalizeFilename('foo.txt')   == os.path.join(cwd,  'foo.txt')
    assert normalizeFilename('~/foo.txt') == os.path.join(home, 'foo.txt')
    assert normalizeFilename('./foo.txt') == os.path.join(cwd,  'foo.txt')
Пример #3
0
def gather(filepath, filename=None, force=False):
    logger.info('gather [%s] [%s] [%s]' % (filepath, filename, force))
    if filename is None:
        if filepath is None:
            logger.error('A specific file or a path to walk must be specified')
        else:
            for path, dirlist, filelist in os.walk(filepath):
                if len(filelist) > 0:
                    for item in filelist:
                        filename, ext = os.path.splitext(item)
                        if ext in ('.md', ):
                            state = isUpdated(path, filename, force)
                            key = 'kaku-event::%s::%s::%s' % (
                                'post', state, str(uuid.uuid4()))
                            data = {
                                'type': 'post',
                                'action': state,
                                'data': {
                                    'path': path,
                                    'file': filename
                                },
                                'key': key
                            }
                            db.set(key, json.dumps(data))
                            db.publish(cfg.events, key)
    else:
        s = normalizeFilename(filename)
        if not os.path.exists(s):
            s = normalizeFilename(os.path.join(filepath, filename))
        logger.info('checking [%s]' % s)
        if os.path.exists(s):
            path = os.path.dirname(s)
            filename, ext = os.path.splitext(s)
            if ext in ('.md', ):
                state = isUpdated(path, filename, force)
                key = 'kaku-event::%s::%s::%s' % ('post', state,
                                                  str(uuid.uuid4()))
                data = {
                    'type': 'post',
                    'action': state,
                    'data': {
                        'path': path,
                        'file': filename
                    },
                    'key': key
                }
                db.set(key, json.dumps(data))
                db.publish(cfg.events, key)
Пример #4
0
def gather(filepath, filename=None, force=False):
    logger.info('gather [%s] [%s] [%s]' % (filepath, filename, force))
    if filename is None:
        if filepath is None:
            logger.error('A specific file or a path to walk must be specified')
        else:
            for path, dirlist, filelist in os.walk(filepath):
                if len(filelist) > 0:
                    for item in filelist:
                        filename, ext = os.path.splitext(item)
                        if ext in ('.md',):
                            state = isUpdated(path, filename, force)
                            key   = 'kaku-event::%s::%s::%s' % ('post', state, str(uuid.uuid4()))
                            data  = { 'type':   'post',
                                      'action': state,
                                      'data':   { 'path': path,
                                                  'file': filename
                                                },
                                      'key':    key
                                    }
                            db.set(key, json.dumps(data))
                            db.publish(cfg.events, key)
    else:
        s = normalizeFilename(filename)
        if not os.path.exists(s):
            s = normalizeFilename(os.path.join(filepath, filename))
        logger.info('checking [%s]' % s)
        if os.path.exists(s):
            path          = os.path.dirname(s)
            filename, ext = os.path.splitext(s)
            if ext in ('.md',):
                state = isUpdated(path, filename, force)
                key   = 'kaku-event::%s::%s::%s' % ('post', state, str(uuid.uuid4()))
                data  = { 'type':   'post',
                          'action': state,
                          'data':   { 'path': path,
                                      'file': filename
                                    },
                          'key':    key
                        }
                db.set(key, json.dumps(data))
                db.publish(cfg.events, key)
Пример #5
0
def validateToken(authToken=None, tokenFile=None):
    if authToken is None:
        if tokenFile is not None:
            tokenFile = normalizeFilename(tokenFile)
            if os.path.exists(tokenFile):
                with open(tokenFile, "r") as h:
                    try:
                        authToken = h.read().strip()
                        if authToken is None or len(authToken) == 0:
                            logger.error("The authentication token found in %s appears to be empty." % tokenFile)
                            authToken = None
                    except:
                        authToken = None
    if authToken is None:
        if tokenFile is not None:
            s = " or retrieved at %s" % tokenFile
        else:
            s = ""
        logger.info("No Authorization token was found%s." % s)
    return authToken
Пример #6
0
def validateToken(authToken=None, tokenFile=None):
    if authToken is None:
        if tokenFile is not None:
            tokenFile = normalizeFilename(tokenFile)
            if os.path.exists(tokenFile):
                with open(tokenFile, 'r') as h:
                    try:
                        authToken = h.read().strip()
                        if authToken is None or len(authToken) == 0:
                            logger.error(
                                'The authentication token found in %s appears to be empty.'
                                % tokenFile)
                            authToken = None
                    except:
                        authToken = None
    if authToken is None:
        if tokenFile is not None:
            s = ' or retrieved at %s' % tokenFile
        else:
            s = ''
        logger.info('No Authorization token was found%s.' % s)
    return authToken
Пример #7
0
    logHandler.setFormatter(logFormatter)
    logger.addHandler(logHandler)
    logger.setLevel(logging.DEBUG)
    logger.info('micropub started')

    domain = None
    authToken = None
    newToken = False

    if args.publish is None:
        logger.error(
            'A file to publish must be specified using the --publish command line option.'
        )
        sys.exit(2)

    publish = normalizeFilename(args.publish)

    if not os.path.exists(publish):
        logger.error('Unable to locate the file %s to publish.' % publish)
        sys.exit(2)

    if args.domain is not None:
        url = urlparse(args.domain)
        if len(url.scheme) == 0 or (url.netloc) == 0:
            logger.error(
                'The domain must be specified with a scheme or location.')
            sys.exit(2)
        else:
            domain = ParseResult(url.scheme, url.netloc, url.path, '', '',
                                 '').geturl()
Пример #8
0
    logHandler   = logging.StreamHandler()
    logFormatter = logging.Formatter("%(asctime)s %(levelname)-9s %(message)s", "%Y-%m-%d %H:%M:%S")
    logHandler.setFormatter(logFormatter)
    logger.addHandler(logHandler)
    logger.setLevel(logging.DEBUG)
    logger.info('micropub started')

    domain    = None
    authToken = None
    newToken  = False

    if args.publish is None:
        logger.error('A file to publish must be specified using the --publish command line option.')
        sys.exit(2)

    publish = normalizeFilename(args.publish)

    if not os.path.exists(publish):
        logger.error('Unable to locate the file %s to publish.' % publish)
        sys.exit(2)

    if args.domain is not None:
        url = urlparse(args.domain)
        if len(url.scheme) == 0 or (url.netloc) == 0:
            logger.error('The domain must be specified with a scheme or location.')
            sys.exit(2)
        else:
            domain = ParseResult(url.scheme, url.netloc, url.path, '', '', '').geturl()

    if domain is None:
        logger.error('A domain must be specified using the --domain command line option.')