Skip to content

Commit

Permalink
change setup.py, lightfile.py, and main.py
Browse files Browse the repository at this point in the history
  • Loading branch information
caiosv committed Sep 25, 2013
1 parent bdf36f4 commit 485e1e0
Show file tree
Hide file tree
Showing 4 changed files with 210 additions and 21 deletions.
100 changes: 100 additions & 0 deletions light/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
"""
I NEED AN ELSE after: if len(sysArgv) > 1:
TO RUN ALL METHODS ONCE WITHOUT ARGUMENTS.
THINK ABOUT MAKE A LIGHT COMMAND-LINE TO SEARCH
FOR A lightfile.py FILE IN THE DIR OF WORK ENV
THEN HANDLE THOSE THINGS WE HAVE ALREADY DONE.
"""
import os
import sys
import re
from light.operations import run
from light.colors import log
from lightfile import *


class job_execute(object):
def __init__(self, sysArgv, methods):
try:
log('methods: %s' % methods)
log('lenght methods: %s' % len(methods))
self.function = None
self.args = []
self.modulePath = sysArgv[0]
log('Module Path: %s' % self.modulePath)
self.moduleDir, tail = os.path.split(self.modulePath)
log('Module Dir: %s' % self.moduleDir)
self.moduleName, ext = os.path.splitext(tail)
log('Module Name: %s' % self.moduleName)
#__import__(self.moduleName)
#self.module = sys.module.__dict__[self.moduleName]
if len(sysArgv) > 1:
self.functionName = sysArgv[1]
log('Function Name: %s' % self.functionName)
#self.function = globals()[self.functionName]
possibles = globals().copy()
possibles.update(locals())
self.function = possibles.get(self.functionName)
if self.function:
pass
else:
for method in methods:
if self.functionName == method:
self.function = methods[self.functionName]
log('self func: %s' % self.function)
self.args = sysArgv[2:]
except Exception, e:
sys.stderr.write('%s %s\n' % ('job_execute#__init__', e))

def execute(self):
try:
if self.function:
self.function(*self.args)
except Exception, e:
sys.stderr.write('%s %s\n' % ('job_execute#execute', e))


def opp():
run('ls -la /home/ubuntu/')


"""
I NEED FIND A WAY TO ORDERED MY DIC or LIST
"""


def words(fileobj):
for line in fileobj:
for word in line.split():
yield word


def file_find_word(thisfile):
searchterms = ['def']
found_word = {}
with open(thisfile) as wordfile:
print wordfile
wordgen = words(wordfile)
for word in wordgen:
if word in searchterms:
nw = next(wordgen, None)
nw = re.split('\(.*\):', nw)[0]
if not nw.startswith('_') and not 'main' in nw:
fw_dict = {nw: eval(nw)}
found_word.update(fw_dict)
else:
word = None
foundwords = [word, next(wordgen, None)]
print foundwords
print 'Found Word dict: %s' % found_word
return found_word

"""
def main():
m_dict = file_find_word('/home/ubuntu/confs/light/lightfile.py')
job_execute(sys.argv, m_dict).execute()
"""
24 changes: 22 additions & 2 deletions light/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ def _run_command(command, shell=True, sudo=False):
"""
if command:

if env.command_prefixes:
cmd_prefix = _AttributeSting(env.command_prefixes[0])
command = cmd_prefix + command

given_command = _AttributeSting(command)

which = 'sudo' if sudo else 'run'

if which == 'run':
given_command = _AttributeSting(command)
print(gray('Perfoming given command: ' + \
blue(given_command, bold=True)))

Expand All @@ -39,7 +44,6 @@ def _run_command(command, shell=True, sudo=False):
print(white(indent(e.message) + '\n', bold=True))
hr()
elif which == 'sudo':
given_command = _AttributeSting(command)
print(gray('Perfoming given command:' + \
blue('sudo ' + command, bold=True)))
try:
Expand Down Expand Up @@ -120,3 +124,19 @@ def cd(path):
os.chdir(old_dir)
env.cwd = '' # clean env.cwd
env.new_cwd = [] # clean env.new_cwd


@contextmanager
def prefix(command, shell=True):
given_command = _AttributeSting(command)
given_command = given_command + ' && '

if not env.command_prefixes:
env.command_prefixes.append(given_command)
else:
env.command_prefixes = []
env.command_prefixes.append(given_command)
try:
yield
finally:
pass
64 changes: 57 additions & 7 deletions bootstrap.py → lightfile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env python
#_____GLOBAL IMPORTS_____#

import sys
import getopt
#_____LIGHT PACKAGES IMPORTS_____#
from light.api import *
from light.operations import prefix

#_____SET ENVIRONMENT_____#
env.user = 'ubuntu'
Expand Down Expand Up @@ -47,6 +49,9 @@
"libmysqlclient-dev"
]

# VERSION
VERSION = '0.1.0'


def install_packages():
package_count = len(INSTALL_PACKAGES)
Expand Down Expand Up @@ -214,20 +219,32 @@ def start_project():
red('requirements file', bold=True) + \
': '))
print magenta('Install Requirements..')
run('source bin/activate && pip install -r %(project_requirements)s' % env)
with prefix('. bin/activate'):
run('pip install -r %(project_requirements)s' % env)

_set_up_webservers()
_set_up_database()

with cd('%(home)s/%(project_base)s' % env):
with cd('%(home)s/%(project_base)s/%(project_home)s' % env):
print magenta('Syncing database..')
with cd('%(project_home)s' % env):
run('. bin/activate && python manage.py syncdb')
with prefix('. bin/activate'):
run('python manage.py syncdb')
hr()
print magenta('[DONE] PROJECT IS READY.')
hr()


def update_project():
"""
Updates the remote project
"""
with cd('%(home)s/%(project_base)s' % env):
run('git pull')
with prefix('. bin/activate'):
run('pip install -r %(project_requirements)s' % env)
run('python manage.py syncdb')


def restart_webservers():
"""
RESTART BOTH WEBSERVERS NGINX AND GREEN UNICORN.
Expand All @@ -243,13 +260,46 @@ def restart_webservers():
print magenta('[DONE] Web Servers is up.')


def operations():
with cd('/home/ubuntu/confs/light'), prefix('. bin/activate'):
run('pip install ipython')


def caio():
print "HELO MY NEW BABY"


def main():
from datetime import datetime
startTime = datetime.now()
#argv = sys.argv[1:]
#_job_execute(argv).execute()
#install_packages()
#git_global_config()
operations()
print (datetime.now() - startTime)
#operations()

from light.main import file_find_word
m_dict = file_find_word('/home/ubuntu/confs/light/lightfile.py')

"""
from light.read_methods_file import file_find_word
m_dict = file_find_word('/home/ubuntu/confs/light/bootstrap.py')
print blue(m_dict)
list_keys = list(m_dict.iterkeys())
for key in list_keys:
val = m_dict.get(key)
print yellow(val)
up_dic = {key: eval(val)}
m_dict.update(up_dic)
print red(m_dict)
"""
#methods = {'git_global_config': git_global_config, 'operations': operations}

from light.main import job_execute
job_execute(sys.argv, m_dict).execute()

print red('It took: ' + str(datetime.now() - startTime), bold=True)

if __name__ == '__main__':
main()
43 changes: 31 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from distutils.core import setup
from setuptools import setup, find_packages
from light.install import _man_pages, _install_commands

VERSION = '0.1.0'

readme = open('README.txt').read()
readme = open('README.md').read()

long_description = """
To find out what's new in this version of Light, please see `the changelog
Expand All @@ -28,17 +28,36 @@
license='LICENSE.txt',
description='Light is a simple, Pythonic tool for execution System Administration.',
long_description=long_description,
# Package Info
packages=find_packages(),
entry_points={
'light': [
'light = light.main:main',
]
},

# Package Info
packages=[
'light',
'light.api',
'light.colors',
'light.context_managers',
'light.operations',
'light.state',
'light.utils',
],


classifiers=[
'Development Status :: 5 - Production/Beta',
'Environment :: Console',
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: MIT License',
'Operating System :: MacOS :: MacOS X',
'Operating System :: Unix',
'Operating System :: POSIX',
'Programming Language :: Python',
'Programming Language :: Python :: 2.5',
'Programming Language :: Python :: 2.6',
'Topic :: Software Development',
'Topic :: Software Development :: Build Tools',
'Topic :: Software Development :: Libraries',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: System :: Clustering',
'Topic :: System :: Software Distribution',
'Topic :: System :: Systems Administration',
],

)

Expand Down

0 comments on commit 485e1e0

Please sign in to comment.