""" Server package installer for SaberNet DCS """ from distutils.core import setup, Command from sys import argv import glob import os from sndcs_common import VERSION, DESCRIPTION BUILDING_DEB = False class UninstallCommand(Command): user_options = [] description = "uninstall the package files and directories" def initialize_options(self): pass def finalize_options(self): pass def run(self): # Execute build self.announce('determining installation files') self.announce('(re)building package') savevalue = self.distribution.dry_run self.distribution.dry_run = 0 self.run_command('build') # Execute install in dry-run mode self.announce('dry-run package install') self.distribution.dry_run = 1 self.run_command('install') self.distribution.dry_run = savevalue build = self.get_finalized_command('build') install = self.get_finalized_command('install') # Remove all installed files self.announce("removing files") dirs = {} filenames = install.get_outputs() for filename in filenames: if not os.path.isabs(filename): raise DistutilsError,\ 'filename %s from .get_output() not absolute' % \ filename if os.path.isfile(filename): self.announce("removing %s" % filename) if not self.dry_run: try: os.remove(filename) except OSError, details: self.warn("Could not remove file: %s" % details) dir = os.path.split(filename)[0] if not dirs.has_key(dir): dirs[dir] = 1 if os.path.splitext(filename)[1] == '.py': # Remove byte-code files as well try: os.remove(filename + 'c') except OSError: pass try: os.remove(filename + 'o') except OSError: pass elif os.path.isdir(filename): # This functionality is currently not being used by distutils if not dirs.has_key(dir): dirs[filename] = 1 elif not os.path.splitext(filename)[1] in ('.pyo', '.pyc'): self.announce("skipping removal of %s (not found)" % filename) # Remove the installation directories self.announce("removing directories") dirs = dirs.keys() dirs.sort(); dirs.reverse() # sort descending for dir in dirs: self.announce("removing directory %s" % dir) if not self.dry_run: try: os.rmdir(dir) except OSError, details: self.warn("could not remove directory: %s" % details) class CleanCommand(Command): user_options = [] description = "remove .pyc files" def initialize_options(self): self._clean_me = [] for root, dirs, files in os.walk('.'): for f in files: if f.endswith('.pyc'): self._clean_me.append(os.path.join(root, f)) def finalize_options(self): pass def run(self): for clean_me in self._clean_me: try: os.unlink(clean_me) except: pass if __name__ == "__main__": # Find out if we are installing the client, the server, or both # If the config file exists... install it if os.path.isfile("sndcs/config/sndcsd.conf"): install_server = True else: install_server = False if os.path.isfile("sndcs/config/sndcs2.conf"): install_client = True else: install_client = False # Hack to allow to build the sndcs_common and sndcs_doc debs if os.path.isfile("sndcs/config/build_sndcs_common") and BUILDING_DEB: install_common = True else: install_common = False if os.path.isfile("sndcs/config/build_sndcs_doc") and BUILDING_DEB: install_doc = True else: install_doc = False # default for Windows systems is to save into C:\python24\ unix like systems into /usr except for the config in /etc if BUILDING_DEB: prefix="../" elif os.name=="nt": prefix="" else: prefix="%%PREFIX%%/" packages = [] data_files = [] scripts = [] if len(argv) > 1 and argv[1] == "sdist": #Source distribution install_server = True install_client = True source_dist = True else: source_dist = False if install_server: sndcs2_web_etc_files = glob.glob("./sndcs/web/etc/*.py") sndcs2_web_lib_files = glob.glob("./sndcs/web/lib/*.py") sndcs2_web_task_files = glob.glob("./sndcs/web/tasks/*.py") sndcs2_web_files = glob.glob("./sndcs/web/sndcs2_web/__init__.py") sndcs2_web_files += glob.glob("./sndcs/web/sndcs2_web/*.ico") sndcs2_web_files += glob.glob("./sndcs/web/sndcs2_web/*.html") sndcs2_web_css_files = glob.glob("./sndcs/web/sndcs2_web/css/*.py") sndcs2_web_css_files += glob.glob("./sndcs/web/sndcs2_web/css/*.css") sndcs2_web_css_files += glob.glob("./sndcs/web/sndcs2_web/css/*.gif") sndcs2_web_employee_list_files = glob.glob("./sndcs/web/sndcs2_web/dcs_employee_list/*.py") sndcs2_web_edit_employees_files = glob.glob("./sndcs/web/sndcs2_web/dcs_edit_employees/*.py") sndcs2_web_edit_customers_files = glob.glob("./sndcs/web/sndcs2_web/dcs_edit_customers/*.py") sndcs2_web_edit_indirect_files = glob.glob("./sndcs/web/sndcs2_web/dcs_edit_indirect/*.py") sndcs2_web_edit_jobs_files = glob.glob("./sndcs/web/sndcs2_web/dcs_edit_jobs/*.py") sndcs2_web_edit_items_files = glob.glob("./sndcs/web/sndcs2_web/dcs_edit_items/*.py") sndcs2_web_edit_shifts_files = glob.glob("./sndcs/web/sndcs2_web/dcs_edit_shifts/*.py") sndcs2_web_edit_departments_files = glob.glob("./sndcs/web/sndcs2_web/dcs_edit_departments/*.py") sndcs2_web_edit_time_files = glob.glob("./sndcs/web/sndcs2_web/dcs_edit_time/*.py") sndcs2_web_admin_files = glob.glob("./sndcs/web/sndcs2_web/dcs_admin/*.py") sndcs2_web_login_files = glob.glob("./sndcs/web/sndcs2_web/dcs_login/*.py") sndcs2_web_js_files = glob.glob("./sndcs/web/sndcs2_web/js/*.js") sndcs2_web_jscalendar_files = glob.glob("./sndcs/web/sndcs2_web/js/jscalendar/*.js") sndcs2_web_images_files = glob.glob("./sndcs/web/sndcs2_web/images/*.gif") sndcs2_web_images_files += glob.glob("./sndcs/web/sndcs2_web/images/*.jpg") sndcs2_web_interface_files = glob.glob("./sndcs/web/sndcs2_web/images/interface/*.gif") sndcs2_web_interface_files += glob.glob("./sndcs/web/sndcs2_web/images/interface/*.jpg") sndcs2_web_interface_files += glob.glob("./sndcs/web/sndcs2_web/images/interface/*.png") wap_files = glob.glob("./sndcs/web/wap/__init__.py") wap_files += glob.glob("./sndcs/web/wap/*.html") wap_css_files = glob.glob("./sndcs/web/wap/css/*.py") wap_css_files += glob.glob("./sndcs/web/wap/css/*.css") wap_clock_in_files = glob.glob("./sndcs/web/wap/dcs_clock_in/*.py") wap_current_activity_files = glob.glob("./sndcs/web/wap/dcs_current_activity/*.py") wap_employee_list_files = glob.glob("./sndcs/web/wap/dcs_employee_list/*.py") wap_login_files = glob.glob("./sndcs/web/wap/dcs_login/*.py") wap_lunch_break_files = glob.glob("./sndcs/web/wap/dcs_lunch_break/*.py") wap_js_files = glob.glob("./sndcs/web/wap/js/*.js") data_files+=[ ("share/sndcs/sndcs.mkmodel", ["sndcs/sndcs.mkmodel/Classes.csv","sndcs/sndcs.mkmodel/Settings.config"]), ("%setc/sndcs" % prefix, ["sndcs/config/sndcsd.conf"]), ("share/sndcs", ["sndcs/pixmaps/sndcs.png"]), ("share/sndcs/web/tasks", sndcs2_web_task_files ),("share/sndcs/web/sndcs2_web/dcs_edit_items", sndcs2_web_edit_items_files), ("share/sndcs/web/sndcs2_web/dcs_edit_customers", sndcs2_web_edit_customers_files), ("share/sndcs/web", ["sndcs/web/404Text.txt", "sndcs/web/AppServer", "sndcs/web/Launch.py", "sndcs/web/sndcs2httpd"]), ("share/sndcs/web/etc", sndcs2_web_etc_files), ("share/sndcs/web/lib", sndcs2_web_lib_files), ("share/sndcs/web/sndcs2_web", sndcs2_web_files), ("share/sndcs/web/sndcs2_web/js", sndcs2_web_js_files), ("share/sndcs/web/sndcs2_web/dcs_edit_employees", sndcs2_web_edit_employees_files), ("share/sndcs/web/sndcs2_web/dcs_edit_indirect", sndcs2_web_edit_indirect_files), ("share/sndcs/web/sndcs2_web/dcs_edit_jobs", sndcs2_web_edit_jobs_files), ("share/sndcs/web/sndcs2_web/dcs_edit_shifts", sndcs2_web_edit_shifts_files),("share/sndcs/web/sndcs2_web/dcs_edit_departments", sndcs2_web_edit_departments_files),("share/sndcs/web/sndcs2_web/dcs_edit_time", sndcs2_web_edit_time_files), ("share/sndcs/web/sndcs2_web/dcs_admin", sndcs2_web_admin_files), ("share/sndcs/web/sndcs2_web/js/jscalendar", sndcs2_web_jscalendar_files), ("share/sndcs/web/sndcs2_web/images", sndcs2_web_images_files), ("share/sndcs/web/sndcs2_web/images/interface", sndcs2_web_interface_files), ("share/sndcs/web/sndcs2_web/dcs_login", sndcs2_web_login_files), ("share/sndcs/web/sndcs2_web/css", sndcs2_web_css_files), ("share/sndcs/web/sndcs2_web/dcs_employee_list", sndcs2_web_employee_list_files), ("share/sndcs/web/Cache", ""), ("share/sndcs/web/ErrorMsgs", ""), ("share/sndcs/web/Logs", ""), ("share/sndcs/web/Sessions", ""), ("share/sndcs/web/Configs", ["sndcs/web/Configs/Application.config", "sndcs/web/Configs/AppServer.config"]), ("share/sndcs/web/wap", wap_files), ("share/sndcs/web/wap/css", wap_css_files), ("share/sndcs/web/wap/dcs_clock_in", wap_clock_in_files), ("share/sndcs/web/wap/dcs_current_activity", wap_current_activity_files), ("share/sndcs/web/wap/dcs_employee_list", wap_employee_list_files), ("share/sndcs/web/wap/dcs_login", wap_login_files), ("share/sndcs/web/wap/dcs_lunch_break", wap_lunch_break_files), ("share/sndcs/web/wap/js", wap_js_files) ] if BUILDING_DEB: packages+=["sndcs", "sndcs.server"] else: packages+=["sndcs", "sndcs_common", "sndcs.server"] data_files+=[ ("%setc/sndcs" % prefix, ["sndcs/config/logging.conf"]), ("share/pixmaps", ["sndcs/pixmaps/sndcs.png"]), ("share/doc/sndcs/html", glob.glob("./docs/*.html")), ("share/doc/sndcs/pdf", glob.glob("./docs/*.pdf")), ("share/doc/sndcs/txt", glob.glob("./docs/*.txt")), ("share/doc/sndcs", [ "COPYING", "README", "AUTHORS", "ChangeLog", "NEWS"]) ] if not source_dist: packages+=["sndcs.GeneratedPy"] scripts+=["sndcs/server/sndcsd"] if install_client: data_files+=[ ("%setc/sndcs" % (prefix), ["sndcs/config/sndcs2.conf"]), ("share/sndcs", ["sndcs_client/gtk/sndcs2.glade", "sndcs/pixmaps/sndcs.png", "sndcs/pixmaps/dcs_splash.png"]) ] if BUILDING_DEB: packages+=["sndcs_client", "sndcs_client.gtk"] else: packages+=["sndcs_client", "sndcs_common", "sndcs_client.gtk", "sndcs_client.curses"] data_files+=[ ("%setc/sndcs" % (prefix), ["sndcs/config/logging.conf"]), ("share/pixmaps", ["sndcs/pixmaps/sndcs.png"]), ("share/doc/sndcs/html", glob.glob("./docs/*.html")), ("share/doc/sndcs/pdf", glob.glob("./docs/*.pdf")), ("share/doc/sndcs/txt", glob.glob("./docs/*.txt")), ("share/doc/sndcs", [ "COPYING", "README", "AUTHORS", "ChangeLog", "NEWS"]) ] if BUILDING_DEB: scripts+=["sndcs_client/gtk/sndcs_gtk"] else: scripts+=["sndcs_client/gtk/sndcs_gtk", "sndcs_client/curses/sndcs_curses"] if install_common: packages+=["sndcs_common"] data_files+=[("%setc/sndcs" % (prefix), ["sndcs/config/logging.conf"]), ("share/pixmaps", ["sndcs/pixmaps/sndcs.png"])] if install_doc: data_files+=[ ("share/doc/sndcs/html", glob.glob("./docs/*.html")), ("share/doc/sndcs/pdf", glob.glob("./docs/*.pdf")), ("share/doc/sndcs/txt", glob.glob("./docs/*.txt")), ("share/doc/sndcs", [ "COPYING", "README", "AUTHORS", "ChangeLog", "NEWS"]) ] if install_server or install_client or install_common or install_doc: setup(name="sndcs", version=VERSION, description=DESCRIPTION, author="Seth Remington", author_email="sremington@saberlogic.com", url="http://sabernetdcs.sourceforge.net/", packages=packages, data_files=data_files, scripts=scripts, cmdclass={'uninstall':UninstallCommand, 'clean':CleanCommand}, ) else: print "You must run configure_sndcs.py before you can install sndcs2"