#!/usr/bin/python #encoding: utf-8 # PyConV v1.0-beta # Script de Controle de Versão # de Aplicações de Pequeno Porte # # Desenvolvido por Flávio Ribeiro # email@flavioribeiro.com #LICENÇA PÚBLICA GERAL GNU #TERMOS E CONDIÇÕES PARA CÓPIA, DISTRIBUIÇÃO E MODIFICAÇÃO #Este programa é software livre; você pode redistribuí-lo e/ou #modificá-lo sob os termos da Licença Pública Geral GNU, conforme #publicada pela Free Software Foundation; tanto a versão 2 da #Licença como (a seu critério) qualquer versão mais nova. #Este programa é distribuído na expectativa de ser útil, mas SEM #QUALQUER GARANTIA; sem mesmo a garantia implícita de #COMERCIALIZAÇÃO ou de ADEQUAÇÃO A QUALQUER PROPÓSITO EM #PARTICULAR. Consulte a Licença Pública Geral GNU para obter mais #detalhes. import time import sys import os import pickle VERSION = '1.0-beta' PATH = '/home/flavio/python/' class Informations: @classmethod def buildRelease(self, status): print 'Building Release ' + str(self.project_version) if status == 'new': os.system('mkdir ' + PATH + self.project_name + '-' + str(self.project_version)) elif status == 'old': os.system('cp -r ' + PATH + self.project_name + '-' + str(self.project_version_old) + ' ' + PATH + \ self.project_name + '-' + str(self.project_version)) @classmethod def firstTime(self): self.projects_info = {} self.exportProjectsInfo() @classmethod def countLines(self): self.total_lines = 0 for root, dirs, files in os.walk(PATH + self.project_name + '-' + str(self.project_version_old)): for file in files: self.parcial_lines = 0 path_file = root + '/' + file if path_file[-3:] == '.py': print 'Opening file ', path_file, for line in open(path_file): if line != '\n': self.parcial_lines += 1 print ' > Lines: ' + str(self.parcial_lines) self.total_lines += self.parcial_lines print 'Total of Lines of Code: ' + str(self.total_lines) return self.total_lines @classmethod def updateProjectsInfo(self, project_name , status): ''' { 'project_name' : {'version' : 'size'} ''' self.project_name = project_name if status == 'new': self.project_version = 1.0 self.projects_info.update({ self.project_name : { self.project_version : 0 }}) elif status == 'old': self.project_info = self.projects_info[self.project_name] self.project_version_old = max(self.project_info.keys()) print 'Calculating size of version: ' + str(self.project_version_old) self.projects_info[self.project_name][self.project_version_old] = self.countLines() self.project_version = self.project_version_old + 1.0 self.projects_info[self.project_name][self.project_version] = 0 self.buildRelease(status) self.exportProjectsInfo() @classmethod def loadProjectsInfo(self): self.projects_file = open(PATH + '.data.pcv','r') self.projects_info = pickle.load(self.projects_file) self.projects_file.close() @classmethod def exportProjectsInfo(self): self.projects_file = open(PATH + '.data.pcv','w') pickle.dump(self.projects_info, self.projects_file) self.projects_file.close() @classmethod def makeGraphics(self,project_name): try: import pylab my_project_info = self.projects_info[project_name] pylab.title(project_name + ' Project Information Graphic') pylab.xlabel('Version') pylab.ylabel('Size (Lines of Code)') x_values = my_project_info.keys()[:-1] y_values = my_project_info.values()[:-1] print x_values,y_values pylab.plot(x_values, y_values, linewidth=3.0) pylab.grid(True) pylab.show() except ImportError: print 'Error! You dont have pylab installed.' def HOWTO(): ''' Function that stores documentation about how to use pyConV ''' print 'Usage: ./pyconv [OPTION] [PROJECT NAME]' print 'Where [OPTION] can be:' print 'start - Starts a new project.' print 'commit - Build a new Release' print 'info - Make graphics about the project (needs pylab)' def start(args): ''' Main Function. ''' if args[1] == 'start': project_name = args[2] print 'PyConV %s ' % VERSION if project_name not in Informations.projects_info.keys(): print 'Starting a new project called: ' + project_name Informations.updateProjectsInfo(project_name, 'new') else: print 'Error! This Project already exists!' elif args[1] == 'commit': project_name = args[2] print 'PyConV %s ' % VERSION if project_name in Informations.projects_info.keys(): print 'Old Version: ' + str(max(Informations.projects_info[project_name].keys())) Informations.updateProjectsInfo(project_name, 'old') else: print 'Error! This Project no exists!' elif args[1] == 'info': project_name = args[2] print 'PyConV %s' % VERSION if project_name in Informations.projects_info.keys(): Informations.makeGraphics(project_name) else: print 'Error! This Project no exists!' else: HOWTO() if __name__ == '__main__': try: open(PATH + '.data.pcv', 'r') except IOError: print 'pyConV %s ' % VERSION print 'by Flávio Ribeiro \ email [at] flavioribeiro.com' print 'First time you run pyConV\nInitializing environment ... ', Informations.firstTime() print '[Ok]\n' Informations.loadProjectsInfo() if len(sys.argv) >= 3: start(sys.argv) else: HOWTO()