From 923218b12168fbcde0b33133ba8ee7d1ac1e5abf Mon Sep 17 00:00:00 2001 From: Thierry Carrez Date: Fri, 16 Jan 2015 17:36:55 +0100 Subject: [PATCH] Use yaml2ical as CLI, clean up useless const.py Declare a yaml2ical entry point to replace convert.py. Clean up the useless const.py and move the only remaining constant to meeting.py. Change-Id: I6204aa2c9d96640e50167a9df78686a1cd25e9ec --- README.rst | 17 ++++++----------- setup.cfg | 4 ++++ tox.ini | 3 +-- yaml2ical/{convert.py => cli.py} | 0 yaml2ical/const.py | 27 --------------------------- yaml2ical/meeting.py | 9 ++++++--- 6 files changed, 17 insertions(+), 43 deletions(-) rename yaml2ical/{convert.py => cli.py} (100%) delete mode 100644 yaml2ical/const.py diff --git a/README.rst b/README.rst index ffdfc94..40a7168 100644 --- a/README.rst +++ b/README.rst @@ -37,8 +37,9 @@ section below. :: - $ python convert.py -h - usage: convert.py [-h] -y YAML_DIR -i ICAL_DIR [-f] + $ pip install yaml2ical + $ yaml2ical + usage: yaml2ical [-h] -y YAML_DIR -i ICAL_DIR [-f] A tool that automates the process for testing, integrating, and publishing changes to OpenStack meetings using the existing OpenStack @@ -53,11 +54,6 @@ section below. -f, --force forcefully remove old .ics files from iCal directory - :: - - $ git clone https://github.com/openstack-infra/yaml2ical.git - $ cd yaml2ical/yaml2ical - The following are a few scenarios: @@ -65,8 +61,7 @@ Generate .ics files locally from existing yaml meeting files: :: - $ python convert.py -y ../meetings/ \ - -i ../icals/ + $ yaml2ical -y meetings/ -i icals/ The generated .ics files are not tracked in this git repository, but they are available locally to import into your calendar. Note, @@ -74,7 +69,7 @@ to remove stale .ics files, use the ``--force`` argument: :: - yaml2ical/icals$ ls + $ ls icals/ Barbican Meeting-b58d78a4.ics Ceilometer Team Meeting-9ed7b5b4.ics Chef Cookbook Meeting-2418b331.ics @@ -83,7 +78,7 @@ With each .ics file looking something similar to: :: - yaml2ical/icals$ cat Barbican\ Meeting-b58d78a4.ics + $ cat icals/Barbican\ Meeting-b58d78a4.ics BEGIN:VCALENDAR VERSION:2.0 PRODID:-//yaml2ical agendas//EN diff --git a/setup.cfg b/setup.cfg index 6797f58..9f8fd9c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -21,3 +21,7 @@ setup-hooks = [files] packages = yaml2ical + +[entry_points] +console_scripts = + yaml2ical = yaml2ical.cli:main diff --git a/tox.ini b/tox.ini index 78b404b..af3f8f5 100644 --- a/tox.ini +++ b/tox.ini @@ -15,8 +15,7 @@ commands = flake8 commands = {posargs} [testenv:mkical] -commands = mkdir -p ical - python yaml2ical/convert.py -i ./ical -c +commands = yaml2ical -y meetings/ -i icals/ -f [flake8] show-source = True diff --git a/yaml2ical/convert.py b/yaml2ical/cli.py similarity index 100% rename from yaml2ical/convert.py rename to yaml2ical/cli.py diff --git a/yaml2ical/const.py b/yaml2ical/const.py deleted file mode 100644 index 9591266..0000000 --- a/yaml2ical/const.py +++ /dev/null @@ -1,27 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import os - - -project_dir = os.path.dirname(os.getcwd()) - -YAML_FILE_EXT = '.yaml' - -WEEKDAYS = {'Monday': 0, 'Tuesday': 1, 'Wednesday': 2, 'Thursday': 3, - 'Friday': 4, 'Saturday': 5, 'Sunday': 6} - -SRC_DIR = project_dir - -# NOTE(jotan): The following publish URL is for testing purposes only. -# It should be later changed to the official OpenStack Meetings Wiki. -PUBLISH_URL = 'https://wiki.openstack.org/wiki/Meetings_Autogenerated' diff --git a/yaml2ical/meeting.py b/yaml2ical/meeting.py index 6e10654..0b16fd9 100644 --- a/yaml2ical/meeting.py +++ b/yaml2ical/meeting.py @@ -18,10 +18,13 @@ import icalendar import pytz import yaml -from yaml2ical import const from yaml2ical import schedule +WEEKDAYS = {'Monday': 0, 'Tuesday': 1, 'Wednesday': 2, 'Thursday': 3, + 'Friday': 4, 'Saturday': 5, 'Sunday': 6} + + class Yaml2IcalCalendar(icalendar.Calendar): """A calendar in ics format.""" @@ -71,11 +74,11 @@ class Meeting: if sch.freq.startswith('biweekly'): meet_on_even = sch.freq.endswith('even') next_meeting = next_biweekly_meeting(start_date, - const.WEEKDAYS[sch.day], + WEEKDAYS[sch.day], meet_on_even=meet_on_even) else: next_meeting = next_weekday(start_date, - const.WEEKDAYS[sch.day]) + WEEKDAYS[sch.day]) next_meeting_date = datetime.datetime(next_meeting.year, next_meeting.month,